> ## 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.

# Upsert Contact

> Please find the list of acceptable values for the `country` field  here<br/><br/>The Upsert API will adhere to the configuration defined under the “Allow Duplicate Contact” setting at the Account leve

Please find the list of acceptable values for the `country` field  here\<br/>\<br/>The Upsert API will adhere to the configuration defined under the “Allow Duplicate Contact” setting at the Account level. If the setting is configured to check both Email and Phone, the API will attempt to identify an existing contact based on the priority sequence specified in the setting, and will create or update the contact accordingly.\<br/>\<br/>If two separate contacts already exist—one with the same email and another with the same phone—and an upsert request includes both the email and phone, the API will update the contact that matches the first field in the configured sequence, and ignore the second field to prevent duplication.

```http theme={null}
POST https://services.leadconnectorhq.com/contacts/upsert
```

## 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="firstName" type="string" default="Rosan" />

<ParamField body="lastName" type="string" default="Deo" />

<ParamField body="name" type="string" default="Rosan Deo" />

<ParamField body="email" type="string" default="rosan@deos.com" />

<ParamField body="locationId" type="string" required default="ve9EPM428h8vShlRW1KT" />

<ParamField body="gender" type="string" default="male" />

<ParamField body="phone" type="string" default="+1 888-888-8888" />

<ParamField body="address1" type="string" default="3535 1st St N" />

<ParamField body="city" type="string" default="Dolomite" />

<ParamField body="state" type="string" default="AL" />

<ParamField body="postalCode" type="string" default="35061" />

<ParamField body="website" type="string" default="https://www.tesla.com" />

<ParamField body="timezone" type="string" default="America/Chihuahua" />

<ParamField body="dnd" type="boolean" default="True" />

<ParamField body="dndSettings" type="object">
  <Expandable title="propiedades">
    <ParamField body="Call" type="object">
      <Expandable title="propiedades">
        <ParamField body="status" type="string" required>
          Posibles valores: 'active', 'inactive', 'permanent'
        </ParamField>

        <ParamField body="message" type="string" />

        <ParamField body="code" type="string" />
      </Expandable>
    </ParamField>

    <ParamField body="Email" type="object">
      <Expandable title="propiedades">
        <ParamField body="status" type="string" required>
          Posibles valores: 'active', 'inactive', 'permanent'
        </ParamField>

        <ParamField body="message" type="string" />

        <ParamField body="code" type="string" />
      </Expandable>
    </ParamField>

    <ParamField body="SMS" type="object">
      <Expandable title="propiedades">
        <ParamField body="status" type="string" required>
          Posibles valores: 'active', 'inactive', 'permanent'
        </ParamField>

        <ParamField body="message" type="string" />

        <ParamField body="code" type="string" />
      </Expandable>
    </ParamField>

    <ParamField body="WhatsApp" type="object">
      <Expandable title="propiedades">
        <ParamField body="status" type="string" required>
          Posibles valores: 'active', 'inactive', 'permanent'
        </ParamField>

        <ParamField body="message" type="string" />

        <ParamField body="code" type="string" />
      </Expandable>
    </ParamField>

    <ParamField body="GMB" type="object">
      <Expandable title="propiedades">
        <ParamField body="status" type="string" required>
          Posibles valores: 'active', 'inactive', 'permanent'
        </ParamField>

        <ParamField body="message" type="string" />

        <ParamField body="code" type="string" />
      </Expandable>
    </ParamField>

    <ParamField body="FB" type="object">
      <Expandable title="propiedades">
        <ParamField body="status" type="string" required>
          Posibles valores: 'active', 'inactive', 'permanent'
        </ParamField>

        <ParamField body="message" type="string" />

        <ParamField body="code" type="string" />
      </Expandable>
    </ParamField>
  </Expandable>
</ParamField>

<ParamField body="inboundDndSettings" type="object">
  <Expandable title="propiedades">
    <ParamField body="all" type="object">
      <Expandable title="propiedades">
        <ParamField body="status" type="string" required>
          Posibles valores: 'active', 'inactive'
        </ParamField>

        <ParamField body="message" type="string" />
      </Expandable>
    </ParamField>
  </Expandable>
</ParamField>

<ParamField body="tags" type="string[]">
  This field will overwrite all current tags associated with the contact. To update a tags, it is recommended to use the Add Tag or Remove Tag API instead.
