POST/ companies/ :id/ add_member/
Company add member
You can add an employee (a user) to a company.
Attributes
Optional unless marked required
- id
- A unique identifier for the company which is given by User automatically.
- user_id
- A unique identifier for the user which is given by User automatically. Send this or
user_custom_id. - user_custom_id
- A unique identifier for the user which is provided by the client. Send this or
user_id.
Send one of user_id and user_custom_id to point at the contact. Adding a contact that's already a member of the company answers 201 again, not an error.
Request
- cURL
- JavaScript
- PHP
- Python
curl -X POST "https://<your_app_subdomain>.user.com/api/public/companies/:id/add_member/" \
-H "Authorization: Token <your_64_char_api_key>" \
-H "Accept: */*; version=2" \
-H "Content-Type: application/json" \
-d '{
"user_id": 1884
}'
const response = await fetch(
"https://<your_app_subdomain>.user.com/api/public/companies/:id/add_member/",
{
method: "POST",
headers: {
Authorization: "Token <your_64_char_api_key>",
Accept: "*/*; version=2",
"Content-Type": "application/json",
},
body: JSON.stringify({
user_id: 1884,
}),
},
);
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/:id/add_member/",
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([
"user_id" => 1884,
]),
]);
$response = curl_exec($curl);
curl_close($curl);
echo $response;
import requests
response = requests.post(
"https://<your_app_subdomain>.user.com/api/public/companies/:id/add_member/",
headers={
"Authorization": "Token <your_64_char_api_key>",
"Accept": "*/*; version=2",
},
json={
"user_id": 1884,
},
)
print(response.json())
Response examples
- 201 Created
- 400 Bad Request
- 404 Not Found
{
"success": true
}
{
"error": "'user_id' or 'user_custom_id' field is necessary."
}
{
"detail": "No Company matches the given query."
}
A 400 comes with one of these messages:
| Message | When |
|---|---|
'user_id' or 'user_custom_id' field is necessary. | The body has neither field. |
Given value is not matching any user. | No contact has that user_id or user_custom_id. |
Response fields
Fields returned in the 201 Created response body.
- success
truewhen the contact was added to the company.
note
Errors that can come from any endpoint (401, 429, 500, 502, 504) are described in HTTP response codes.