API and Endpoints
Swagger UI
You can see the full Sanr API reference here.
Authentication and Authorization
Some methods require authorized access. To obtain an access token, you must provide cryptographic evidence of wallet ownership, via a message signature from the backend as follows:
import fetch from "node-fetch";
import {ether} from "ethers";
async function getSanrAPIResponse(path, method = "get", body, accessToken) {
// 'https://sanrnew-api.production.internal.santiment.net/api/v1/'
const url = "https://sanr-api.stage.internal.santiment.net/api/v1/";
const options = {
method,
headers: {"Content-Type": "application/json"},
};
if (body) options.body = JSON.stringify(body);
if (accessToken) options.headers.Authorization = `Bearer ${accessToken}`;
const response = await fetch(url + path, options);
return await response.json();
}
async function authoriseOnSanR() {
const {code} = await getSanrAPIResponse("auth");
const signedMessage = await wallet.signMessage(code);
const profile = await getSanrAPIResponse("auth", "post", {
signedMessage,
originalMessage: code,
isMobileUser: true,
});
return profile.accessToken;
}
const accessToken = await authoriseOnSanR(); //ofc u can't await here
Use cases
Most likely the main routes that you will want to use are getting a list of current smart contract addresses, getting the ABI contract, getting a list of supported price pairs, as well as changing the description of the prediction and saving information about the prediction.
Most common request parameters are intended for pagination, sorting and filtering data in response. Pagination parameters should be set like this skip=0&take=100, sort parameter should be set like this sort=date:asc and filter parameter should be set like this filter="direction":"up","$or":[{"title":null},{"status":"open"}]. You can use this operators aliases for filtering: $ne, $gte, $gt, $lte, $lt, $notIn, $iLike, $ilike, $between, $notBetween, $and, $or.
Error Handling and Status Codes
When working with API, you may encounter errors of the following type:
{
"message": "WRONG_SORT_OR_FILTER_FIELD",
"timestamp": "2024-10-25T06:52:30.543Z",
"i": 4,
"error": {"message": "FIELD_HIDDEN", "details": {"field": "performance"}}
}
If the error status is 400, it means that you are trying to perform an invalid operation or you made a mistake when writing the parameters. If the error status is 500 and the error looks like this:
{
"message": "SERVER_ERROR",
"timestamp": "2024-10-25T07:13:30.765Z",
"i": 4
}
Please post the timestamp and i value in Discord, this will help us fix the issue.
If the error format is different and the error status is 502 or 503 - the server is undergoing maintenance, please repeat your request later.
Rate Limits and Quotas
At the moment, rate limits 30 request per sec. The maximum value of the take parameter (required for pagination) is 1000.