Companies API
π Why Use the Companies API?β
Companies are a foundational entity in DataDocks that represent organizations interacting with your warehousesβboth carriers that transport goods and customers that send or receive them. The Companies API enables you to programmatically manage these relationships, synchronizing company data with your ERP, CRM, or other business systems.
Real Problems This API Solvesβ
- Maintain a single source of truth: Sync company data between your enterprise systems and DataDocks
- Streamline onboarding: Automatically create carrier and customer records when added to your systems
- Enhance data accuracy: Keep contact information and shipping preferences current
- Automate relationship management: Programmatically control which companies can interact with each other
5-Minute Quickstartβ
Want to see the API in action right now? Follow these steps to get your first company created:
- Get your API token from support
- Find your location subdomain (e.g.,
your-warehouse.datadocks.com) - Create a basic company with this command:
See cURL example
curl -X POST \
https://your-warehouse.datadocks.com/api/v1/companies \
-H 'Authorization: Token YOUR_API_TOKEN' \
-H 'Content-Type: application/json' \
-d '{
"company": {
"name": "Acme Logistics",
"company_type": "carrier",
"company_number": "ACME-001",
"email": "dispatch@acmelogistics.example.com",
"phone": "+15551234567"
}
}'
- VoilΓ ! You've created your first company. Check your DataDocks dashboard to see it.
API Architecture Overviewβ
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β Your System ββββββββΆβ DataDocks API ββββββββΆβ Warehouse Ops β
β (ERP/CRM/TMS) βββββββββ€ (REST/JSON) βββββββββ€ (Companies) β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β β²
β β
βΌ β
βββββββββββββββββββ
β Carrier/ β
β Customer β
β Portals β
βββββββββββββββββββ
Authenticationβ
All API requests must include your API token in the Authorization header:
Authorization: Token YOUR_API_TOKEN
Listing Companiesβ
Purposeβ
Retrieve a paginated list of companies with optional filtering by company type, name, or company number. Use this endpoint for syncing companies with your systems or generating reports.
Business Use Casesβ
- Sync companies with your ERP or CRM system
- Generate reports on carriers or customers
- Display company information in your custom dashboards
- Filter companies by type for specialized processing
HTTP Requestβ
GET https://[location_subdomain].datadocks.com/api/v1/companies
Query Parametersβ
| Parameter | Type | Required | Description | Example |
|---|---|---|---|---|
page | Integer | No | Page number for pagination (defaults to 1) | page=2 |
company_type | String | No | Filter by company type (case-insensitive) | company_type=carrier |
name | String | No | Filter by company name (case-insensitive, starts with match) | name=acme |
company_number | String | No | Filter by company number (case-insensitive, exact match) | company_number=ACME-001 |
Response Formatβ
The response contains a paginated array of company objects, each with the following fields:
| Field | Type | Description |
|---|---|---|
id | Integer | Unique identifier for the company |
parent_id | Integer | ID of parent company (null if none) |
company_type | String | Type of company ("carrier", "customer", or "both") |
name | String | Name of the company |
company_number | String | Unique external identifier for the company |
email | String | Primary email address for the company |
phone | String | Primary phone number for the company |
street | String | Street address |
unit | String | Unit or suite number |
city | String | City |
province | String | Province or state |
country | String | Country code (2-letter ISO code) |
postal | String | Postal or ZIP code |
category | String | Category or classification |
auto_approve_appointments | Boolean | Whether appointments are automatically approved |
can_create_carriers | Boolean | Whether this company can create carrier companies |
notifications | Boolean | Whether this company receives notifications |
custom_values | Object | Key-value pairs of custom fields |
users | Array | List of users associated with this company |
Code Examplesβ
cURLβ
See cURL example
# Basic listing
curl -H "Authorization: Token YOUR_API_TOKEN" \
https://YOUR_LOCATION.datadocks.com/api/v1/companies
# Filtered by company type and name
curl -H "Authorization: Token YOUR_API_TOKEN" \
"https://YOUR_LOCATION.datadocks.com/api/v1/companies?company_type=carrier&name=logistic"
JavaScriptβ
See JavaScript example
// Using fetch API with filters
const getCompanies = async (companyType, nameFilter, companyNumber) => {
const params = new URLSearchParams();
if (companyType) params.append("company_type", companyType);
if (nameFilter) params.append("name", nameFilter);
if (companyNumber) params.append("company_number", companyNumber);
const response = await fetch(
`https://YOUR_LOCATION.datadocks.com/api/v1/companies?${params.toString()}`,
{
method: "GET",
headers: {
Authorization: "Token YOUR_API_TOKEN",
"Content-Type": "application/json",
},
}
);
// Handle potential errors
if (!response.ok) {
const errorData = await response.json();
throw new Error(`Failed to fetch companies: ${JSON.stringify(errorData)}`);
}
return response.json();
};
Sample Responseβ
See sample response example
[
{
"id": 1,
"parent_id": null,
"company_type": "carrier",
"name": "Joe's Shipping",
"company_number": "A17727959343",
"email": "info@joesshipping.com",
"phone": "+14161231234",
"street": "1 Yonge St.",
"unit": null,
"city": "Toronto",
"province": "ON",
"country": "CA",
"postal": "M8H 1G1",
"category": null,
"auto_approve_appointments": true,
"can_create_carriers": false,
"notifications": true,
"custom_values": {
"ap_contact": "Sue Brown",
"sales_contact": "Tim Jones",
"facility_contact": "John Green"
},
"users": [
{
"email": "driver@joesshipping.com",
"name": "Joe Driver"
}
]
},
{
"id": 2,
"parent_id": null,
"company_type": "customer",
"name": "Spatula City",
"company_number": "B83582616848",
"email": "info@spatulacity.com",
"phone": "+14161231234",
"street": "1 Yonge St.",
"unit": "4",
"city": "Toronto",
"province": "ON",
"country": "CA",
"postal": "M8H 1G1",
"category": null,
"auto_approve_appointments": false,
"can_create_carriers": true,
"notifications": false,
"custom_values": {
"ap_contact": "",
"sales_contact": "Al Yankovic",
"facility_contact": ""
},
"users": []
}
]
Paginationβ
The response is paginated to manage data volume. For detailed information about pagination headers and navigation, please refer to the Pagination documentation.
Retrieving a Single Companyβ
Purposeβ
Get detailed information about a specific company by ID. Use this endpoint when you need comprehensive data about a particular company.
Business Use Casesβ
- Display detailed company information in your application
- Verify company details before processing transactions
- Retrieve current contact information for communications
- Access company-specific settings and preferences
HTTP Requestβ
GET https://[location_subdomain].datadocks.com/api/v1/companies/:id
Path Parametersβ
| Parameter | Type | Required | Description |
|---|---|---|---|
id | Integer | Yes | Unique ID of the company |
Responseβ
A successful request returns a 200 OK response with the full company object in the same format as the list response.
Code Examplesβ
cURLβ
See cURL example
curl -H "Authorization: Token YOUR_API_TOKEN" \
https://YOUR_LOCATION.datadocks.com/api/v1/companies/123
JavaScriptβ
See JavaScript example
const getCompany = async (companyId) => {
try {
const response = await fetch(
`https://YOUR_LOCATION.datadocks.com/api/v1/companies/${companyId}`,
{
method: "GET",
headers: {
Authorization: "Token YOUR_API_TOKEN",
"Content-Type": "application/json",
},
}
);
if (!response.ok) {
if (response.status === 404) {
throw new Error(`Company #${companyId} not found`);
}
const errorData = await response.json();
throw new Error(
`Failed to retrieve company: ${JSON.stringify(errorData)}`
);
}
return await response.json();
} catch (error) {
console.error("Error fetching company:", error);
throw error;
}
};
Creating a Companyβ
Purposeβ
Create a new company record in DataDocks. This endpoint allows you to add new carriers or customers to your system programmatically.
Decision Tree: When to Create a Company via APIβ
βββββββββββββββββββ
β Need to add a β
β company? β
ββββββββββ¬βββββββββ
β
βΌ
βββββββββββββββββββ Yes βββββββββββββββββββ
β Adding many ββββββββββββββΆβ Consider β
β companies at β β bulk import β
β once? β β β
ββββββββββ¬βββββββββ βββββββββββββββββββ
β No
βΌ
βββββββββββββββββββ Yes βββββββββββββββββββ
β Is this a one- ββββββββββββββΆβ Use the web β
β time addition? β β interface β
ββββββββββ¬βββββββββ βββββββββββββββββββ
β No
βΌ
βββββββββββββββββββ
β Perfect for β
β the API! β
βββββββββββββββββββ
Business Use Casesβ
- System Integration: Create companies directly from your ERP or CRM
- Automated Onboarding: Programmatically set up new carriers or customers
- Data Migration: Transfer company records from legacy systems
- Partner Integration: Allow partners to register companies through your systems
HTTP Requestβ
POST https://[location_subdomain].datadocks.com/api/v1/companies
Request Bodyβ
| Parameter | Type | Required | Description | Constraints | Default | Example |
|---|---|---|---|---|---|---|
name | String | Yes | Name of the company | 2-164 chars, unique within org (case-insensitive) | None | "Acme Logistics" |
company_type | String | Yes | Type of company | "carrier", "customer", or "both" | None | "carrier" |
company_number | String | No | External identifier | Unique within org | Random 11-digit number | "ACME-001" |
email | String | No | Primary email address | Valid email format, 4-128 chars | None | "info@example.com" |
phone | String | No | Primary phone number | None | None | "+15551234567" |
street | String | No | Street address | 4-64 chars if provided | None | "123 Main St" |
unit | String | No | Unit or suite number | 1-64 chars if provided | None | "Suite 400" |
city | String | No | City | 2-64 chars if provided | None | "Chicago" |
province | String | No | Province or state | None | None | "IL" |
country | String | No | Country code | 2 chars if provided (ISO code) | None | "US" |
postal | String | No | Postal or ZIP code | 4-10 chars if provided | None | "60601" |
category | String | No | Category or classification | None | None | "Premium" |
auto_approve_appointments | Boolean | No | Auto-approve appointments | None | false | true |
can_create_carriers | Boolean | No | Can create carriers | None | false | false |
notifications | Boolean | No | Receives notifications | None | false | true |
can_book_drop_trailers | Boolean | No | Can book drop trailers | None | true | true |
send_appointment_no_show_notifications | Boolean | No | Sends no-show notifications | None | true | true |
send_appointment_late_notifications | Boolean | No | Sends late notifications | None | true | true |
custom_values | Object | No | Custom field values | Based on location settings | {} | {"reference": "ABC123"} |
invite_user | String | No | Invite a user for this company | If "true", uses email field | false | "true" |
parent_id | Integer | No | Parent company ID | Must be an existing company | None | 123 |
Responseβ
A successful request returns a 200 OK response with the full company object, including the generated id and other system-assigned values.
Code Examplesβ
cURLβ
See cURL example
curl -H "Authorization: Token YOUR_API_TOKEN" \
-H "Content-Type: application/json" \
-X POST \
-d '{
"company": {
"name": "Quick Transport Inc",
"company_type": "carrier",
"company_number": "QT-2023-001",
"email": "dispatch@quicktransport.example.com",
"phone": "+15551234567",
"street": "123 Logistics Way",
"city": "Chicago",
"province": "IL",
"country": "US",
"postal": "60601",
"auto_approve_appointments": true,
"notifications": true,
"custom_values": {
"insurance_policy": "INS-567890",
"preferred_dock": "Dock 3"
},
"invite_user": "true",
"parent_id": 123
}
}' \
https://YOUR_LOCATION.datadocks.com/api/v1/companies
JavaScriptβ
See JavaScript example
const createCompany = async (companyData) => {
try {
const response = await fetch(
`https://YOUR_LOCATION.datadocks.com/api/v1/companies`,
{
method: "POST",
headers: {
Authorization: "Token YOUR_API_TOKEN",
"Content-Type": "application/json",
},
body: JSON.stringify({ company: companyData }),
}
);
if (!response.ok) {
const errorData = await response.json();
const errorMessages = Object.entries(errorData.errors || {})
.map(([field, messages]) => `${field}: ${messages.join(", ")}`)
.join("\n");
throw new Error(`Failed to create company:\n${errorMessages}`);
}
return await response.json();
} catch (error) {
console.error("API Error:", error);
throw error;
}
};
Updating a Companyβ
Purposeβ
Update an existing company's details. This endpoint allows you to modify any aspect of a company's information.
Business Use Casesβ
- Keep Data Current: Update contact information or shipping preferences
- Change Company Status: Modify notification settings or appointment approval rules
- Manage Permissions: Adjust what a company is allowed to do in the system
- Synchronize Systems: Keep DataDocks in sync with your ERP or CRM
HTTP Requestβ
PUT https://[location_subdomain].datadocks.com/api/v1/companies/:id
Path Parametersβ
| Parameter | Type | Required | Description |
|---|---|---|---|
id | Integer | Yes | Unique ID of the company |
Request Bodyβ
The request body accepts the same parameters as the create endpoint. Only the fields you want to change need to be included.
Common Update Scenariosβ
Updating Contact Informationβ
{
"company": {
"email": "new-contact@example.com",
"phone": "+15559876543"
}
}
Changing Notification Settingsβ
{
"company": {
"notifications": true,
"auto_approve_appointments": false
}
}
Updating Addressβ
{
"company": {
"street": "456 New Street",
"city": "New City",
"province": "NC",
"postal": "90210"
}
}
Code Examplesβ
cURLβ
See cURL example
curl -H "Authorization: Token YOUR_API_TOKEN" \
-H "Content-Type: application/json" \
-X PUT \
-d '{
"company": {
"name": "Updated Company Name",
"email": "newemail@example.com",
"custom_values": {
"account_manager": "Jane Smith"
}
}
}' \
https://YOUR_LOCATION.datadocks.com/api/v1/companies/123
JavaScriptβ
See JavaScript example
const updateCompany = async (companyId, updateData) => {
try {
const response = await fetch(
`https://YOUR_LOCATION.datadocks.com/api/v1/companies/${companyId}`,
{
method: "PUT",
headers: {
Authorization: "Token YOUR_API_TOKEN",
"Content-Type": "application/json",
},
body: JSON.stringify({ company: updateData }),
}
);
if (!response.ok) {
const errorData = await response.json();
throw new Error(`Failed to update company: ${JSON.stringify(errorData)}`);
}
return await response.json();
} catch (error) {
console.error("Error updating company:", error);
throw error;
}
};
// Example usage
const updateCompanyEmail = async (companyId, newEmail) => {
try {
const updatedCompany = await updateCompany(companyId, {
email: newEmail,
});
console.log(`Successfully updated company #${updatedCompany.id} email`);
return updatedCompany;
} catch (error) {
console.error(`Failed to update company #${companyId}:`, error);
throw error;
}
};
Error Handlingβ
| Error Code | Description | Possible Cause |
|---|---|---|
| 400 | Bad Request | Invalid values or format |
| 404 | Not Found | Company ID doesn't exist |
| 422 | Unprocessable Entity | Validation failed (e.g., duplicate name) |
| 401 | Unauthorized | Invalid or missing API token |
| 403 | Forbidden | Insufficient permissions to update |
Deleting a Companyβ
Purposeβ
Remove a company from the system. This endpoint allows you to delete companies that are no longer needed.
Important Considerationsβ
Before deleting a company, consider the following:
- The company must not have any active appointments
- The company must not be referenced by any active packing lists
- Deletion is permanent and cannot be undone
Business Use Casesβ
- Clean Up Test Data: Remove test or dummy companies
- Comply with Privacy Requests: Delete company information upon request
- Remove Duplicate Records: Clean up after data de-duplication
- System Maintenance: Remove old, unused company records
HTTP Requestβ
DELETE https://[location_subdomain].datadocks.com/api/v1/companies/:id
Path Parametersβ
| Parameter | Type | Required | Description |
|---|---|---|---|
id | Integer | Yes | Unique ID of the company |
Responseβ
A successful request returns a 204 No Content response, indicating that the company was deleted successfully.
Code Examplesβ
cURLβ
See cURL example
curl -H "Authorization: Token YOUR_API_TOKEN" \
-X DELETE \
https://YOUR_LOCATION.datadocks.com/api/v1/companies/123
JavaScriptβ
See JavaScript example
const deleteCompany = async (companyId) => {
try {
const response = await fetch(
`https://YOUR_LOCATION.datadocks.com/api/v1/companies/${companyId}`,
{
method: "DELETE",
headers: {
Authorization: "Token YOUR_API_TOKEN",
},
}
);
if (!response.ok) {
if (response.status === 404) {
throw new Error(`Company #${companyId} not found`);
}
const errorData = await response.json();
throw new Error(`Failed to delete company: ${JSON.stringify(errorData)}`);
}
return true; // Successfully deleted
} catch (error) {
console.error("Error deleting company:", error);
throw error;
}
};