Errors, pagination & filters
Understanding API returned status and errors
Every API request results in a response with either a 200 (OK) or 201 (Created) status code, indicating successful execution. If an error occurs during the request processing, the server responds with an appropriate error status code, accompanied by a message detailing the nature of the error.
{
"statusCode": 401,
"errorCode": "NOT_AUTHENTICATED",
"message": "Not authenticated",
"timestamp": "2023-10-14T00:12:22.470Z",
"path": "/v3/smart-contract-template",
"context": {},
}
Filtering your API calls
Paginating API calls
API calls can return a large number of items. To simplify the view, you can set the number of results per page and the number of pages returns.
This indicator 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:
/smart-contract-template?limit=5&page=2
In this example, the call will return results 6 to 10.
const axios = require("axios")
const axiosInstance = axios.create({
baseURL: "https://api.starton.com/v3",
headers: {
"x-api-key": "YOUR_API_KEY",
},
})
axiosInstance.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 network you can use:
/watcher?network=network_of_your_watcher
If the watchers you need are on "avalanche-fuji", you could make the following call:
const axios = require("axios")
const axiosInstance = axios.create({
baseURL: "https://api.starton.com/v3",
headers: {
"x-api-key": "YOUR_API_KEY",
},
})
axiosInstance.get("/watcher?network=polygon-amoy").then((response) => {
console.log(response.data)
})