Skip to content
Nils Rauch edited this page Sep 11, 2020 · 9 revisions

It is now possible to connect with Cryptopus via an API User.

This API-User is personalized and able to query all accounts it is enabled in for either a name or a tag.

API Standard

The Cryptopus API follows the JSON API Standard

Creating an API-User

  1. Go to your Profile Page (click on your name to the top right).
  2. Switch to the tab 'API-Users'.
  3. Press the button 'New'.

This new API-User does not have any rights yet. You have to explicitly enable it for any team you want to access.

Give rights to the API-User

  1. Go to the page of the team for which you want to enable the API user.
  2. Switch to the tab 'API-Users'.
  3. Toggle 'Enabled'.

Authorization

You need to set the following headers in your request:

  • Authorization-User: YOUR_API_USERNAME
  • Authorization-Password: YOUR_TOKEN

Important: The token has to be base64 encoded.

API-User

Besides manually clicking in the profile page, it is possible to access your API-Users via your usual username and password. But keep in mind, these ones are user specific! This requires you to set the same headers as above and enables you to connect to

  • Retrieve all API users: GET /api/api_users
  • Get an API user by ID: GET /api/api_users/:id
  • Refresh the Token of an API user: GET /api/api_users/:id/token

Account

Read

The URL looks like this: GET /api/accounts/:id

  1. cURL for a GET request could look like this:
curl --request GET 'localhost:3000/api/accounts/1' \
--header 'Authorization-User: YOUR_AUTH_USER' \
--header 'Authorization-Password: YOUR_AUTH_PASSWORD_BASE64_ENCODED'

Update

Accounts can be updated through the API. Therefore you need to be in the team in which the account belongs to and you need to know the :id of the account.

Avoid giving the Query in the URL like this: PATCH /api/accounts/:id?QUERY

If you prefer sending the data in the JSON format, follow these steps:

  1. Add the required headers to the cURL as follows:
--header 'Accept: application/json' \
--header 'Content-Type: application/json'
  1. Change the format that it matches the JSON In addition to this, you are ready to send a Request in the JSON format. The cURL for a PATCH request could look like this:
curl --request PATCH 'localhost:3000/api/accounts/1' \
--header 'Authorization-User: YOUR_AUTH_USER' \
--header 'Authorization-Password: YOUR_AUTH_PASSWORD_BASE64_ENCODED' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data '{"data": {"attributes": {"accountname": "Bob Meyer"}}}'

Basic cURL request from Command line:

curl -X PATCH -d "data%5Battributes%5Btag%5D=taggy&account%5Baccountname%5D=Bob+Meyer" \
--header 'Authorization-Password: YOUR_AUTH_PASSWORD_BASE64_ENCODED' \
--header 'Authorization-User: YOUR_AUTH_USER' \
--url 'http://localhost:3000/API/accounts/1'

In the Background is equal to this:

{"data": {"attributes"=>{"accountname"=>"Bob Meyer", "tag"=>"taggy"}}}

Query Cryptopus with the API user

The API user can connect to the following endpoint: /api/accounts Options are:

  1. /api/accounts?q=QUERY
  2. /api/accounts?tag=TAG

We recommend to use Postman to test the requests.

Nevertheless, in case you want to work with curl, you can find examples here:

Requests using cURL

This in an example for an update call:

curl --request PATCH --url 'http://localhost:3000/api/accounts/1' \
--header 'Authorization-Password: YOUR_AUTH_PASSWORD_BASE64_ENCODED' \ 
--header 'Authorization-User: YOUR_AUTH_USER' \
--data 'data%5Battributes%5Btag%5D=taggy&account%5Baccountname%5D=Bob+Meyer'

Use this for a GET request:

curl --request GET --url 'http://localhost:3000/api/accounts/1' \
--header 'Authorization-Password: YOUR_AUTH_PASSWORD_BASE64_ENCODED' \ 
--header 'Authorization-User: YOUR_AUTH_USER'

Keep in mind that your you'll find the auth credentials on your name tab, in the application.

If you don't give any option, Cryptopus will return all accounts the API user has permission to.

API users token renewal

With /api/api_users/:id/token, you renew an API user.

A renewal will mean, that the API user will now again be valid for a certain time-span (see on your profile page) Additionally, if he was locked, the renewal will unlock him again. Finally, the response contains the new token of the API user, which you need to store.