Connecting with Rest API
Overview
This documentation explains how to connect to Chochae Engine REST API using a POST request with a JSON payload. The example uses a specific endpoint and includes the necessary headers and body data.
API Endpoint
Webhook API
Method: POST
URL:
https://ccgpt-uat.iapp.co.th/common/webhook-api?id=YOUR_ID
Headers
Content-Type
String
Specifies the media type of the resource. Set to application/json
Request Body
The request body is in JSON format. In this example, it contains a message in Thai.
Example Code Using Axios
Import Axios
First, import the Axios library to make HTTP requests:
Create Data Payload
Define the data to be sent in the POST request as a JSON string. In this example, the payload contains a message in Thai:
Configure the Request
Set up the Axios request configuration, including the HTTP method, URL, headers, and data payload:
method: HTTP method for the request (POST in this case).
maxBodyLength: Configures Axios to handle large payloads.
url: Endpoint to which the request is sent.
headers: HTTP headers for the request, specifying the content type as
application/json
.data: JSON payload to be sent.
Send the Request
Use axios.request
to send the configured request. Handle the response and potential errors with then
and catch
blocks:
.then((response) => { ... }): Executes if the request is successful, logging the response data.
.catch((error) => { ... }): Executes if there is an error during the request, logging the error.
Full Code Example
Example Response
200: OK Sample Response
If the request is successful, you might receive a response similar to the following:
for the video tutorial please click : https://ccgpt-uat.iapp.co.th/public/video/api.mp4
Last updated