How to Authenticate with the TeamTrace API

Created by TeamTrace Support, Modified on Tue, 17 Nov at 3:59 AM by TeamTrace Support

Overview

Before your application can call the TeamTrace API, it has to prove who it is. You do this by sending your Client ID and Client Secret to the authorization endpoint. The API responds with an authorization token, and you send that token in the authorization header of every other API request. This article explains how to get a token, how to use it, and what to do when authentication fails.


Before You Begin

  • You need a Client ID and a Client Secret for your application. The Client ID is a unique identifier for your application, and the Client Secret is a private key that verifies it.
  • Make sure you can send HTTPS requests, for example with cURL, Postman or code in your own application.
  • Store the Client Secret securely. Anyone who has it can request tokens as your application.


[Note: Contact customer support for Client id. and Client Secret at support@teamtrace.app.]


How Authentication Works

  1. Your application sends a POST request to the authorization endpoint with the x-client-id and x-client-secret headers.
  2. If the credentials are valid, the API returns a successful response with an authorization token.
  3. Your application sends that token in the authorization header on every request to the protected endpoints.


How to Get an Authorization Token

Endpoint

POST https://api-info.teamtrace.app/api/authorization


Steps

  1. Prepare your credentials. Have your Client ID and Client Secret ready.
  2. Set the request headers. Add the two headers in the table below.
  3. Send the request. Make a POST request to the endpoint with those headers.
  4. Check the response. A successful response means your credentials are valid. Copy the token from the response and use it in your next requests.


Request headers

HeaderTypeRequiredDescription
x-client-idstringYesYour application's unique client ID.
x-client-secretstringYesYour application's secret key.

Example request (cURL)

curl -X POST "https://api-info.teamtrace.app/api/authorization" \
 -H "x-client-id: YOUR_CLIENT_ID" \
 -H "x-client-secret: YOUR_CLIENT_SECRET"


How to Use the Token in Your Requests

All other API endpoints need a valid token. Add it to the authorization header of each request.

HeaderTypeRequiredDescription
authorizationstringYesThe API authorization token you received.

Requests that send a JSON body also need the Content-Type: application/json header.

Example: fetch the customer list

curl --request GET "https://api-info.teamtrace.app/api/v1/fetch-customer-list?customer_status=ACTIVE&page=1&limit=10" \
 --header "authorization: YOUR_TOKEN"


Endpoints That Need a Token

APIMethodEndpoint
Customer ListGET/api/v1/fetch-customer-list
Customer Task ListPOST/api/v1/fetch-customer-task-list
User ListGET/api/v1/user/list
Leave ListPOST/api/v1/company-leave/list
Employee Screenshot FetchPOST/api/v1/screenshot-fetch
Detailed TimesheetPOST/api/v1/worklog-summary/detailed-timesheet-report
Field People TimesheetPOST/api/v1/worklog-summary/field-people-timesheet

All of these endpoints are on https://api-info.teamtrace.app.


When Authentication Fails

If the credentials or the token are wrong or missing, the API returns an error instead of data. A missing or invalid token on a protected endpoint returns a response like this:

{
  "status": "error",
  "message": "Unauthorized",
  "code": 401
}

When you get a 401 response, check that the token is present and correct, and request a new token if it has expired.


Example: handle a 401 in code (Node.js)

if (response.status === 401) {
  throw new Error("Auth failed. Check or refresh token.");
}

Tips

  • Keep the Client Secret private. Never put it in front-end code, public repositories or shared documents. Store it in an environment variable or a secrets manager.
  • Send credentials in headers only. The Client ID and Client Secret go in the x-client-id and x-client-secret headers, not in the URL.
  • Reuse the token. Request a token once and use it for your requests until it expires, rather than requesting a new one for every call.
  • Add a retry for failures. If a request fails because of a network or server problem, retry it a few times before giving up.
  • Test with one endpoint first. After you get a token, try a simple request such as the User List before building your full integration.


Notes

  • The authorization endpoint uses POST, and it has no request body. Only the two headers are needed.
  • Both x-client-id and x-client-secret are required. The request fails if either one is missing.
  • Every protected endpoint needs the authorization header. A request without it fails.


Troubleshooting



ProblemWhat to check
The authorization request failsCheck that you send both x-client-id and x-client-secret, that the names are spelled exactly, and that the values are correct.
I get an error on the authorization endpointCheck that you use POST and not GET, and that the URL is https://api-info.teamtrace.app/api/authorization.
I get 401 Unauthorized on another endpointCheck that the authorization header is present and holds a valid token. Request a new token if the old one has expired.
The token works for one request and fails laterThe token may have expired. Request a new one. [Add: the token lifetime.]
I sent the credentials in the request body or URLMove them to the x-client-id and x-client-secret headers.
My request times out or fails on the networkCheck your internet connection and try again. Retry a few times before reporting a problem.
I get a 500 server errorWait a moment and retry. If it keeps happening, contact TeamTrace support.
I lost my Client Secret, or it was shared by mistake[Add: how to regenerate or revoke the credentials.]


Related Articles

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article