Skip to main content

Using Starton API

Understanding REST APIs

An API is an application programming interface. It is a set of routines, functions, data structures and other tools that make possible for computers program to communicate with each other.

Starton API is a REST API. A REST API is an application program interface that uses HTTP requests to send information between client and server.

It's a protocol that works over the web and uses URLs (Uniform Resource Locators) to identify resources. Information or content can be accessed at a URLs location, such as JSON, HTML, audio files or images.

Often resources have one or more methods that can be performed on them over HTTP (Hypertext Transfer Protocol), such as GET, POST, PUT and DELETE. The action represented by the first and last of these is clear; but POST and PUT have specific meanings: use POST to create resources; use PUT to update them.

Authenticating on Starton API

To use Starton Connect from your code, you will need to authenticate yourself to the API through an API key.

What is an API Key ?

An API key (Application Programming Key) is used to authenticate yourself to an API. For example, Starton can generate API keys related to the use of Connect, so you can call our API from your code and authenticate yourself with it. The API keys generated by Starton are linked to a specific project, which means you could have multiple API keys. API keys are linked to your projects/account, so anyone gaining access to your API keys could use your credits by pretending to be you.

Generating an API Key

On the Developer section, you can generate new API keys or revoke the previous ones (for example, if they leaked).

Using an API Key

The API key will be needed in your code if you try to call Connect's API endpoints (as the x-api-key variable in the Headers of the requests).

const startonApi = axios.create({
baseURL: "https://api.starton.io",
headers: {
"x-api-key": "YOUR_API_KEY",
},
})

Filtering your API calls

Paginating API calls

API calls can return a large number of items. It can be very useful to set the number of results per page and the number of pages returns.

This information is set in the path of your request. You can use:

  • limit: the number of results returned by page. By default, this number is set to 100.
  • page: the page returned. By default, the page returned is the first.

For example if you want to get the list of templates Starton will return, you will use the path:

v3/smart-contract-template?limit=5&page=2

In this example, the call will return results 6 to 10.

const axios = require("axios")

const http = axios.create({
baseURL: "https://api.starton.io/v3",
headers: {
"x-api-key":YOUR_API_KEY,
},
})
http.get('/smart-contract-template?limit=5&page=2').then(response => {
console.log(response.data)
})

Filtering your API calls

You can filter your API calls using parameters. For example, if you created watchers and want to get the watchers you created on a specific networks you can use:

/v3/watcher?network=network_of_your_watcher

If the watchers you needs are on "avalanche-fuji", you could make the following call:

const axios = require("axios")

const http = axios.create({
baseURL: "https://api.starton.io/v3",
headers: {
"x-api-key":YOUR_API_KEY,
},
})
http.get('/watcher?network=polygon-mumbai').then(response => {
console.log(response.data)
})

Related topics