Get More Out of Your LiveChat With API Calls and Postman

Krzysztof Kraus in Product, Tutorials, on April 11, 2018, Comments

LiveChat Academy

Making our customers happy is the number one rule at LiveChat. In this next part of our LiveChat Workshop series (stay tuned!), we want to show you how to get more out of your LiveChat license – all of that with the use of a simple yet powerful tool – Postman.

With today’s LiveChat Workshop, you will learn:

  1. What is Postman?

  2. Why do we use Postman at LiveChat?

  3. How to authorize and execute your API calls in Postman?

  4. What REST API calls are available at LiveChat and how to filter them?

Also, in the last section of this article, we’ve prepared a special treat for you – hope you’ll like it!

What is Postman?

Postman is a tool that allows you to quickly deploy API calls for both testing and development. With just a few clicks, you can check out if one or several of your API endpoints are functioning properly, debug them in case of any problems, or even use it to determine the uptime of your API services.

Those are just a few of the many useful features of Postman. To check out all of them, be sure to visit www.getpostman.com.

Why do we use Postman at LiveChat?

There are several reasons that made Postman our number one tool when it comes to both testing our API endpoints and gathering additional information from LiveChat licenses.

1. Easy navigation

Yup, you heard that right. Postman’s UI makes calling our API so easy that not only is it used by our Developers and Technical Department, but also by our Support Heroes (themselves!). With just a few easy steps, you can create an API call by:

  1. Choosing a method;

  2. Providing the request’s URL;

  3. Choosing the type of authorization;

  4. Adding some additional parameters to both Header and Body of your API call.

Create an API request with Postman

Regarding the simplicity, it beats a regular cURL, doesn’t it?

2. Speaking of cURLs

After preparing and deploying a call, we often hear that our customers would like to test the specific API endpoint on their own. And sometimes they may not want to use Postman, but rather some other method that will be compatible with their current workflow.

Since not everyone can write an example in cURL or Python, Postman is there to help. After preparing your call, simply click on Code, and choose which method you would like Postman to prepare.

Quickly generate a code for your API call

And, that’s it! You can now share your code with a customer, making both your and your customer’s life easier.

curl -X GET \
  https://api.livechatinc.com/agents \
  -H 'authorization: Basic ' \
  -H 'cache-control: no-cache' \
  -H 'postman-token: cc51f0ba-99ca-78d7-dfe3-3fba8a725f81' \
  -H 'x-api-version: 2'

3. Storing all those API calls in one place

You have probably found yourself in a situation where you have faced multiple customers, asking for the same API requests. Memorizing the entire API documentation may seem like a fun hobby, but we have a better and more convenient solution – Postman Collections.

Use Postman's Collections

With just a click of a button, you can save the API call and store it in your Postman Collections, calmly waiting for you to use it later. What’s more, you can save and share your brand new Postman Collection with your customers and coworkers alike!

Share your Collection with customers and coworkers alike!

OK, so now that you know why we use Postman at LiveChat, it is time to learn how you can use Postman to your advantage with your LiveChat license!

Learn how to run REST API calls with Postman

First of all, if you are not yet equipped with Postman, make sure to grab it from the official website. It will make the usage of all of those LiveChat REST API calls a blast.

Before making your first API call, you have to know how to authorize each and every API request. For that, you’ll need to add the following attributes to your Postman’s Headers section.

-H "Authorization: Bearer access_token" \
-H "X-API-Version: 2"

Add authorization headers to your Postman API call

X-API-Version is pretty self-explanatory, but how to get the Access token? To do that, follow the simple steps listed below.

1. Create new app in your Developer Console

First, log into your LiveChat’s Developer Console and go to Apps section.

Log into your Developer Console and go to Apps

To proceed with creating a new app, click on New app button.

Click on New App button to proceed

We will leave naming the app to you but remember to choose the Web app as the type of your application. After that, click on Continue to create your new app.

Click on Continue to create your app

Now proceed to the Authorization section of your new app. While there, copy the provided Client ID and Redirect URI – we will need them for later.

Copy your client ID and redirect URI available in the Authorization section

On the same Authorization section, the thing that you need to do next is to set up the right scopes for your application. What are the application scopes? Putting it simply, they allow you to decide which parts of LiveChat API can be accessed by your application.

Make sure to mark all the available scopes if you want to use the full potential of LiveChat’s REST API. After doing that, click on Save Changes to finalize the process.

Choose the scopes for your app and Save Changes

2. Generate your Access token

Now is the time to use the Client ID and Redirect URI that you have copied before. Take a look at the following URL:

https://accounts.livechatinc.com/?response_type=token&client;_id=496dfcbf0526410ce72fbeb6&redirect;_uri=https%3A%2F%2Fmy.livechatinc.com

This URL contains a sample Client ID and Redirect URI. Grab the link from above, making sure to replace those parameters with the values copied from the Authorization section of your app, and run it in your web browser of choice. As the result, you should be redirected to LiveChat Web Application but with one difference.

Take a look at the URL section of your web browser. You will see that the link to LiveChat’s Web Application now includes your access token:

https://my.livechatinc.com/#access_token=BPQgoLQEOW&expires;_in=57600&scope;=agents_read,agents_write,archives_read,archives_write,billing_manage&state;=123&token;_type=Bearer
Note that your access token **will be valid for 8 hours.** After that time, you will have to generate a new token by following the exact steps described above. **Don't worry though!** In the near future we will prepare a simple form that will take care of generating access token for you.

Copy it and paste as the header when running a Postman call, just like on the following example:

Paste access token to Postman's Authorization section

Now that you have your access token, you can use various endpoints available in our REST API to gather additional information from your LiveChat or perform additional actions on your license, like adding new agents or editing your current greetings. Now you no longer have to occupy your agents’ seats!

So, now that you know everything you need to authorize and run your requests, there is one question that still remains:

What are the available REST API endpoints and what parameters can you use to filter your requests?

REST API calls available at LiveChat

Setting up your Postman and acquiring your access token might have taken up some time, so we’ve got a special treat for you. We’ve prepared a dedicated Postman documentation that includes all of the available LiveChat’s REST API calls – just follow the link to check it out.

What’s more, the documentation includes the Run in Postman button. If you have installed Postman on your computer, this button will automatically import all of the available LiveChat’s REST API calls and save them as a collection.

Import and store all of LiveChat's REST API calls

Alternatively, simply click the Run in Postman button available below and we will do the rest.

And that’s it! All that is left for you to do is to:

  1. Check out the documentation;

  2. Choose which request you would like to run;

  3. What optional parameters you would like to apply to filter your request.

All of the available parameters are listed in the documentation, at the beginning of each REST API calls category, such as Archives.

Filter your calls with additional parameters

The thing to remember is that all of the optional parameters should be passed as the keys added to the endpoint’s URL that you’d like to call…

Filter your request and run it with Postman

and all additional attributes that you’d like to pass in your POST or PUT requests should be passed within the BODY section of your call.

Add additional attributes to BODY of your call

We’re hoping this article not only pointed out the benefits of using Postman, but also helped you find and run useful API calls with LiveChat.

If you have any additional questions about how we use Postman at LiveChat or wanted to know more about our REST API, just ask in the comments down below! We will be more than happy to help you.