Skip to content

Publish API Project

If you are an API provider and provide high-quality API resources, you only need the following steps to easily publish your API.

Preparation

In order to better unified management and maintenance of APIs, we have the following requirements for accessed APIs:

  1. Need to return JSON format
  2. The top-level fields of response need to meet the following requirements
NameDescription
code(Required) Return code. The return result is determined based on this field. See the table below for detailed meaning.
forceDeduct(Optional) If forceDeduct = true, the credits/fees will be forced to be deducted. If forceDeduct = false or not passed, use code field to determine whether to deduct the credits/fees
result(Optional) The complete original return result, field structure and explanation should be provided by the supplier
msg(Optional) Reason for request failure
creditsDeduct(Optional) When using a dynamic pricing plan, use this field to return the credits deducted. This value cannot exceed 0.2 by default.

Deduction Rule

Sometimes the code field is not suitable for determining whether credits/fees should be deducted. For this situation, we have added the forceDeduct field.

When forceDeduct = true or code = 0, the credits/fees will be deducted

Considering the actual situation, we will count the number of successful requests based on forceDeduct = true or code = 0

We will construct the response returned to the user based on the above fields, for example:

json
{
  "code": 0,
  "result": {
    "data": "sample"
  },
  "otherField1": "value1",  // This field will be ignored
  "otherField2": "value2"  // This field will be ignored
}
json
{
  "code": 0,
  "credits": 0.001,  // assume unit price = 0.001USD
  "result": {
    "data": "sample"
  }
}

The response sample for a failed request is as follows:

json
{
  "code": 1000,
  "msg": "Reason for request failure",
  "otherField1": "value1",  // This field will be ignored
  "otherField2": "value2"  // This field will be ignored
}
json
{
  "code": 1000,
  "msg": "Reason for request failure",
}

TIP

It should be noted that response status will not be checked.

  1. code字段的含义与解释
codedescription
0Request successful, will consume credits according to the pricing plan.
1000Internal error
1001Parameter error
1002The requested resource does not exist and may be deleted.
1003Internal processing is busy, please retry later
1004Insufficient permissions (Usually returned by platform)
1005Insufficient balance (Usually returned by platform)

Steps

1. Create Project

Enter the console Merchant, click Create Project, and select API as product type.

Create API Project

After creation, click the project to enter the management page

Merchant Projects

2. Fill in basic project info

Enter the project to complete the relevant configurations. You can upload your own project cover image, and click Save to take effect.

Project Base Info

3. Create API Endpoint

Create Endpoint

TIP

For better user experience, it is strongly recommended to fill in the Response Docs Link to describe the field structure and explanation in result.

The Slug field is the API sub-path of the Endpoint and cannot be duplicated. It is recommended to fill in a path with business meaning.

The Backend URL is the API URL provided by merchant, this field is not public.

Params Schema & Json Schema

Params Schema and Json Schema have the same structure and are used to describe parameter information and automatically generate documents. Json Schema should not be configured for GET requests.

We will check whether the required parameters are missing. This is only the most basic parameter check. There is no guarantee that the user has passed the correct parameters. Therefore, you should also verify the parameters.

FieldRequiredDescription
nametruefield name
requiredtruedetermine whether the parameter must be passed, bool value
typefalsefield type, has the following values: ["number", "string", "file", "array", "object", "int", "long", "date", "boolean"]
defaultValuefalsefield default value, it is recommended to fill in when the parameter are not required
descfalsefield description
examplefalsefield example
json
[
  {
    "name": "bindId",
    "desc": "bind user ID",
    "required": true,
    "defaultValue": "",
    "type": "string",
    "example": "123"
  },
  {
    "name": "productId",
    "desc": "product ID",
    "required": true,
    "defaultValue": "",
    "type": "string",
    "example": "123456"
  }
]

4. Configure Pricing Plan

Create Pricing Plan

TIP

When setting the last stage price to 0 for stage pricing, it can be equivalent to the daily price.

Dynamic Pricing requires the creditsDeduct field in the API return fields to specify the cost of this call.

Dynamic pricing limits

Due to the uncertainty and risks brought by the dynamic pricing plan, we stipulate that the maximum dynamic price for a single request cannot exceed 0.2 USD. If it exceeds, it will still be billed at 0.2 USD

If you select a dynamic pricing plan but do not pass the creditsDeduct field, no deduction will be made.

5. Publish

Go to the project page and set the Status = Online to complete the online process. The platform will also automatically generate API documents based on the project configuration information.

API Document Page

Finally

The API configuration will take effect immediately after modification, so please operate with caution, especially do not easily modify configurations such as Slug, Status, etc. that will affect current users.

Make things simple and timeproof.