API reference
Callbacks and Webhooks
Description
This section documents the integrations in which the CWS platform starts the communication and sends data to your store's system. Unlike the other sections of this documentation, here we describe the endpoints that you will need to build to receive our calls.
There are two types of communication started by CWS:
-
Synchronous (Callbacks): CWS makes a call and waits for an immediate response to continue a process. E.g.: Tax Calculation.
-
Asynchronous (Webhooks): CWS sends a notification about an event that has occurred and does not wait for a response to continue its processes. E.g.: Notification of new orders and customers.
Tax Calculation (Synchronous)
Authentication (What your store needs to provide)
Authentication Overview
Authentication is the same for tax calculation and for the order and customer webhooks.
Before calling your endpoint, CWS authenticates with your system and obtains an access token (access_token). This token goes in the Authorization header of each call.
To set up the integration, give the CWS team your system's authentication details: the token endpoint URL and the credentials.
Token Endpoint Structure (Your Responsibility)
Your token endpoint receives the credentials and returns the access token. The response must follow the OAuth2 standard:
{
"access_token": "YOUR_GENERATED_TOKEN",
"expires_in": 3600
}
Below are four real examples of how your token endpoint can be configured.
Example 1: client_credentials flow with Basic Auth
How it works: Your credentials (clientId and clientSecret) are combined, Base64-encoded and sent in the Authorization header.
Request that CWS will make to your token endpoint:
curl --location 'https://api.exemplo-cliente.com.br/oauth/access-token' \
--header 'Authorization: Basic [YOUR_BASE64_CREDENTIALS]' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'grant_type=client_credentials'
Example 2: Flow with clientId and clientSecret in the Body
How it works: Your credentials are sent directly in the request body, in JSON format.
Request that CWS will make to your token endpoint:
curl --location 'https://api.exemplo-cliente.com.br/v1/token' \
--header 'User-Agent: CWS Digital' \
--header 'Content-Type: application/json' \
--data '{
"clientId": "YOUR_CLIENT_ID",
"clientSecret": "YOUR_CLIENT_SECRET"
}'
Example 3: Flow with Credentials in Custom Headers
How it works: A non-standard model, in which the username and password are sent in specific headers, instead of using Authorization or the request body.
Request that CWS will make to your token endpoint:
curl --location --request POST 'https://api.exemplo-cliente.com.br/rest/api/oauth2/v1/token?grant_type=password' \
--header 'username: YOUR_USERNAME' \
--header 'password: YOUR_PASSWORD'
Example 4: Authentication with a Static Token in the Body
How it works: This simpler method does not use a token endpoint. A fixed token (API Key), agreed in advance, is sent directly in the body of each tax calculation request.
Request that CWS will make to your Tax Calculation endpoint:
curl --location 'https://api.exemplo-cliente.com.br/wscwstax/calcular' \
--header 'Content-Type: application/json' \
--data '{
"cliente": "57.578.030/0001-05",
"itens": [...],
"token": "YOUR_PRE_AGREED_STATIC_TOKEN",
...
}'
Webhooks (Asynchronous)
This subgroup contains practical examples of requests that CWS sends to your store's system. They serve as a model for building your Webhooks endpoints.
- POSTOrders Webhook Payload (Simplified)Webhook
- POSTOrders Webhook Payload (Complete)Webhook
- POSTCustomers Webhook PayloadWebhook
Authentication
Webhooks use the same authentication as tax calculation, described in the Tax Calculation (Synchronous) section.