> ## Documentation Index
> Fetch the complete documentation index at: https://developers.leadwaycrm.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Create Relation for you associated entities.

> Create Relation.Documentation Link - https://doc.clickup.com/8631005/d/h/87cpx-293776/cd0f4122abc04d3

Create Relation.Documentation Link - [https://doc.clickup.com/8631005/d/h/87cpx-293776/cd0f4122abc04d3](https://doc.clickup.com/8631005/d/h/87cpx-293776/cd0f4122abc04d3)

```http theme={null}
POST https://services.leadconnectorhq.com/associations/relations
```

## Autorización

<ParamField header="Authorization" type="string" required>
  Bearer token generado desde el portal Leadway. Ver [Autenticación](/authentication).
</ParamField>

<ParamField header="Version" type="string" required default="2021-07-28">
  Versión de la API.
</ParamField>

## Body

<ParamField body="locationId" type="string" required default="clF1LD04GTUKN3b3XuOj">
  Your Sub Account's ID
</ParamField>

<ParamField body="associationId" type="string" required default="ve9EPM428h8vShlRW1KT">
  Association's Id
</ParamField>

<ParamField body="firstRecordId" type="string" required default="ve9EPM428h8vShlRW1KT">
  First Record's Id. For instance, if you have an association between a contact and a custom object, and you specify the contact as the first object while creating the association, then your firstRecordId would be the contactId
</ParamField>

<ParamField body="secondRecordId" type="string" required default="ve9EPM428h8vShlRW1KT">
  Second Record's Id.For instance, if you have an association between a contact and a custom object, and you specify the custom object as the second entity while creating the association, then your secondRecordId would be the customObject record Id
</ParamField>

## Respuestas

<Accordion title="201 - Successful response">
  <ResponseField name="locationId" type="string" required default="string" />

  <ResponseField name="id" type="string" required default="ve9EPM428h8vShlRW1KT" />

  <ResponseField name="key" type="string" required default="student">
    First Objects Association Label (custom\_objects.children)
  </ResponseField>

  <ResponseField name="firstObjectLabel" type="object" required default="student">
    First Objects Association Label (custom\_objects.children)
  </ResponseField>

  <ResponseField name="firstObjectKey" type="object" required default="custom_objects.children">
    First Objects Key
  </ResponseField>

  <ResponseField name="secondObjectLabel" type="object" required default="Teacher">
    Second Object Association Label (contact)
  </ResponseField>

  <ResponseField name="secondObjectKey" type="object" required default="contact">
    Second Objects Key
  </ResponseField>

  <ResponseField name="associationType" type="object" required default="USER_DEFINED">
    Association Type can be USER\_DEFINED or SYSTEM\_DEFINED
  </ResponseField>

  ```json theme={null}
  {
    "locationId": "string",
    "id": "ve9EPM428h8vShlRW1KT",
    "key": "student",
    "firstObjectLabel": "student",
    "firstObjectKey": "custom_objects.children",
    "secondObjectLabel": "Teacher",
    "secondObjectKey": "contact",
    "associationType": "USER_DEFINED"
  }
  ```
</Accordion>

<Accordion title="400 - Bad Request">
  ```json theme={null}
  {}
  ```
</Accordion>

<Accordion title="401 - Unauthorized">
  ```json theme={null}
  {}
  ```
</Accordion>

<Accordion title="422 - Unprocessable Entity">
  ```json theme={null}
  {}
  ```
</Accordion>

## Ejemplo

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST 'https://services.leadconnectorhq.com/associations/relations' \
    -H 'Authorization: Bearer YOUR_TOKEN' \
    -H 'Version: 2021-07-28' \
    -H 'Content-Type: application/json' \
    -d '{
    "locationId": "clF1LD04GTUKN3b3XuOj",
    "associationId": "ve9EPM428h8vShlRW1KT",
    "firstRecordId": "ve9EPM428h8vShlRW1KT",
    "secondRecordId": "ve9EPM428h8vShlRW1KT"
  }'
  ```

  ```javascript Node.js theme={null}
  const response = await fetch('https://services.leadconnectorhq.com/associations/relations', {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${process.env.LEADWAY_TOKEN}`,
      Version: '2021-07-28',
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({"locationId": "clF1LD04GTUKN3b3XuOj", "associationId": "ve9EPM428h8vShlRW1KT", "firstRecordId": "ve9EPM428h8vShlRW1KT", "secondRecordId": "ve9EPM428h8vShlRW1KT"}),
  });
  const data = await response.json();
  ```

  ```python Python theme={null}
  import os, requests
  response = requests.request(
      'POST',
      'https://services.leadconnectorhq.com/associations/relations',
      headers={
          'Authorization': f"Bearer {os.environ['LEADWAY_TOKEN']}",
          'Version': '2021-07-28',
          'Content-Type': 'application/json',
      },
      json={"locationId": "clF1LD04GTUKN3b3XuOj", "associationId": "ve9EPM428h8vShlRW1KT", "firstRecordId": "ve9EPM428h8vShlRW1KT", "secondRecordId": "ve9EPM428h8vShlRW1KT"},
  )
  data = response.json()
  ```

  ```php PHP theme={null}
  <?php
  $ch = curl_init('https://services.leadconnectorhq.com/associations/relations');
  curl_setopt_array($ch, [
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_CUSTOMREQUEST => 'POST',
      CURLOPT_HTTPHEADER => [
          'Authorization: Bearer ' . getenv('LEADWAY_TOKEN'),
          'Version: 2021-07-28',
          'Content-Type: application/json',
      ],
      CURLOPT_POSTFIELDS => json_encode({'locationId': 'clF1LD04GTUKN3b3XuOj', 'associationId': 've9EPM428h8vShlRW1KT', 'firstRecordId': 've9EPM428h8vShlRW1KT', 'secondRecordId': 've9EPM428h8vShlRW1KT'}),
  ]);
  $data = json_decode(curl_exec($ch), true);
  ```
</CodeGroup>
