Short URL API Integration Guide

This article introduces a Short URL API integration guide, which can convert long URLs into short URLs.

Application Process

To use the Short URL API, first go to the Ace Data Cloud Console to obtain your API Token for later use.

If you have not yet logged in or registered, you will be automatically redirected to the login page to register and log in. Once completed, you will be automatically returned to the current page.

A general application's API Key can be used for services enabled for the account; a dedicated application's Key can be used within that application's service scope. Please check the Key's permissions, validity period, and limits, and confirm that the application balance is sufficient to pay for this request. Available trial credits are subject to what is displayed in the account. If the balance is insufficient, click the "Recharge" button.

📘 Full documentation: Short URL API →

Basic Usage

First, let's look at the basic usage: enter the long URL to be converted to obtain the processed result. You simply need to pass a content field. We can then fill in the corresponding content in the interface, as shown below:

You can see that we have set the Request Headers here, including:

  • accept: The format in which you want to receive the response. Here it is set to application/json, meaning JSON format.
  • authorization: The key used to call the API. After obtaining it, you can select it directly from the dropdown.

We have also set the Request Body, including:

  • content: The content of the URL to be shortened.

After making the selections, you can see that the corresponding code has also been generated on the right, as shown below:

Click the "Try" button to test it. As shown above, we obtain the following result:

{
  "success": true,
  "data": {
    "url": "https://surl.id/1uHCs01xa5"
  }
}

The response contains several fields, described below:

  • success: The status indicating whether the task was successful.
  • data: Contains the converted URL.

As you can see, the original long URL https://platform.acedata.cloud/documents/shorturl has been successfully converted into the short URL https://surl.id/1uHCs01xa5.

Additionally, if you want to generate the corresponding integration code, you can copy the generated code directly. For example, the CURL code is as follows:

curl -X POST 'https://api.acedata.cloud/shorturl' \
-H 'accept: application/json' \
-H 'authorization: Bearer {token}' \
-H 'content-type: application/json' \
-d '{
  "content": "https://platform.acedata.cloud/documents/shorturl"
}'

The Python integration code is as follows:

import requests

url = "https://api.acedata.cloud/shorturl"

headers = {
    "accept": "application/json",
    "authorization": "Bearer {token}",
    "content-type": "application/json"
}

payload = {
    "content": "https://platform.acedata.cloud/documents/shorturl"
}

response = requests.post(url, json=payload, headers=headers)
print(response.text)

Error Handling

If an error occurs when calling the API, the API will return the corresponding error code and message. For example:

  • 400 token_mismatched: Bad request, possibly due to missing or invalid parameters.
  • 400 api_not_implemented: Bad request, possibly due to missing or invalid parameters.
  • 401 invalid_token: Unauthorized, invalid or missing authorization token.
  • 429 too_many_requests: Too many requests, you have exceeded the rate limit.
  • 500 api_error: Internal server error, something went wrong on the server.

Example Error Response

{
  "success": false,
  "error": {
    "code": "api_error",
    "message": "fetch failed"
  },
  "trace_id": "2cf86e86-22a4-46e1-ac2f-032c0f2a4e89"
}

Conclusion

Through this document, you have learned how to use the Short URL API to convert long URLs into short URLs. We hope this document helps you better integrate and use the API. If you have any questions, please feel free to contact our technical support team.