How do I use Rest APIs?

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.

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

  1. Copy the JSON code from the link http://<sandboxdomain>:<portno>/apidoc/postman/Environment.json and paste it in a separate file.

  2. Select the cogwheel button on the top right corner of the application to manage environment settings.

  3. Click “Import” from the dialog box.

  4. Select the file. The environment file is loaded to the postman.

  5. Click the file name to edit the environment settings and update your domain and token and click on “Update”.

How to get Token

  1. Login to postman

  2. Set the method to “POST” and use the URL https://<domain-name>:<portno>/api/login.

  3. Use the below code in the body of the request and click “Send”. Please change the login credentials as per the instance/domain.

  4. You will receive a token in the response.

  5. Select the Environment that you created from the Environment dropdown on the top right corner of the page.

Import using URL

  1. Open Postman and Select the Import option.

  2. 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

  1. Open Postman and Select the Import option.

  2. 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”.

Related Articles