How do I use Rest APIs?
- 1 What is REST API?
- 2 How does REST API work?
- 2.1 Get Authorization Keys
- 2.2 GET
- 2.2.1 Get the list of all intents
- 2.2.2 Get specific intents
- 2.3 POST
- 2.4 PUT
- 2.5 DELETE
- 3 Using Postman to access the REST APIs
- 3.1 Adding Collections to Postman
- 3.1.1 Setting up an Environment in Postman
- 3.1.1.1 How to get Token
- 3.1.2 Import using URL
- 3.1.3 Import Raw Text
- 3.1.1 Setting up an Environment in Postman
- 3.1 Adding Collections to Postman
What is REST API?
REST API ā REpresentational State Transfer Application Program Interface.
Representational State Transfer is an architectural style for exposing your program using existing protocols, typically HTTP, to GET, POST, PUT, and DELETE Data.
How does REST API work?
A REST API breaks down a transaction to create a series of small modules. Each module addresses an underlying part of the transaction.
A REST API uses:
GET to retrieve a resource.
POST to create a resource.
PUT to change the state of, or update a resource, which can be an object, file or block.
DELETE to remove a resource.
The following sections show how to use the APIs, using āIntent Managerā APIs as examples.
Get Authorization Keys
A developer should have an Orbita userās login credentials to access APIs and call the following API to get the bearerās token.
/api/login
If the credentials are correct, the response from the API will be a JW token, which is the bearerās token for the request.
The bearerās token is passed through the Authorization property in the Request Header of subsequent API requests.
The minimum validity for the JW token is 4 hours.
If JW token is expired, the application must call for JW token again.
The Content-Type property in the Request Header will be application/json.
GET
Sends a simple request to read a response from the remote server.
Get the list of all intents
To get a list of all the available intents in the current server, use the following API call:
/api/voice/intent
Example usage
curl. Clientās URL.
curl -X PATCH https://[YOUR_ENDPOINT]/api/voice/intent
PATCH Example
Success Response
Get specific intents
To get a list of specific intents in the current server, use the following API call:
Example usage
GET Example
Success Response
POST
Creates a resource for the remote server.
To create an intent in the intent library, use the following API call:
Example usage
POST Example
Success Example
PUT
Updates a resource in the remote server.
To edit an intent that is already created, use the following API call:
Example usage
PUT Example
Success Example
DELETE
Deletes a resource in the remote server.
To delete an intent from the intent library, use the following API call:
Example usage
DELETE Example
Success Example
Using Postman to access the REST APIs
The Postman is a great tool when trying to dissect RESTful APIs made by others or test the ones that you have made.
See https://www.youtube.com/watch?v=K3s0iT6rWe0 for a video that shows how to get started with Postman.
See also https://<sandbox-domain>:<portno>/apidoc, which shows the complete REST API documentation on the sandbox.
Adding Collections to Postman
It can be tiresome to test all the Orbita APIs by copying each API to Postman. To minimize the effort and the time consumed, we have provided a JSON to add a collection of all the APIs to Postman so that the admins can navigate to the required API and test it quickly. The two ways of importing JSON to Postman are described below.
Setting up an Environment in Postman
Copy the JSON code from the link http://<sandboxdomain>:<portno>/apidoc/postman/Environment.json and paste it in a separate file.
Select the cogwheel button on the top right corner of the application to manage environment settings.
Click āImportā from the dialog box.
Select the file. The environment file is loaded to the postman.
Click the file name to edit the environment settings and update your domain and token and click on āUpdateā.
How to get Token
Login to postman
Set the method to āPOSTā and use the URL https://<domain-name>:<portno>/api/login.
Use the below code in the body of the request and click āSendā. Please change the login credentials as per the instance/domain.
You will receive a token in the response.
Select the Environment that you created from the Environment dropdown on the top right corner of the page.
Import using URL
Open Postman and Select the Import option.
Copy the link http://<sandbox-domain>:<portno>/apidoc/postman/ItemCollection.json and paste it in the āImport From Linkā tab in the import dialog box and click āImportā.
Import Raw Text
Open Postman and Select the Import option.
Copy the JSON content in the link https://<sandbox-domain>:<portno>/apidoc/postman/ItemCollection.json and paste it into the āPaste Raw Textā tab in the import dialog box and click āImportā.