Creating resources via POST request in the REST API
This article provides the steps to create Autotask resources by using POST operations in the REST API.
To help you learn how to construct requests to the Autotask REST API, Datto provides a customizable REST API request collection for use with Postman. For more information, refer to Sample requests.
Overview
You can create a resource in Autotask via the API by using a POST request.
NOTE You can refer to the Online Help to find root and child access URLs of the entity you wish to query. Refer to Finding resource and child access URLs of REST API entities for more information.
Syntax examples: Creating resources with POST
The non-UDF example demonstrates how to create a ContactGroups resource with POST.
In the UDF example, the POST action will create a new company in Autotask with an account type of Customer(1) and a user-defined field populated with a starting value. The response will contain the ID of the newly created company.
URL:
https://webservices[n].autotask.net/atservicesrest/v1.0/ContactGroups
Body:
{
"id": "0",
"Name": "Test 1 Create of Contact Group x",
"IsActive": "True"
}
IMPORTANT You can only query by one user-defined field at a time.
URL:
https://webservices[n].autotask.net/atservicesrest/v1.0/Companies
Body:
{
"companyName":"A Company",
"companyType":1,
"ownerResourceID":4,
"phone":"5555555555",
"userDefinedFields": [
{
"name": "CustomerRanking",
"value": "not Golden"
}
]
}
Verifying success or failure
When making operational calls, you will not receive a JSON-formatted response. Creating data will return a JSON-formatted response, which will either be the item ID of the created resource or an error string array. You can verify the success or failure of operational calls by checking their return HTTP status code.
Successful operations will return an HttpStatusCode of 200 with a response that looks similar to this example:
EXAMPLE "itemId": 4
Unsuccessful operations will return an HttpStatusCode of 500 with a response that looks similar to this example:
EXAMPLE {"errors":["A ContactGroup already exists with Name [Test 1 Create of Contact Group x]. ContactGroup names must be unique."]}
An unsuccessful operation might also return a 400-series response, depending on the cause of the error. In general, it's a best practice to treat any response other than 200 as an error state.