Authentication

Authentication

Arattai Business Platform REST APIs utilize OAuth 2.0 to authorize and authenticate calls, providing secure access and eliminating the hassle of manual logins. Follow the steps below to access Arattai Business Platform REST APIs using OAuth 2.0.

Advantages of OAuth 2.0

  • Clients are not required to support password authentication or store user credentials, as authentication and authorization are handled by exchanging OAuth tokens.
  • Clients gain delegated access, i.e., access only to resources authorized by the user.
  • Users can revoke a third-party application's delegated access at any time.
  • OAuth access tokens expire after a set time.

Available Scopes

When making an authorization request, specify the scopes your application requires. The following scopes are supported by the Arattai Business Platform:

Scope Purpose Used By
ArattaiBusiness.messages.CREATE Send business-initiated and conversational messages Promotional, Transactional, Authentication, Display & Input Messages APIs
ArattaiBusiness.customerdata.READ Read mini app user session data Mini Apps API
ArattaiBusiness.customerdata.DELETE Close mini app sessions Mini Apps API
ArattaiBusiness.companies.READ Read company accounts and verification details Companies API
ArattaiBusiness.companies.CREATE Upload company logos and verification documents, and submit a company for verification Companies API
ArattaiBusiness.companies.UPDATE Update company accounts and verification Companies API
ArattaiBusiness.companies.DELETE Delete company accounts Companies API
ArattaiBusiness.businesses.READ Read business accounts and verification details Businesses API, Business Numbers API (display name verification)
ArattaiBusiness.businesses.CREATE Create business accounts Businesses API
ArattaiBusiness.businesses.UPDATE Update business accounts and verification Businesses API, Business Numbers API (display name verification)
ArattaiBusiness.businesses.DELETE Delete business accounts Businesses API
ArattaiBusiness.phonenumbers.READ Read business numbers, logos, cover images, and mini apps Business Numbers API
ArattaiBusiness.phonenumbers.CREATE Create business numbers and mini apps Business Numbers API
ArattaiBusiness.phonenumbers.UPDATE Update business numbers, logos, and cover images Business Numbers API
ArattaiBusiness.phonenumbers.DELETE Delete business numbers and logos Business Numbers API
ArattaiBusiness.messagetemplates.READ Read message templates and translations Message Templates API
ArattaiBusiness.messagetemplates.CREATE Create message templates and translations Message Templates API
ArattaiBusiness.messagetemplates.UPDATE Update message templates and translations Message Templates API
ArattaiBusiness.messagetemplates.DELETE Delete message templates and translations Message Templates API
ArattaiBusiness.webhooks.READ Read webhooks and secret keys Webhook Management API
ArattaiBusiness.webhooks.CREATE Create webhooks Webhook Management API
ArattaiBusiness.webhooks.UPDATE Update webhooks and regenerate secret keys Webhook Management API
ArattaiBusiness.webhooks.DELETE Delete webhooks Webhook Management API

You can request multiple scopes by separating them with commas. Example: ArattaiBusiness.messages.CREATE,ArattaiBusiness.companies.READ

Step 1: Register a new client

To integrate your application with Arattai Business Platform, you must register it with Arattai Business Platform:

  1. Go to https://api-console.arattai.in/. If this is your first time registering a client application, click on GET STARTED.
  2. Choose the required Client Type.
  3. Enter the Client Name. This is the name of the application that you are registering with Arattai.
  4. Enter the Homepage URL.
  5. If you are registering a client-based, server-based, or mobile-based application, enter at least one Authorized Redirect URI. These are the URLs of your application to which Arattai Accounts will redirect you with the authorization code after successful authentication.
  6. The URIs must start with https:// or http://. The path after the domain is flexible - for example: https://www.your-domain.com/oauth/redirect. The path does not need to be /callback.
    • You can enter multiple URIs, separated by commas.
    • You may use dummy values if you do not have a valid URI.
  7. If you are registering a client-based application, you must enter at least one JavaScript Domain.
    • You can enter multiple domains, separated by commas.
    • Dummy values can be used if necessary.
  8. Click on CREATE.

The client credentials will be displayed.

Step 2: Generating grant tokens and obtaining authorization code

To generate an authorization code, redirect your application's browser to Arattai's OAuth endpoint. Arattai utilizes the authorization code grant type, which requires a client application to obtain an authorization code to receive an access token.

The process for generating the authorization code varies based on the client type. Still, it is usually a one-time process, if you generate the access and refresh tokens before the code expires.

Generating the Authorization Code for a Server-Based Client Application

