Export a table to CSV or XLSX using the API with a token
In this guide I will show you how to pull a CSV file based on a specific table from vScope – only using the API in vScope. ”Why would you do that?” you might wonder. The answer is easy: using data from vScope can actually be the first step towards automating manual operations in other systems. This by making vScope responsible for the gathering and structuring of data.
I will also cover how you can do the export using an API token. This means that you can have the option ”Guest access” (that is, accessing vScope without having to login) turned off and still be able to securely access the API.
We have a quite comprehensive API documentation. You can find it here:
To read more on how the API documentation works, checkout my earlier blogpost:
How to make use of vScope’s API.
In order to create an API token you will need to be logged in to vScope. You can do this either directly in vScope and then return to the documentation; Or you can authenticate yourself via the endpoint
/rest/usermanager/authenticate. Also, make sure that you are a vScope administrator.
First, let’s create an API token!
Every token is created for a specific user in vScope. So for instance, you can create an user that is dedicated for API tokens. Users are created under the settings page under Users & Groups.
Create a dedicated user for API tokens
This step is actually not required. You can create an API tokens for anyone of your current users. If you don’t want a dedicated user for your tokens, skip to the next step (Create the token)
Name the user something like apiuser and set the email to someone that should be responsible for the user. Make sure to set the user as Admin, if you want the user to have admin privileges (which is recommended for this example).
Follow the link provided in the email and set a password for the user.
Create the token
Now let’s actually create the token! Go to the settings page and expand the section called API Tokens.
Here you can see all the API Tokens that can be used. To revoke a token , press the
X next to it.
To create a token , simply click the button. A float should appear.
Select the user that you want to base the API Token on. This should be the the user that we recently created. You can also set how many days the token should be valid. This field is optional and leaving it empty will make the token valid for ten years. Click create and the new token should appear in the list.
Using the token
To do a request with a token simply pass it along as a header, using the header key
token. In CURL it looks like this:
curl -X GET --header 'token: [token]' [your vScope]/[endpoint]
For example; this will return the information about the user who owns the provided token, and save it to a file called me.txt:
curl -X GET --header 'token: 6483b55a3083b516' https://vscope/rest/usermanager/me > me.txt