</ParamField>

<ParamField body="customFields" type="object[]" />

<ParamField body="source" type="string" default="public api" />

<ParamField body="dateOfBirth" type="object" default="1990-09-25">
  The birth date of the contact. Supported formats: YYYY/MM/DD, MM/DD/YYYY, YYYY-MM-DD, MM-DD-YYYY, YYYY.MM.DD, MM.DD.YYYY, YYYY\_MM\_DD, MM\_DD\_YYYY
</ParamField>

<ParamField body="country" type="string" default="US" />

<ParamField body="companyName" type="string" default="DGS VolMAX" />

<ParamField body="assignedTo" type="string" default="y0BeYjuRIlDwsDcOHOJo">
  User's Id
</ParamField>

<ParamField body="createNewIfDuplicateAllowed" type="boolean" default="False">
  Controls whether to create a new contact or update an existing duplicate. **Scenario 1:** If this value is `true` and the account allows duplicate contacts, a new contact will be created immediately without checking for duplicates. **Scenario 2:** If this value is `true` but the account does not allow duplicate contacts, this field is ignored and the normal upsert behavior applies: the API will search for an existing duplicate contact, update it if found, or create a new contact if not found. **Scenario 3:** If this value is `false` or not provided, the normal upsert behavior applies regardless of the account's duplicate contact setting.
</ParamField>

## Respuestas