A server-based client application serves multiple users and requires user intervention during authorization.

  1. To generate the authorization code for this type of client, use redirection-based code generation.
    The authorization flow is as follows:
    The client makes an authorization request to the resource owner by accessing the following URL:

Request URL:

Here's what each parameter means:

Parameter Description
scope This specifies the resource you want to access from the user's account for which the token is to be generated. The available scopes will be displayed to the user during the consent request.
You can mention multiple scopes by separating them with commas.
Example : ArattaiBusiness.messages.CREATE
client_id This is obtained during client registration. It is an opaque string that represents the client and will be passed back to the user.
response_type Set the response_type to code. The value code is mandatory to obtain the authorization code, which is valid for 60 seconds.
redirect_uri This is the URI where the authorization server will redirect the browser after providing the authorization code.
It must match the URI specified during app registration in the API console and should start with http:// or https://.
For example: https://www.your-app.com/oauthredirect.
access_type This determines whether your app can refresh the access token without user intervention after it expires.
If set to online, only the access token will be provided, which cannot be refreshed by the app.
If set to offline, a refresh token will also be provided on the first request for an access token, allowing the app to refresh it as needed.
The default value is online.
prompt If this parameter is included, the user will be prompted for consent every time your app requests access to the resource.
If not included, the user will only be prompted the first time. The value must be consent.
tenant Specifies the tenant to direct the user to the ArattaiBusiness sign-in page. Set this to ArattaiBusiness to ensure users are redirected to the ArattaiBusiness consent screen instead of the default Arattai sign-in.

2. After the user clicks Accept, the request will be approved, and they will be redirected back to the client application's URI (specified in the previous step) with keys in the query string.

For example:

Parameter Description
code This contains the short-lived grant token required to generate the access and refresh tokens.
location This indicates the domain location of the requesting user.

By following these steps, you will successfully generate the authorization code needed to obtain the necessary tokens for accessing the resources.

Error codes

Error Reasons
access_denied User rejected the request for access.
Invalid Client The parameter client_id is missing or its value is invalid.
Invalid response type The parameter response_type is missing or its value is incorrect. It must be code.
Invalid OAuth scope The parameter scope is either missing or the entered scope doesn't exist.
Invalid Redirect Uri The parameter redirect_uri is either missing or the entered URI doesn't match with the one configured in the API console.
⚠
Note The authorization code will be valid for one minute. If the user declines the authorization request, they will be redirected to the URI of the client application (as specified in the previous step) with error=access_denied included in the query string.

Error Reasons
An error occurred/500 server error The value of the parameter response_type is invalid. It must be "code".
405 Method Not Allowed The HTTP method used is incorrect. It must be GET.

Request URL

Click to copy
GET https://accounts.arattai.in/oauth/v2/auth?response_type=code&client_id=<client_id>&scope=<scope>&redirect_uri=<redirect_uri>&access_type=offline&tenant=ArattaiBusiness

Redirect Example

Click to copy
https://yourapp.com/callback?code=1000.xxxxxxxx.e1a88.xxxxxxx40a3&location=us&accounts-server=https://accounts.arattai.in

Step 3: Generating access and refresh tokens

To exchange the authorization code for an access token and a refresh token, make a POST request to Arattai's OAuth token endpoint.

Once your client application receives the authorization code, you can exchange it for an access token by making the following request:

Request URL:

Parameter Description
client_id The unique ID of your application. You can find this in the API console.
client_secret The unique secret for your app, which should only be known to your app and Arattai. You can find this in the API console.
grant_type Should be set to authorization_code.
code The authorization code you received after making the authorization code request.
redirect_uri This must match the URI provided when registering the app in the API console.
It should begin with http:// or https://.

Example redirect_uri:
https://www.your-app.com/oauthredirect

Response:

In the response, you will receive both access_token and refresh_token.

Token Details

  • access_token: This token is required to access resources corresponding to the scopes included in the authorization request. It will expire after a specific period, typically one hour
  • refresh_token: This token is permanent and will be used to refresh the access token once it has expired. The refresh token is included in the response only if you passed the parameter access_type with the value offline when making the authorization code request for the first time.

Additional Token Information

  • api_domain: The domain used by your app to make API requests to access protected resources.
  • token_type: Indicates the type of access token generated. Access tokens issued by Arattai are Bearer tokens. When your app makes API requests to access protected resources, the access token must be included in the "Authorization" header.
    Syntax: Authorization: Bearer {access_token}
  • expires_in: Indicates the duration (in seconds) until the access token expires. The lifespan of an access token is typically one hour (3600 seconds).
⚠
Note Each time a user accepts the re-consent page, a new refresh token is generated. There is a maximum limit of 20 refresh tokens per user. If this limit is exceeded, the oldest refresh token is automatically deleted to accommodate the latest one, regardless of whether it is currently in use.

