Examples of Statistical API in javascript with axios

Hi all,

This is more a javascript question than a Sentinel Hub question but I hope that some people here know the answer.

I saw the announcement of the new statistical API and its documentation at:

However I could not wrap my head around that axios/oauth business. I am able to use axios to get an access token to use the Catalog API, but I do not know how to use this access token as the “oauth” object shown in the previous link to make POST requests against the new statistical API URL.

Has anyone managed to make work the whole pipeline?

PS: the axios documentation was of no help either.

Hi Guillaume,

If you managed to get an authorization token you can use it by passing it as an Authentication header like this:


axios.post("https://services.sentinel-hub.com/api/v1/statistics", data, { headers: { 'Authorization': `Bearer ${your_token_here}`}});

Where data is the JSON object that you are sending to the API (I suggest using Statistical mode on Requests Builder, under Request Preview to get that object in a more friendly way).

To make auth work, basically you need to attach the HTTP header Authorization: Bearer <token> to your request.

Let me know if I can assist you further.

Ignasi Espinosa

Edit: Note that you may also need to add ‘Content-type’: ‘application/json’ and ‘Accept’: ‘application/json’ headers in the headers object passed to axios.

2 Likes

Thanks Ignasi! I can now make requests to the statistical API. I hace more questions but I will open another thread for them.