Table of Contents

Get and use API key

There is no limit to the number of API keys you can create in the EasyAR developer center. It is recommended to assign independent API keys to different applications for more granular permission control.

Create API key

Log in to the EasyAR Developer Center. If you are using an API key for the first time, please create one first by following these steps:

  • Under "Authorization," click "Cloud Service API KEY"
  • On the "API KEY" page, click the "Create API KEY" button

APIKey

  • Fill in the "Application Name"
  • Check the required cloud services according to your application needs. It is not recommended to authorize all services.
  • Click "Confirm"
Tip

To use SpatialMap, check SpatialMap.

To use Cloud Recognition, check Cloud Recognition.

To use Mega Landmark, check Mega Landmark. You need to apply for this feature through business channels before use.

To use AR Operations Center, check AR Operations Center. You need to apply for this feature through business channels before use.

To use Mega Block Cloud Localization, check Mega Block.

APIKey

  • The API Key and API Secret will then be generated on the page, as shown below. Be careful not to leak them.

APIKey

Warning

Do not use the API Key and API Secret directly on client-side applications (e.g., web, WeChat Mini Programs, etc.).

Get token

There are two ways to obtain a token: 1. Get it directly from the development center; 2. Write code to obtain it. If you need to control access to resources, it is recommended to use the second method. Below are the two acquisition methods, you can choose according to your needs.

Get token from the development center

  • Select an API Key you want to use, and click "Manage" on the right

APIKeyToken

  • Select a validity period for the token
  • Click "Generate Token"
  • Click "Copy" to complete

APIKeyToken

Note

Security is the primary reason for setting the token validity period. If the token validity period is too long, once leaked or stolen, attackers can use it for a long time, leading to data leakage or unauthorized operations. The validity period limits the effective window of the token, so even if it is leaked, the harm is limited to a short time.

Generate token using API key and API secret

The token generation process requires signing core parameters to ensure transmission security. These signed parameters are then sent to the STS (Security Token Service) for authentication. Once verified by the STS service, a temporary access token is issued, which is only valid within a specified time window. After expiration, the authentication process must be reinitiated.

Warning

Do not generate the token in client-side code. Instead, generate the token on the server side and pass it to the client for use.

Request parameters

Field name Type Required Description
apiKey string Yes API Key
expires int Yes Generated token validity period, in seconds
acl string Yes Access Control List, controls token's accessible resource permissions
timestamp long Yes Timestamp, in milliseconds
signature string Yes Signature

acl: Consists of one or more ACs (Access Control). Each AC contains four parts: service, effect, resource, permission.

  1. service: Service type. Currently supports ecs:crs (cloud recognition), ecs:spatialmap (sparse spatial map), ecs:cls (Mega Block cloud-based localization), ecs:vps1 (landmark)
  2. resource: Specific service's app id, e.g., CRS AppId for cloud recognition library
  3. effect: Specifies whether access matching this resource configuration item can be executed. Values: Allow, Deny
  4. permission: Permission values: READ, WRITE

Structure example:

[
  {
    "service": "ecs:crs",
    "resource": ["f7ff497727ab2d55ea01d9984ef8068c"],
    "effect": "Allow",
    "permission": ["READ"]
  }
]

Signature method

  1. Sort all request parameters by key.
  2. For each parameter, concatenate its key and value into a string.
  3. Concatenate all the strings obtained in this way, and append the API Secret at the end.
  4. Calculate the sha256 hash of the string in hexadecimal as the signature.
Signature example
<?php
// Your API Key and API Secret
$apiKey = '6a47f7f8ff6......68744b4bcf';
$apiSecret = '87745d866345256b......fbae27c502a';
// Your service App ID
$appId = 'f7ff497727ab2d55ea01d9984ef8068c';
// Validity period, in seconds
$expires = 3600;

