CommTrak API
Overview
To access the CommTrak API, a short-lived access token (valid for 1 hour) is required for authentication. This article explains how to obtain and use the access token when interacting with various API endpoints. All requests to the API must include the required authentication headers, as described below.
The complete API reference is available at https://resources.commtrak.com.au/api/v1/
Client ID and Client Secret
Before you can obtain an access token, you will need to create a Client ID and a Client Secret for your application. You can learn how to do this in the Applications article.
Each application or integration that accesses the API needs its own Client ID and Client Secret. Do not share a Client ID between integrations, because requesting a new access token invalidates the previous access token for that Client ID. See Token Expiry and Renewal.
Base URL
API endpoints are accessed via the base URL:
https://yourorg.commtrak.com.au/api/v1
OAuth2 endpoints, used to obtain and refresh access tokens, are accessed via:
https://yourorg.commtrak.com.au/api
Authentication: Obtaining an Access Token
To authenticate and use the API, you need to first obtain an access token using the OAuth2 client_credentials grant. The access token is valid for 1 hour. After it expires, you can either request a new token or use your refresh token to obtain one, as described under Token Expiry and Renewal.
Requesting a new access token cancels any existing valid access token for the same Client ID.
Endpoint for Access Token Request
Request URL:
POST https://yourorg.commtrak.com.au/api/oauth2/token
Headers:
-
Authorization: Basic {client_credentials}The credentials must be sent as a Base64-encoded string in the format:
client_id:client_secret. Content-Type: application/x-www-form-urlencoded
To create the Base64-encoded credentials, join your Client ID and Client Secret with a colon (client_id:client_secret ), then Base64-encode the whole string. Encode the Client ID and Client Secret together as one string, not separately. The Authorization header is then the word Basic , a space, and the encoded string.
For example, client_id:client_secret encodes to Y2xpZW50X2lkOmNsaWVudF9zZWNyZXQ= , which is the value used in the example request below. On Linux or macOS, you can create the encoded string with:
echo -n "client_id:client_secret" | base64
The -n option stops a line break being added to the end of the string, which would make the credentials invalid. Many tools, including curl (-u client_id:client_secret ) and Postman, can create the header for you from the Client ID and Client Secret, so you do not need to encode them yourself.
Body Parameters:
grant_type=client_credentials
Example Request:
curl -X POST https://yourorg.commtrak.com.au/api/oauth2/token \ -H "Authorization: Basic Y2xpZW50X2lkOmNsaWVudF9zZWNyZXQ=" \ -H "Content-Type: application/x-www-form-urlencoded" \ -d "grant_type=client_credentials"
Response:
A successful response will return an access token and a refresh token in JSON format:
{
"access_token": "your-access-token",
"token_type": "Bearer",
"expires_in": 3600,
"refresh_token": "your-refresh-token",
"scope": "Contacts Jobs Tickets"
}
The scope value lists the scopes granted to the token, separated by spaces.
Using the Access Token
Once you have obtained the access token, it must be included in the Authorization header of all API requests to authenticate.
We recommend reusing the access token until it expires, rather than requesting a new access token for each API call. If you do request a new access token, the existing access token for that Client ID is cancelled.
Required Headers for API Requests
Include the following headers in your requests to the API:
Authorization: Bearer {access_token}Required on all requests. Replace{access_token}with the token obtained from the previous step.Content-Type: application/jsonRequired on POST, PUT, or PATCH requests.
Scopes
Each access token has a set of granted scopes, which are returned in the scope field of the token response. An endpoint can only be used if the token includes the scope it requires. For example, Staff endpoints require the Staff scope. Please refer to the CommTrak API reference for the scope required by each endpoint.
Example API Requests
The following are examples of using CommTrak API endpoints for reading and updating a CommTrak customer record. Please refer to the CommTrak API reference for details of all available endpoints: https://resources.commtrak.com.au/api/v1/
1. Searching for Customers
API reference:
https://resources.commtrak.com.au/api/v1/#/Customer/get_customer_search
Endpoint:
GET https://yourorg.commtrak.com.au/api/v1/customer/search?company_name={companyName}
Headers:
Authorization: Bearer {access_token}
Example Request:
curl -X GET "https://yourorg.commtrak.com.au/api/v1/customer/search?company_name=Acme" \ -H "Authorization: Bearer your-access-token"
Pagination:
Customer search results are returned in pages. Use the offset and limit parameters to move through the results. The maximum limit is 1000. Please refer to the CommTrak API reference for details.
Response:
A successful response will return the pagination details and a list of matching customers in JSON format:
{
"pagination": {
"count": 1,
"total": 1,
"limit": 1000,
"offset": 0
},
"data": [
{
"customer_id": 12345,
"company_name": "Acme Corporation",
"suburb": "Perth"
}
]
}
2. Fetching Customer Details
API Reference:
https://resources.commtrak.com.au/api/v1/#/Customer/get_customer_existing__customer_id_
Endpoint:
GET https://yourorg.commtrak.com.au/api/v1/customer/existing/{customerId}
Headers:
Authorization: Bearer {access_token}
Example Request:
curl -X GET "https://yourorg.commtrak.com.au/api/v1/customer/existing/12345" \ -H "Authorization: Bearer your-access-token"
Response:
A successful response will return the customer's details in JSON format. The example below is shortened, as the response includes many more fields, including custom fields.
{
"company_name": "Acme Corporation",
"customer_id": 12345,
"address_1": "123 Main St",
"email": "info@acmecorp.com.au",
"phone": "0893150000"
}
3. Updating Customer Details
API Reference:
https://resources.commtrak.com.au/api/v1/#/Customer/put_customer_existing__customer_id_
Endpoint:
PUT https://yourorg.commtrak.com.au/api/v1/customer/existing/{customerId}
The company_name field is required on every update request.
Headers:
Authorization: Bearer {access_token}Content-Type: application/json
Example Request:
curl -X PUT "https://yourorg.commtrak.com.au/api/v1/customer/existing/12345" \
-H "Authorization: Bearer your-access-token" \
-H "Content-Type: application/json" \
-d '{
"company_name": "Updated Acme Corporation",
"state": "NSW"
}'
Response:
If the update is successful, you will receive a confirmation response in JSON format:
{
"customer_id": 12345,
"company_name": "Updated Acme Corporation"
}
Common Responses
In addition to a successful response, API requests can return the following responses. Please refer to the CommTrak API reference for details.
401Unauthorized409Unexpected Warning417Invalid API Version429Rate Limit500Error
An access token that has been replaced is rejected. Depending on how it was replaced, the old access token returns either 401 Unauthorized or 409 Unexpected Warning, so your integration should handle both responses. See Token Expiry and Renewal.
Token Expiry and Renewal
The access token will expire after 1 hour (3600 seconds). When the token expires, you can obtain a new one using either of the following options:
- Request a new token by following the steps under Authentication: Obtaining an Access Token.
- Use your refresh token to request a new token, by sending a request to the refresh endpoint:
curl -X POST https://yourorg.commtrak.com.au/api/oauth2/refresh \
-H "Content-Type: application/json" \
-d '{
"grant_type": "refresh_token",
"refresh_token": "your-refresh-token"
}'
The response contains the same fields as the access token request, including an expires_in value of 3600.
When you refresh a token:
- A successful refresh returns a new access token and a new refresh token. Store both.
- The previous access token is invalidated immediately.
- A refresh token can only be used once. Using it again returns a
409response:
{
"message": "Invalid refresh token",
"status": "Warning"
}
- Requesting a new access token through
https://yourorg.commtrak.com.au/api/oauth2/tokenalso invalidates the previous refresh token, and using it returns the same409response.
Requesting a new access token immediately invalidates the previous access token for that Client ID. If two integrations share a Client ID, each integration invalidates the other's token, and API requests return an error response (see Common Responses). Use a separate Client ID and Client Secret for each application or integration, and we recommend reusing an access token until it expires.