API Calls Using Third Party Applications: Personal Access Tokens
- Our Products & Services
- Getting Started
- Accounts
- Communication
- Billing
- Companies
- Financial
- Integrations
- Inventory
- Jobs
- Mapping
- Misc.
- Monitoring
- Purchase Orders
- Release Notes
- Sonar Billing
- Voice
- Reporting
- Security
- sonarPay
- Ticketing
- Working With the Sonar Team & Additional Resources
- System
- Networking
Table of Contents
When creating an integration that will access Sonar through the API, the first step is to create a personal access token in your Sonar instance for that integration to use. The following article details the steps in creating a personal access token.
- Create an appropriate role and a user that you will use to perform the queries or mutations.
- Log in as that user.
- Click the Avatar on the top-right (first letter of your username by default).
- Select the Personal Access Tokens tab to navigate to the management page, then click on Create Personal Access Token.
- Name your access token. It is best practice to name this as a device, vendor, or server that will be integrating with Sonar.
Once you have copied the token, you will then need to click "Confirm" - after these steps have been completed, the token will appear in the Personal Access Tokens section as shown below.
GraphQL from CLI
Below is an example of running GraphQL query from the command line via curl. It is the most basic possible example of querying GraphQL outside of using https://instance.sonar.software/graphiql.
It should be run from bash or *nix because of the singe quotes. If you’re a Windows user, be sure to set up WSL for running Ubuntu in a container.
<token>
with an actual token that you got from following the instructions abovecurl -X POST \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <token>' \
--data-raw '{"query": "{ me { name username } }"}' \
https://instance.sonar.software/api/graphql
Using Postman
You can also connect to your Sonar instance using the Personal Access Token by using an application such as Postman. In this case, you would provide the Personal Access Token as Authorization Type / Bearer Token