POST/ companies/ update_or_create/
Update or create company
You can create or update companies based on the "custom_id" key-value. If a company with the provided value exists, we will update its profile with provided data, otherwise, a new company will be created.
Attributes
Optional unless marked required
- custom_id
- The unique identifier for the company which is provided by the client.
- address
- A company’s address.
- city
- A company city of residence.
- country
- A company country of residence.
- created_at
- Set by User. A value sent here is ignored.
- description
- A description of a company.
- A company’s email address.
- name
- A company name. Not needed when
custom_idmatches an existing company. - phone_numbers
- A list of phone numbers.
- postal_code
- A postal code according to the address of your company..
- region
- A company region of residence.
- size
- An approximate size of your company.
- tags
- A list of tags associated with a company
- updated_at
- Set by User. A value sent here is ignored.
- assigned_to
- An agent group ID.
Request
- cURL
- JavaScript
- PHP
- Python
curl -X POST "https://<your_app_subdomain>.user.com/api/public/companies/update_or_create/" \
-H "Authorization: Token <your_64_char_api_key>" \
-H "Accept: */*; version=2" \
-H "Content-Type: application/json" \
-d '{
"custom_id": "acme-inc",
"name": "Acme Inc",
"description": "Online store selling outdoor gear since 2015."
}'
const response = await fetch(
"https://<your_app_subdomain>.user.com/api/public/companies/update_or_create/",
{
method: "POST",
headers: {
Authorization: "Token <your_64_char_api_key>",
Accept: "*/*; version=2",
"Content-Type": "application/json",
},
body: JSON.stringify({
custom_id: "acme-inc",
name: "Acme Inc",
description: "Online store selling outdoor gear since 2015.",
}),
},
);
const data = await response.json();
console.log(data);
<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://<your_app_subdomain>.user.com/api/public/companies/update_or_create/",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_HTTPHEADER => [
"Authorization: Token <your_64_char_api_key>",
"Accept: */*; version=2",
"Content-Type: application/json",
],
CURLOPT_POSTFIELDS => json_encode([
"custom_id" => "acme-inc",
"name" => "Acme Inc",
"description" => "Online store selling outdoor gear since 2015.",
]),
]);
$response = curl_exec($curl);
curl_close($curl);
echo $response;
import requests
response = requests.post(
"https://<your_app_subdomain>.user.com/api/public/companies/update_or_create/",
headers={
"Authorization": "Token <your_64_char_api_key>",
"Accept": "*/*; version=2",
},
json={
"custom_id": "acme-inc",
"name": "Acme Inc",
"description": "Online store selling outdoor gear since 2015.",
},
)
print(response.json())
Response examples
- 200 OK
- 400 Bad Request
{
"created": false,
"id": 34
}
{"size": ["A valid integer is required."]}A 400 names every field that was rejected, each with its messages. The ones you're most likely to see:
| Field | Message | When |
|---|---|---|
size | A valid integer is required. | The value isn't a whole number. |
assigned_to | Invalid pk "123" - object does not exist. | No agent has that ID. |
assigned_to | Incorrect type. Expected pk value, received str. | The value isn't a number. |
email | Enter a valid email address. | The value isn't an email address. |
phone_numbers | Expected a list of items but got type "str". | A single string instead of a list. |
The numbers inside phone_numbers aren't checked: any string is saved as it is.
Response fields
Fields returned in the 200 OK response body.
- created
trueif a new company was created,falseif an existing one was updated.- id
- Unique identifier of the company, assigned by User.
note
Errors that can come from any endpoint (401, 429, 500, 502, 504) are described in HTTP response codes.