Authentication

The Text Insights API uses JWT bearer authentication, which requires a valid token to be included in the Authorization header of the HTTP requests.

Getting the Token

To obtain a valid token, you will need to make a POST request to the /auth endpoint.

fetch('https://server-text.x2d.com.br/api/v1/auth', {
method: 'POST',
headers: {
    'accept': 'application/json',
    'Content-Type': 'application/json'
},
body: JSON.stringify({
    clientId: 'CLIENT_ID',
    apiKey: 'API_KEY'
})
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error(error));
curl -X 'POST' \
'https://server-text.x2d.com.br/api/v1/auth' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"clientId": "CLIENT_ID",
"apiKey": "API_KEY"
}'

Replace "CLIENT_ID" and "API_KEY" with your actual clientId and apiKey.

In response, you'll receive a JSON object with the token:

{
  "token": "your_token"
}

Using the Token

Once you have obtained the token, it can be included in the Authorization header of the HTTP requests to the Text Insights API, as demonstrated below:

fetch('https://server-text.x2d.com.br/api/v1/{endpoint}', {
  method: 'GET',
  headers: {
    'accept': 'application/json',
    'Authorization': 'Bearer your_token'
  }
})
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error(error));
curl -X 'GET' \
  'https://server-text.x2d.com.br/api/v1/{endpoint}' \
  -H 'accept: application/json' \
  -H 'Authorization: Bearer your_token'

Replace your_token with the token you obtained from the /auth endpoint. This authenticates your request and gives you access to the Text Insights API.

Please note that tokens are typically valid for a certain period of time, after which they expire and a new token must be obtained. Check the API documentation for specifics on token expiry.