Error codes

Error Reasons
invalid_client The parameter client_id is missing or its value is invalid.
The value of the parameter grant_type is invalid. It must be authorization_code.
invalid_client_secret The parameter client_secret is missing or its value is invalid.
invalid_redirect_uri The parameter redirect_uri is either missing or the entered URI doesn't match with the one configured in the API console.
invalid_code The parameter code is missing or its value is either invalid or already used.
The value of the parameter grant_type is incorrect. It must be authorization_code.
400 Bad Request The HTTP method used is incorrect. It must be POST.
The parameter grant_type is missing.
⚠
Note
  • An access token is valid for only one hour and can only be used to perform the operations defined by the scopes included in the authorization request.
  • A refresh token does not expire but can be revoked. Its purpose is to refresh the access token when it expires.
  • A maximum of five refresh tokens can be generated per minute.

Endpoint

Click to copy
POST https://accounts.arattai.in/oauth/v2/token?grant_type=authorization_code&code=<AUTHORIZATION_CODE>&client_id=<YOUR_CLIENT_ID>&client_secret=<YOUR_CLIENT_SECRET>&redirect_uri=<YOUR_REDIRECT_URI>

Response

{ "access_token": "1000.875cf8ea310ae70c6fb26e25a5a48df0.be3bc88ac53c61", "refresh_token": "1000.ce79a5110c4097744b17aecbb95dcfb.db312474fc80e", "api_domain": "<api_domain>", "token_type": "Bearer", "expires_in": 3600 }

Step 4: Get access token from refresh token

Access tokens expire in an hour. Client applications must make the following request and use their user's refresh token to generate a new access token. An access token typically expires after 3600 seconds (1 hour).

Before making API calls, or if you encounter an "expired token" error, you should obtain a new access token using the refresh token.

To Request a Refresh Token:

Make a POST request to the OAuth token endpoint with the following parameters:

Endpoint:

Parameter Description
client_id The unique ID of your application. You can find this in the API console.
client_secret The unique secret for your app, which should only be known to your app and Arattai. You can find this in the API console.
grant_type This should be sent with the value refresh_token.
refresh_token This is the refresh token that you received after making the initial access token request.

Response:

When you successfully request a new access token, you will receive the following response parameters:

  • access_token: This is the token your app needs to access the resources, as defined by the requested scopes. This token is valid for 1 hour.
  • api_domain: The domain to which your app needs to make API requests to access the protected resources.
  • token_type: Indicates the type of access token generated. The access tokens issued by Arattai are Bearer tokens. When making API requests, include the access token in the "Authorization" header following this syntax:
    Authorization: Bearer {access_token}
  • expires_in: Indicates the time (in seconds) until the access token expires, which is 3600 seconds (1 hour).

Endpoint

Click to copy
POST https://accounts.arattai.in/oauth/v2/token?grant_type=refresh_token&refresh_token=<YOUR_REFRESH_TOKEN>&client_id=<YOUR_CLIENT_ID>&client_secret=<YOUR_CLIENT_SECRET>

Step 5 : Revoking OAuth tokens

Why Revoke?

If a refresh token is no longer needed or seems to be compromised, it can be revoked and rendered invalid. This is done by making an API request. Once the revocation is successful, the refresh token can no longer be used to generate access tokens, and any existing access tokens that were created using this refresh token will also become invalid.

Programmatic Revocation

OAuth tokens can also be revoked by making a POST request to the endpoint /oauth/v2/token/revoke.

Both access tokens and refresh tokens can be revoked. If a refresh token is revoked, all access tokens generated using that refresh token will also be revoked.

Query Parameter:

token (required): The refresh token or access token that needs to be revoked.

Response:

  • {"status": "success"} The token has been successfully revoked.
  • 400 Bad Request: The token provided in the Request is invalid.

Endpoint

Click to copy
POST https://accounts.arattai.in/oauth/v2/token/revoke?token=<YOUR_TOKEN>

Response

{ "status": "success" }

General HTTP Status Codes

The following standard HTTP status codes may be returned by any Arattai Business Platform API endpoint.

200
Success
The request was completed successfully.
400
Bad Request
The request cannot be performed due to malformed or missing parameters.
401
Unauthorized
Request was rejected due to an invalid or missing OAuth token.
403
Forbidden
The user does not have sufficient permissions to access the resource.
429
Too Many Requests
Rate limit exceeded. Wait for the lock period to elapse before retrying.
500
Internal Server Error
The server encountered an unexpected condition preventing it from fulfilling the request.