3 How to call
This page describes how to call Mercury Cloud OpenAPI.
3.1 Base URL
The base service endpoint is at:
Mercury Cloud API is served only over HTTPS to ensure your data privacy.
The domain.com
might differ according to your service region. Please find this information in your service starting email.
3.2 Common parameters
Each API call requires a few common parameters, HTTP method, App ID, Access Key, and Secret Key.
GET
, POST
, and DELETE
are the HTTP method used in Mercury Cloud. Refer to the API References for details on the method of each API. This method will also be used in API authentication.
The App ID, the Access Key, and the Secret Key are included in your service starting email. Please keep them in a safe place and do not disclose them to others. They will be used in setting the API URL and calculating the API auth token.
3.3 API authentication
All Mercury APIs require auth tokens to verify valid clients. There are two types of additional headers (x-date and Authorization) needed in each API call. If they are not included, you will get a 401 HTTP error code.
The x-date header
The x-date header uses an RFC-7231 formatted UTC date-time string.
For example:
This stands for 2021-07-09T01:51:02Z. Please notice that the x-date is the time of the GMT, not your local time.
The Authorization header
The Authorization header is generated based on a given URL path, HTTP method, App ID, Access Key, and Secret Key. For some APIs related to Features DBs, the DB ID is also required. The Authorization follows the following format.
A common Authorization header example is as follows.
The hmac username
is your Access Key. Replace 005c5acf-5ea9-499c-8d3e-690413f9b5b9
with your own access key.
The signature
is a base64 encoded string encrypted by HMAC-SHA256.
Let us do it step by step. First, assemble the message
before encryption.
A common message
example before encryption is as follows.
x-date
is the same as the x-date header.
POST
is the HTTP method. Make it consistent with the API you are going to use.
/openapi/face/v1/abc1a8a7-038f-4f9a-b98a-5b602978b135/detect
is the URL path including the abc1a8a7-038f-4f9a-b98a-5b602978b135
part as the APP ID. Replace it with your own APP ID. Also, substitute this part with the URL path of your designated API. In some APIs, DB ID is also needed. For example,
Where the aed37153-16b6-4f19-a479-302049e44000
is the DB ID.
Use the Secret key blFWSvhp9pRz2JnRHnfvkFeAuApClhKg
to encrypt the first message we created.
Then we will get
Encode it with base64. The signature is finalized as follows.
Use this signature will complete the Authorization composition we saw above.
You can now use the x-date Header and the Authorization Header to make the API call of /openapi/face/v1/{app_id}/detect
.
3.4 Samples for making headers
3.5 "Try it out" in the SwaggerHub
SwaggerHub offers interactive ways to let you test API calls directly from the browser using the "Try it out" button. Mercury Cloud Interactive API Documentation requires a special Authentication before you can use this function. Here is the guide to using the "Try it out" function in the Mercury Cloud Interactive API Documentation.
3.5.1 Prepare headers
Prepare the x-date header and the Authorization header, respectively, using the code samples.
3.5.2 Select the server
Click the Servers dropdown list and choose the server according to your service area.
3.5.3 Authorize with the Authorization header
Click the "Authorize" button right to the Servers list.
The following window will pop up. Paste the Authorization header into the "Value" textbox and click the "Authorize" button.
The Authorization header has now been fixed. To re-authorize it, click the "Logout" button and re-do the steps above.
The Authorization header is time-sensitive, so you need to re-authorize it every time before you call the API.
3.5.4 Enter the Parameters and have a try
Now we can try the API call. Take the List Feature Database API for example.
Click the "Try it out" button, the "Execute" button will show up.
Fill up the x-date and the app_id parameter and click the "Execute" button.
The API response will be displayed with some other related information.
Last updated