// Build parameters to be signed
$data = [
    'apiKey' => $apiKey,
    'expires' => $expires,
    'acl' => '[{"service":"ecs:crs","resource":["'. $appId .'"],"effect":"Allow","permission":["READ"]}]',
    'timestamp' => time() * 1000,
];

// Sort
ksort($data);

// Concatenate strings
$builder = [];
foreach ($data as $key => $value) {
    array_push($builder, $key . $value);
}

// Concatenate API Secret
array_push($builder, $apiSecret);

// Generate signature
$signature = hash('sha256', implode('', $builder));
echo $signature;
Tip

When adding a signature, the ACL needs to be converted to a JSON string.

Get the token

Add the generated signature to the parameter list and send a request to the /token/v2 interface to obtain the token.

  • Request address: https://uac.easyar.com/token/v2 or https://uac-na1.easyar.com/token/v2 (North America Zone 1)
  • Request method: POST
  • Request header: Content-Type: application/json
  • Request parameters: {"apiKey":"6a47f7f8ff6......68744b4bcf","expires":3600,"acl":"[{\"service\":\"ecs:crs\",\"resource\":[\"f7ff497727ab2d55ea01d9984ef8068c\"],\"effect\":\"Allow\",\"permission\":[\"READ\"]}]","timestamp":1765954279002,"signature":"32f18a37fc3c18......55c4943af9"}

Example:

curl -X POST https://uac.easyar.com/token/v2 \
-H 'Content-Type: application/json' \
-d '{"apiKey":"6a47f7f8ff6......68744b4bcf","expires":3600,"acl":"[{\"service\":\"ecs:crs\",\"resource\":[\"f7ff497727ab2d55ea01d9984ef8068c\"],\"effect\":\"Allow\",\"permission\":[\"READ\"]}]","timestamp":1765954279002,"signature":"32f18a37fc3c18......55c4943af9"}'

If the statusCode in the response is 0, it indicates success.

Normal response format:

{
  "statusCode": 0,
  "timestamp": 1765954874399,
  "msg": "Success",
  "result": {
    "apiKey": "6a47f7f8ff6......68744b4bcf",
    "expires": 3600,
    "token": "nuPDCj......xstQX",
    "expiration": "2025-12-17T08:01:14.399+0000"
  }
}
  • token: The token for business request authentication.
  • expiration: The expiration time of the token. A new token must be requested after expiration.

Error response format:

{
  "statusCode": 4001017,
  "timestamp": 1765954666624,
  "msg": "AppId is not authorized by this API Key",
  "result": null
}

Using token

In business HTTPS requests, add the token to the request header in the format: {"Authorization": "nuPDCj......xstQX"}.

When sending business API requests, the parameter appId must be included (refer to the development center for the source of obtaining it).

Error code description

During the process of token generation and token usage, various errors or exceptions may occur.
To help developers quickly locate issues and take effective solutions, the following details common error codes and their meanings:

Error Code Error Message Error Description Solution
4001011 API Key invalid API Key is invalid Check if this API Key exists under "Cloud Service API KEY"
4001012 Timestamp invalid Timestamp is invalid The timestamp unit is milliseconds, and the deviation from standard time should not exceed 5 minutes
4001015 Signature invalid Signature is invalid Verify the signature algorithm is correct and check if the API Secret matches the API KEY
4001017 AppId is not authorized by this API Key API Key is not authorized for this AppId Check if the service where the AppId is located is associated with this API Key
4001018 Base64 decode error The Authorization set in the request header is not in a valid base64 format Do not process the obtained token in any way; use it directly
4001019 Decryption error The Authorization set in the request header is not generated by EasyAR Do not process the obtained token in any way; use it directly
4001022 API Key's resource is empty API Key has no associated cloud service Check if the API Key is associated with a cloud service and if the associated cloud service has expired
4001024 Token is expired Token has expired Regenerate the token
4001025 Token generate fail Token generation failed Contact technical support: support@easyar.com