Documentation

Public API > API External Download.

Documentation Menu

API External Download

The purpose of this document is to demonstrate, how requests can be retrieved and approve from an external system. The goal is to empty the request queue on an interval and approve or deny requests that are already stored in the external system. The scenario could be to make a recurring job in ServiceNow and then add buttons on tickets to approve or deny requests.
Documentation for the Public REST API can be found here.
The API exposes the same features as you can find in the portal and the mobile app. There are three areas: Auditlog, Requests, Inventory, Events, and PIN Code. The details and fields of each API can be found at the links below.

Set Up

The first step is to generate an API key. By default, your tenant data is not exposed to the public API. You have to generate a new key and use this to get the data. Note that the API has brute force protections in place, so it’s safe to open the API.
» admin by request » admin by request
Once we have this key, we can make a call to the API using the API key as the “apikey” header. We will be using the free Postman (https://www.postman.com/) to demonstrate the use. Here we have called the Auditlog API to get entries:
» admin by request » admin by request

Getting Requests

Requests will appear in the “Requests” top menu in the portal as shown here:
» admin by request » admin by request
To get a list of pending requests for approval, we need to call the Requests API indicating that we are only interested in “Pending” states. The URL is then (dc1api for Europe and dc2api for US tenants): https://dc1api.adminbyrequest.com/requests?status=pending
This will give us a list in json format with all the same information that is shown in the Admin Portal:
» admin by request » admin by request

Approving Requests

Notice that each request has an “id” field. This field is used to perform an approve or deny request as explained in the Requests API documentation.
The resources table in the requests api page » admin by request » admin by request
So all we have to do is to make a simple PUT request with the ID:
» admin by request » admin by request
And the request is now approved and the user is notified accordingly.
» admin by request » admin by request

Keeping State

So how do you only get new requests? The easiest way is to store the highest id you have received before and use this for the next calls. Here are the filters for the Requests API:
The filters table from the admin by request requests api doc page » admin by request » admin by request
Let’s say the last request we received was 65430930. Then we add one (since we already received 65430930) and use as startid, meaning that we only want to see any requests with an id higher than 65430930:
» admin by request » admin by request