---
title: Create relationship
slug: data-platform/api/create-relationship
docTags: 
createdAt: 2026-09-02T14:41:00.110Z
---

{
  "id": "HEa7ry6kpOpIWfsEA71iJ",
  "type": "api-oas-v2",
  "data": {
    "method": "POST",
    "url": "https://api.us1.odp.optimizely.com/v3/schema/objects/{object_name}/relations",
    "servers": [
      {
        "url": "https://api.us1.odp.optimizely.com/v3/schema/objects/{object_name}/relations",
        "description": "United States"
      },
      {
        "url": "https://api.eu1.odp.optimizely.com/v3/schema/objects/{object_name}/relations",
        "description": "Europe"
      },
      {
        "url": "https://api.au1.odp.optimizely.com/v3/schema/objects/{object_name}/relations",
        "description": "Asia-Pacific"
      }
    ],
    "name": "Create relationship",
    "description": "<p>Create a relation between objects in Optimizely Data Platform (ODP).</p>",
    "contentType": "application/json",
    "request": {
      "pathParameters": [
        {
          "kind": "required",
          "name": "object_name",
          "type": "string",
          "description": "The name of the object where you want to create the relationship."
        }
      ],
      "headerParameters": [
        {
          "name": "accept",
          "type": "string",
          "kind": "optional",
          "description": "Generated from available response content types",
          "enum": [
            "application/json"
          ],
          "default": "application/json"
        }
      ],
      "queryParameters": [],
      "bodyDataParameters": [
        {
          "kind": "required",
          "name": "body",
          "type": "object",
          "description": "",
          "customType": "Relation",
          "schema": [
            {
              "name": "child_object",
              "kind": "required",
              "type": "string",
              "description": "The name of the child object.",
              "example": "child"
            },
            {
              "name": "name",
              "kind": "required",
              "type": "string",
              "description": "<p>The name of the relationship (for example, ticket).</p>",
              "example": "relation_name"
            },
            {
              "name": "display_name",
              "kind": "required",
              "type": "string",
              "description": "<p>The human-readable name of the field (for example, Ticket).</p>",
              "example": "Relation Display Name"
            },
            {
              "name": "public_read",
              "kind": "required",
              "type": "string",
              "description": "Enable access with the API public key.",
              "example": false,
              "default": false
            },
            {
              "name": "join_fields",
              "kind": "optional",
              "type": "array",
              "description": "",
              "example": "",
              "itemType": "object",
              "customType": "object[]",
              "schema": [
                {
                  "name": "parent",
                  "kind": "required",
                  "type": "string",
                  "description": "<p>The name of the object that links to the child object (for example, id).</p>",
                  "example": "id"
                },
                {
                  "name": "child",
                  "kind": "optional",
                  "type": "string",
                  "description": "<p>The name of the child object that links to this object (for example, ticket_id).</p>",
                  "example": "child_id"
                }
              ]
            }
          ],
          "modelRef": "#/components/schemas/Relation",
          "isExpanded": true
        }
      ],
      "formDataParameters": [],
      "oAuthParameters": [
        {
          "id": "x-api-key",
          "name": "x-api-key",
          "kind": "optional",
          "type": "apiKey",
          "in": "header"
        }
      ],
      "cookieParameters": []
    },
    "responses": [
      {
        "statusCode": "200",
        "description": "OK",
        "jsonExample": "",
        "isExpanded": true,
        "schema": [
          {
            "kind": "optional",
            "type": "object",
            "example": "{\"name\":\"my_relation\",\"display_name\":\"My Relationship\",\"child_object\":\"child\",\"join_fields\":[{\"parent\":\"child_id\",\"child\":\"child_id\"}]}",
            "description": "",
            "customType": "Object",
            "schema": [
              {
                "name": "name",
                "kind": "required",
                "type": "string",
                "description": "<p>the plural name of the object (for example, tickets)</p>"
              },
              {
                "name": "display_name",
                "kind": "required",
                "type": "string",
                "description": "<p>the human-readable name of the object (for example, Tickets)</p>"
              },
              {
                "name": "public_read",
                "kind": "required",
                "type": "boolean",
                "description": "enable access with the API public key",
                "default": false
              },
              {
                "name": "alias",
                "kind": "required",
                "type": "string",
                "description": "<p>the singular name of the object (for example, ticket)</p>"
              },
              {
                "name": "fields",
                "kind": "required",
                "type": "array",
                "description": "an array of fields objects",
                "example": "",
                "itemType": "object",
                "customType": "object[]",
                "schema": [
                  {
                    "name": "name",
                    "kind": "optional",
                    "type": "string",
                    "description": "",
                    "example": "object_id"
                  },
                  {
                    "name": "display_name",
                    "kind": "optional",
                    "type": "string",
                    "description": "",
                    "example": "New Object Identifier"
                  },
                  {
                    "name": "type",
                    "kind": "optional",
                    "type": "string",
                    "description": "",
                    "example": "string"
                  },
                  {
                    "name": "primary",
                    "kind": "optional",
                    "type": "boolean",
                    "description": "",
                    "example": true,
                    "default": true
                  }
                ]
              },
              {
                "name": "relations",
                "kind": "optional",
                "type": "array",
                "description": "an array of relations objects",
                "example": "",
                "itemType": "object",
                "customType": "object[]",
                "schema": [
                  {
                    "name": "name",
                    "kind": "optional",
                    "type": "string",
                    "description": "",
                    "example": "my_relation"
                  },
                  {
                    "name": "display_name",
                    "kind": "optional",
                    "type": "string",
                    "description": "",
                    "example": "My Relationship"
                  },
                  {
                    "name": "child_object",
                    "kind": "optional",
                    "type": "string",
                    "description": "",
                    "example": "child"
                  },
                  {
                    "name": "join_fields",
                    "kind": "optional",
                    "type": "array",
                    "description": "",
                    "example": "",
                    "itemType": "object",
                    "customType": "object[]",
                    "schema": [
                      {
                        "name": "parent",
                        "kind": "optional",
                        "type": "string",
                        "description": "",
                        "example": "child_id"
                      },
                      {
                        "name": "child",
                        "kind": "optional",
                        "type": "string",
                        "description": "",
                        "example": "child_id"
                      }
                    ]
                  }
                ]
              }
            ],
            "modelRef": "#/components/schemas/Object",
            "isExpanded": true
          }
        ]
      },
      {
        "statusCode": "400",
        "description": "Bad Request",
        "jsonExample": "",
        "isExpanded": true,
        "schema": [
          {
            "kind": "optional",
            "type": "object",
            "example": "{\"title\":\"Bad Request\",\"status\":400,\"timestamp\":\"2018-08-14T12:23:04.500Z\",\"detail\":{\"invalids\":[{\"field\":\"join_fields[0].parent\",\"reason\":\"does not match child data type\"}]}}",
            "description": "",
            "customType": "Error",
            "schema": [
              {
                "name": "title",
                "kind": "optional",
                "type": "string",
                "description": "",
                "example": "Bad Request"
              },
              {
                "name": "status",
                "kind": "optional",
                "type": "integer",
                "description": "",
                "example": 400,
                "default": 0
              },
              {
                "name": "timestamp",
                "kind": "optional",
                "type": "string",
                "description": "",
                "example": "2018-08-07T13:44:17.659Z"
              },
              {
                "name": "detail",
                "kind": "optional",
                "type": "object",
                "description": "",
                "example": "",
                "schema": [
                  {
                    "name": "invalids",
                    "kind": "optional",
                    "type": "array",
                    "description": "",
                    "example": "",
                    "itemType": "object",
                    "customType": "object[]",
                    "schema": [
                      {
                        "name": "field",
                        "kind": "optional",
                        "type": "string",
                        "description": "",
                        "example": "name"
                      },
                      {
                        "name": "reason",
                        "kind": "optional",
                        "type": "string",
                        "description": "",
                        "example": "already used by another object"
                      }
                    ]
                  }
                ]
              }
            ],
            "modelRef": "#/components/schemas/Error",
            "isExpanded": true
          }
        ]
      },
      {
        "statusCode": "403",
        "description": "Forbidden",
        "jsonExample": "",
        "isExpanded": true
      }
    ],
    "hasXCodeSamples": false,
    "examples": {
      "languages": [
        {
          "id": "tmCINCGWF4norDMBrlAqY",
          "language": "curl",
          "label": "cURL",
          "code": "curl --request POST \\\n     --url https://api.us1.odp.optimizely.com/v3/schema/objects/{object_name}/relations \\\n     --header 'accept: application/json' \\\n     --header 'content-type: application/json' \\\n     --data '{\n     \"child_object\": \"child\",\n     \"name\": \"relation_name\",\n     \"display_name\": \"Relation Display Name\",\n     \"public_read\": false,\n     \"join_fields\": [\n     {\n     \"parent\": \"id\"\n     }\n     ]\n     }'"
        },
        {
          "id": "bfQ8bZG61n5KcXa_44Nw-",
          "language": "javascript",
          "label": "javascript",
          "code": "var myHeaders = new Headers();\nmyHeaders.append(\"accept\", \"application/json\");\nmyHeaders.append(\"content-type\", \"application/json\");\n\nvar raw = JSON.stringify({\n   \"child_object\": \"child\",\n   \"name\": \"relation_name\",\n   \"display_name\": \"Relation Display Name\",\n   \"public_read\": false,\n   \"join_fields\": [\n      {\n         \"parent\": \"id\"\n      }\n   ]\n});\n\nvar requestOptions = {\n   method: 'POST',\n   headers: myHeaders,\n   body: raw,\n   redirect: 'follow'\n};\n\nfetch(\"https://api.us1.odp.optimizely.com/v3/schema/objects/{object_name}/relations\", requestOptions)\n   .then(response => response.text())\n   .then(result => console.log(result))\n   .catch(error => console.log('error', error));"
        },
        {
          "id": "ACG1vU8XnQ0kwjPV5uAwV",
          "language": "ruby",
          "label": "Ruby",
          "code": "require \"uri\"\nrequire \"json\"\nrequire \"net/http\"\n\nurl = URI(\"https://api.us1.odp.optimizely.com/v3/schema/objects/{object_name}/relations\")\n\nhttps = Net::HTTP.new(url.host, url.port)\nhttps.use_ssl = true\n\nrequest = Net::HTTP::Post.new(url)\nrequest[\"accept\"] = \"application/json\"\nrequest[\"content-type\"] = \"application/json\"\nrequest.body = JSON.dump({\n   \"child_object\": \"child\",\n   \"name\": \"relation_name\",\n   \"display_name\": \"Relation Display Name\",\n   \"public_read\": false,\n   \"join_fields\": [\n      {\n         \"parent\": \"id\"\n      }\n   ]\n})\n\nresponse = https.request(request)\nputs response.read_body\n"
        },
        {
          "id": "FwtUOMHEkG_aZPDDtWs4k",
          "language": "python",
          "label": "Python",
          "code": "import requests\nimport json\n\nurl = \"https://api.us1.odp.optimizely.com/v3/schema/objects/{object_name}/relations\"\n\npayload = json.dumps({\n   \"child_object\": \"child\",\n   \"name\": \"relation_name\",\n   \"display_name\": \"Relation Display Name\",\n   \"public_read\": False,\n   \"join_fields\": [\n      {\n         \"parent\": \"id\"\n      }\n   ]\n})\nheaders = {\n   'accept': 'application/json',\n   'content-type': 'application/json'\n}\n\nresponse = requests.request(\"POST\", url, headers=headers, data=payload)\n\nprint(response.text)\n"
        }
      ],
      "selectedLanguageId": "tmCINCGWF4norDMBrlAqY"
    },
    "results": {
      "languages": [
        {
          "id": "response-0-200",
          "language": "200",
          "code": "// OK\n{\n  \"name\": \"\",\n  \"display_name\": \"\",\n  \"public_read\": false,\n  \"alias\": \"\",\n  \"fields\": [\n    {\n      \"name\": \"object_id\",\n      \"display_name\": \"New Object Identifier\",\n      \"type\": \"string\",\n      \"primary\": true\n    }\n  ],\n  \"relations\": [\n    {\n      \"name\": \"my_relation\",\n      \"display_name\": \"My Relationship\",\n      \"child_object\": \"child\",\n      \"join_fields\": [\n        {\n          \"parent\": \"child_id\",\n          \"child\": \"child_id\"\n        }\n      ]\n    }\n  ]\n}"
        },
        {
          "id": "response-1-400",
          "language": "400",
          "code": "// Bad Request\n{\n  \"title\": \"Bad Request\",\n  \"status\": 400,\n  \"timestamp\": \"2018-08-07T13:44:17.659Z\",\n  \"detail\": {\n    \"invalids\": [\n      {\n        \"field\": \"name\",\n        \"reason\": \"already used by another object\"\n      }\n    ]\n  }\n}"
        },
        {
          "id": "response-2-403",
          "language": "403",
          "code": "// Forbidden\n"
        }
      ],
      "selectedLanguageId": "response-0-200"
    }
  },
  "children": [
    {
      "text": ""
    }
  ]
}