<Accordion title="200 - Successful response">
  <ResponseField name="new" type="boolean" default="True" />

  <ResponseField name="contact" type="object">
    <Expandable title="propiedades">
      <ResponseField name="id" type="string" default="seD4PfOuKoVMLkEZqohJ" />

      <ResponseField name="name" type="string" default="rubika deo" />

      <ResponseField name="locationId" type="string" default="ve9EPM428h8vShlRW1KT" />

      <ResponseField name="firstName" type="string" default="rubika" />

      <ResponseField name="lastName" type="string" default="Deo" />

      <ResponseField name="email" type="string" default="rubika@deos.com" />

      <ResponseField name="emailLowerCase" type="string" default="rubika@deos.com" />

      <ResponseField name="timezone" type="string" default="Asia/Calcutta" />

      <ResponseField name="companyName" type="string" default="DGS VolMAX" />

      <ResponseField name="phone" type="string" default="+18832327657" />

      <ResponseField name="dnd" type="boolean" default="True" />

      <ResponseField name="dndSettings" type="object">
        <Expandable title="propiedades">
          <ResponseField name="Call" type="object">
            <Expandable title="propiedades">
              <ResponseField name="status" type="string" required>
                Posibles valores: 'active', 'inactive', 'permanent'
              </ResponseField>

              <ResponseField name="message" type="string" />

              <ResponseField name="code" type="string" />
            </Expandable>
          </ResponseField>

          <ResponseField name="Email" type="object">
            <Expandable title="propiedades">
              <ResponseField name="status" type="string" required>
                Posibles valores: 'active', 'inactive', 'permanent'
              </ResponseField>

              <ResponseField name="message" type="string" />

              <ResponseField name="code" type="string" />
            </Expandable>
          </ResponseField>

          <ResponseField name="SMS" type="object">
            <Expandable title="propiedades">
              <ResponseField name="status" type="string" required>
                Posibles valores: 'active', 'inactive', 'permanent'
              </ResponseField>

              <ResponseField name="message" type="string" />

              <ResponseField name="code" type="string" />
            </Expandable>
          </ResponseField>

          <ResponseField name="WhatsApp" type="object">
            <Expandable title="propiedades">
              <ResponseField name="status" type="string" required>
                Posibles valores: 'active', 'inactive', 'permanent'
              </ResponseField>

              <ResponseField name="message" type="string" />

              <ResponseField name="code" type="string" />
            </Expandable>
          </ResponseField>

          <ResponseField name="GMB" type="object">
            <Expandable title="propiedades">
              <ResponseField name="status" type="string" required>
                Posibles valores: 'active', 'inactive', 'permanent'
              </ResponseField>

              <ResponseField name="message" type="string" />

              <ResponseField name="code" type="string" />
            </Expandable>
          </ResponseField>

          <ResponseField name="FB" type="object">
            <Expandable title="propiedades">
              <ResponseField name="status" type="string" required>
                Posibles valores: 'active', 'inactive', 'permanent'
              </ResponseField>

              <ResponseField name="message" type="string" />

              <ResponseField name="code" type="string" />
            </Expandable>
          </ResponseField>
        </Expandable>
      </ResponseField>

      <ResponseField name="type" type="string" default="read" />

      <ResponseField name="source" type="string" default="public api" />

      <ResponseField name="assignedTo" type="string" default="ve9EPM428h8vShlRW1KT" />

      <ResponseField name="address1" type="string" default="3535 1st St N" />

      <ResponseField name="city" type="string" default="ruDolomitebika" />

      <ResponseField name="state" type="string" default="AL" />

      <ResponseField name="country" type="string" default="US" />

      <ResponseField name="postalCode" type="string" default="35061" />

      <ResponseField name="website" type="string" default="https://www.tesla.com" />

      <ResponseField name="tags" type="string[]" />

      <ResponseField name="dateOfBirth" type="string" default="Date format YYYY-MM-DD" />

      <ResponseField name="dateAdded" type="string" default="2021-07-02T05:18:26.704Z" />

      <ResponseField name="dateUpdated" type="string" default="2021-07-02T05:18:26.704Z" />

      <ResponseField name="attachments" type="string" />

      <ResponseField name="ssn" type="string" />

      <ResponseField name="keyword" type="string" default="test" />

      <ResponseField name="firstNameLowerCase" type="string" default="rubika" />

      <ResponseField name="fullNameLowerCase" type="string" default="rubika deo" />

      <ResponseField name="lastNameLowerCase" type="string" default="deo" />

      <ResponseField name="lastActivity" type="string" default="2021-07-16T11:39:30.564Z" />

      <ResponseField name="customFields" type="object[]">
        <Expandable title="cada item">
          <ResponseField name="id" type="string" default="MgobCB14YMVKuE4Ka8p1" />

          <ResponseField name="value" type="string" default="name" />
        </Expandable>
      </ResponseField>

      <ResponseField name="businessId" type="string" default="641c094001436dbc2081e642" />

      <ResponseField name="attributionSource" type="object">
        <Expandable title="propiedades">
          <ResponseField name="url" type="string" required default="Trigger Link" />

          <ResponseField name="campaign" type="string" />

          <ResponseField name="utmSource" type="string" />

          <ResponseField name="utmMedium" type="string" />

          <ResponseField name="utmContent" type="string" />

          <ResponseField name="referrer" type="string" default="https: //www.google.com" />

          <ResponseField name="campaignId" type="string" />

          <ResponseField name="fbclid" type="string" />

          <ResponseField name="gclid" type="string" default="CjOKCQjwnNyUBhCZARISAI9AYIFtNnIcWcYGIOQINz_ZoFI5SSLRRugSoPZoiEu27IZBY£1-MAIWmEaAo2VEALW_WCB" />

          <ResponseField name="msclikid" type="string" />

          <ResponseField name="dclid" type="string" />

          <ResponseField name="fbc" type="string" />

          <ResponseField name="fbp" type="string" default="fb. 1.1674748390986.1171287961" />

          <ResponseField name="fbEventId" type="string" default="Mozilla/5.0" />

          <ResponseField name="userAgent" type="string" default="Mozilla/5.0" />

          <ResponseField name="ip" type="string" default="58.111.106.198" />

          <ResponseField name="medium" type="string" default="survey" />

          <ResponseField name="mediumId" type="string" default="FglfHAn30PRwsZVyQlKp" />
        </Expandable>
      </ResponseField>

      <ResponseField name="lastAttributionSource" type="object">
        <Expandable title="propiedades">
          <ResponseField name="url" type="string" required default="Trigger Link" />

          <ResponseField name="campaign" type="string" />

          <ResponseField name="utmSource" type="string" />

          <ResponseField name="utmMedium" type="string" />

          <ResponseField name="utmContent" type="string" />

          <ResponseField name="referrer" type="string" default="https: //www.google.com" />

          <ResponseField name="campaignId" type="string" />

          <ResponseField name="fbclid" type="string" />

          <ResponseField name="gclid" type="string" default="CjOKCQjwnNyUBhCZARISAI9AYIFtNnIcWcYGIOQINz_ZoFI5SSLRRugSoPZoiEu27IZBY£1-MAIWmEaAo2VEALW_WCB" />

          <ResponseField name="msclikid" type="string" />

          <ResponseField name="dclid" type="string" />

          <ResponseField name="fbc" type="string" />

          <ResponseField name="fbp" type="string" default="fb. 1.1674748390986.1171287961" />

          <ResponseField name="fbEventId" type="string" default="Mozilla/5.0" />

          <ResponseField name="userAgent" type="string" default="Mozilla/5.0" />

          <ResponseField name="ip" type="string" default="58.111.106.198" />

          <ResponseField name="medium" type="string" default="survey" />

          <ResponseField name="mediumId" type="string" default="FglfHAn30PRwsZVyQlKp" />
        </Expandable>
      </ResponseField>

      <ResponseField name="visitorId" type="string" default="ve9EPM428h8vShlRW1KT">
        visitorId is the Unique ID assigned to each Live chat visitor.
      </ResponseField>
    </Expandable>
  </ResponseField>

  <ResponseField name="traceId" type="string" />

  ```json theme={null}
  {
    "new": true,
    "contact": {
      "id": "seD4PfOuKoVMLkEZqohJ",
      "name": "rubika deo",
      "locationId": "ve9EPM428h8vShlRW1KT",
      "firstName": "rubika",
      "lastName": "Deo",
      "email": "rubika@deos.com",
      "emailLowerCase": "rubika@deos.com",
      "timezone": "Asia/Calcutta",
      "companyName": "DGS VolMAX",
      "phone": "+18832327657",
      "dnd": true,
      "dndSettings": {
        "Call": {
          "status": "active",
          "message": "string",
          "code": "string"
        },
        "Email": {
          "status": "active",
          "message": "string",
          "code": "string"
        },
        "SMS": {
          "status": "active",
          "message": "string",
          "code": "string"
        },
        "WhatsApp": {
          "status": "active",
          "message": "string",
          "code": "string"
        },
        "GMB": {
          "status": "active",
          "message": "string",
          "code": "string"
    // truncado: 81 lineas mas
  }
  ```
