Experimenting with Postman and REST APIs
Postman is a fantastic tool that lets you interact with REST APIs.
A few examples.
JIRA REST API
List of projects in JIRA
Lets say you want to get a list of all the projects in a JIRA instance.
- Where it says “Enter request URL” type in the url for the request, for example something like this:
https://jira.starfleet.com/rest/api/2/project
- Set the request type to GET as we’re just retrieving information with this request.
- If Basic Auth is available in your JIRA instance select the “Auth” tab, change the “Type” dropdown to “Basic Auth”, and enter your username and password. Postman will automatically encode your username and password using base64, and add the result as a header to the request. You can see this as a hidden auto-generated header under the Headers tab.
- Click the big blue “Send” button and all being well you should see the response to your request in the bottom pane, in this case listing all the projects.
Changing the Component Lead in JIRA
- Where it says “Enter request URL” type in the url for the request, for example something like this:
https://jira.starfleet.com/rest/api/2/component/16309
- Set the request type to PUT as we’re updating existing information with this request.
- If Basic Auth is available in your JIRA instance select the “Auth” tab, change the “Type” dropdown to “Basic Auth”, and enter your username and password. Postman will automatically encode your username and password using base64, and add the result as a header to the request. You can see this as a hidden auto-generated header under the Headers tab.
- Under the “Body” tab change the type to “raw” and the format to “JSON” and enter the following with your username of choice:
- Click the big blue “Send” button and all being well you should see the response to your request in the bottom pane, in this case acknowledging the change.
BusinessObjects REST API
BusinessObjects uses a different method for authenticating requests. Each request needs a logon token. Before you make a request to for example create a user or modify a universe, you need to make an initial request to get a logon token.
Requesting a logon token
- Where it says “Enter request URL” type in the url for the request, which should look something like this:
https://businessobjects.starfleet.com/biprws/logon/long
- Set the request type to POST as we’re submitting information with this request.
- Under the “Headers” tab add two key/value pairs for “Accept”: “application/json” and “Content-Type”: “application/json”. This tell BusinessObjects that we are sending the body of the request formatted as JSON and we also want the response to be formatted as JSON. BusinessObjects will also accept and respond with XML, but I prefer JSON.
- Under the “Body” tab change the type to “raw” and the format to “JSON” and enter the following with your username, password and the authentication type:
- Click the big blue “Send” button and all being well you should see the response to your request in the bottom pane, in this case providing you with your logonToken.
Getting a list of users
- Where it says “Enter request URL” type in the url for the request, which should look something like this:
https://businessobjects.starfleet.com/biprws/v1/users
- Set the request type to GET as we’re just retrieving information with this request.
- Under the “Headers” tab add a key/value pair for “Accept”: “application/json” to tell BusinessObjects we want the response in JSON format.
- Also under the “Headers” tab add a key called “X-SAP-LogonToken” with the value set to the logonToken from your token request.
- Click the big blue “Send” button and all being well you should see the response to your request in the bottom pane. By default the system will only give you 50 users at a time. To get users beyond the first 50 you need to include a “page” paramater on your request, for example
https://businessobjects.starfleet.com/biprws/v1/users?page=2
to get the second 50 users. You can also change the default page size by including a pagesize parameter, for examplehttps://businessobjects.starfleet.com/biprws/v1/users?pagesize=100
to get 100 users at a time.
Creating a new user
- Where it says “Enter request URL” type in the url for the request, which should look something like this:
https://businessobjects.starfleet.com/biprws/v1/users/user
- Set the request type to POST as we’re submitting information with this request.
- Under the “Headers” tab add two key/value pairs for “Accept”: “application/json” and “Content-Type”: “application/json”. This tell BusinessObjects that we want the response to be formatted as JSON and also that we are sending the body of the request as JSON.
- Also under the “Headers” tab add a key called “X-SAP-LogonToken” with a value set to the logonToken from your token request.
- Under the “Body” tab change the type to “raw” and the format to “JSON” and enter the following with your the parameters for the new account you want to create:
- Click the big blue “Send” button and all being well you should see the response to your request in the bottom pane acknowledging that your new account has been created.