</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/contacts/upsert' \
    -H 'Authorization: Bearer YOUR_TOKEN' \
    -H 'Version: 2021-07-28' \
    -H 'Content-Type: application/json' \
    -d '{
    "firstName": "Rosan",
    "lastName": "Deo",
    "name": "Rosan Deo",
    "email": "rosan@deos.com",
    "locationId": "ve9EPM428h8vShlRW1KT",
    "gender": "male",
    "phone": "+1 888-888-8888",
    "address1": "3535 1st St N",
    "city": "Dolomite",
    "state": "AL",
    "postalCode": "35061",
    "website": "https://www.tesla.com",
    "timezone": "America/Chihuahua",
    "dnd": true,
    "dndSettings": {
      "Call": {
        "status": "active",
        "message": "string",
        "code": "string"
      },
      "Email": {
        "status": "active",
        "message": "string",
        "code": "string"
      },
      "SMS": {
        "status": "active",
        "message": "string",
        "code": "string"
      },
      "WhatsApp": {
        "status": "active",
        "message": "string",
        "code": "string"
      },
      "GMB": {
        "status": "active",
        "message": "string",
        "code": "string"
      },
      "FB": {
        "status": "active",
        "message": "string",
        "code": "string"
      }
    },
    "inboundDndSettings": {
      "all": {
        "status": "active",
        "message": "string"
      }
    },
    "tags": [
      "nisi sint commodo amet",
      "consequat"
    ],
    "customFields": [],
    "source": "public api",
    "dateOfBirth": "1990-09-25",
    "country": "US",
    "companyName": "DGS VolMAX",
    "assignedTo": "y0BeYjuRIlDwsDcOHOJo",
    "createNewIfDuplicateAllowed": false
  }'
  ```

  ```javascript Node.js theme={null}
  const response = await fetch('https://services.leadconnectorhq.com/contacts/upsert', {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${process.env.LEADWAY_TOKEN}`,
      Version: '2021-07-28',
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({"firstName": "Rosan", "lastName": "Deo", "name": "Rosan Deo", "email": "rosan@deos.com", "locationId": "ve9EPM428h8vShlRW1KT", "gender": "male", "phone": "+1 888-888-8888", "address1": "3535 1st St N", "city": "Dolomite", "state": "AL", "postalCode": "35061", "website": "https://www.tesla.com", "timezone": "America/Chihuahua", "dnd": true, "dndSettings": {"Call": {"status": "active", "message": "string", "code": "string"}, "Email": {"status": "active", "message": "string", "code": "string"}, "SMS": {"status": "active", "message": "string", "code": "string"}, "WhatsApp": {"status": "active", "message": "string", "code": "string"}, "GMB": {"status": "active", "message": "string", "code": "string"}, "FB": {"status": "active", "message": "string", "code": "string"}}, "inboundDndSettings": {"all": {"status": "active", "message": "string"}}, "tags": ["nisi sint commodo amet", "consequat"], "customFields": [], "source": "public api", "dateOfBirth": "1990-09-25", "country": "US", "companyName": "DGS VolMAX", "assignedTo": "y0BeYjuRIlDwsDcOHOJo", "createNewIfDuplicateAllowed": false}),
  });
  const data = await response.json();
  ```

  ```python Python theme={null}
  import os, requests
  response = requests.request(
      'POST',
      'https://services.leadconnectorhq.com/contacts/upsert',
      headers={
          'Authorization': f"Bearer {os.environ['LEADWAY_TOKEN']}",
          'Version': '2021-07-28',
          'Content-Type': 'application/json',
      },
      json={"firstName": "Rosan", "lastName": "Deo", "name": "Rosan Deo", "email": "rosan@deos.com", "locationId": "ve9EPM428h8vShlRW1KT", "gender": "male", "phone": "+1 888-888-8888", "address1": "3535 1st St N", "city": "Dolomite", "state": "AL", "postalCode": "35061", "website": "https://www.tesla.com", "timezone": "America/Chihuahua", "dnd": true, "dndSettings": {"Call": {"status": "active", "message": "string", "code": "string"}, "Email": {"status": "active", "message": "string", "code": "string"}, "SMS": {"status": "active", "message": "string", "code": "string"}, "WhatsApp": {"status": "active", "message": "string", "code": "string"}, "GMB": {"status": "active", "message": "string", "code": "string"}, "FB": {"status": "active", "message": "string", "code": "string"}}, "inboundDndSettings": {"all": {"status": "active", "message": "string"}}, "tags": ["nisi sint commodo amet", "consequat"], "customFields": [], "source": "public api", "dateOfBirth": "1990-09-25", "country": "US", "companyName": "DGS VolMAX", "assignedTo": "y0BeYjuRIlDwsDcOHOJo", "createNewIfDuplicateAllowed": false},
  )
  data = response.json()
  ```

  ```php PHP theme={null}
  <?php
  $ch = curl_init('https://services.leadconnectorhq.com/contacts/upsert');
  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({'firstName': 'Rosan', 'lastName': 'Deo', 'name': 'Rosan Deo', 'email': 'rosan@deos.com', 'locationId': 've9EPM428h8vShlRW1KT', 'gender': 'male', 'phone': '+1 888-888-8888', 'address1': '3535 1st St N', 'city': 'Dolomite', 'state': 'AL', 'postalCode': '35061', 'website': 'https://www.tesla.com', 'timezone': 'America/Chihuahua', 'dnd': true, 'dndSettings': {'Call': {'status': 'active', 'message': 'string', 'code': 'string'}, 'Email': {'status': 'active', 'message': 'string', 'code': 'string'}, 'SMS': {'status': 'active', 'message': 'string', 'code': 'string'}, 'WhatsApp': {'status': 'active', 'message': 'string', 'code': 'string'}, 'GMB': {'status': 'active', 'message': 'string', 'code': 'string'}, 'FB': {'status': 'active', 'message': 'string', 'code': 'string'}}, 'inboundDndSettings': {'all': {'status': 'active', 'message': 'string'}}, 'tags': ['nisi sint commodo amet', 'consequat'], 'customFields': [], 'source': 'public api', 'dateOfBirth': '1990-09-25', 'country': 'US', 'companyName': 'DGS VolMAX', 'assignedTo': 'y0BeYjuRIlDwsDcOHOJo', 'createNewIfDuplicateAllowed': false}),
  ]);
  $data = json_decode(curl_exec($ch), true);
  ```
</CodeGroup>
