1

I'm trying the javascript framework react and I need to fetch a token from an api off this service: https://api.monetizze.com.br/2.1/apidoc/#api-Security-Token. For that, I need to send along with the request my X_CONSUMER_KEY. That's the way I'm trying to do with the axios library:

axios.request('https://api.monetizze.com.br/2.1/token', {           
    headers: {              
        'X-Requested-With' : 'XMLHttpRequest',              
        'X_CONSUMER_KEY': 'here is my key'
    }
});

The response I'm getting on the browser console is as follows:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://api.monetizze.com.br/2.1/token. (Reason: CORS preflight channel did not succeed).

Have you experienced that issue and have solved it? Sorry about my very poor English and thank you very much.

Wolgan Ens
  • 385
  • 1
  • 11
  • 1
    Are you sure this API supports client-side requests for that specific endpoint? The code examples they show, cURL and PHP, are both server-side; and considering this needs a "consumer key" it might also be the case that this key should not be exposed in any client-side code to begin with. – CBroe Apr 07 '18 at 23:07
  • I'll try to request a node (express) that will do the request, then put here the results – Wolgan Ens Apr 07 '18 at 23:13
  • Looks like this API was not meant to be used directly from the browser. You'd have to expose the API key to your users, and you really don't want to do that. – Joni Apr 07 '18 at 23:15
  • Yes I know, but it is a simple software for one person to run on his house or his smart-phone, thats the only reason I considered try it on client side – Wolgan Ens Apr 07 '18 at 23:18

1 Answers1

0
http.get({
    host: 'api.monetizze.com.br',
    path: '/2.1/token',
    headers: {
        X_CONSUMER_KEY: 'your_consumer_key',
    }
}, (result) => {
    console.log(req.headers);
    res.send(result.statusCode)
});  

That piece of code above in a server side application did the job, thank you very much.

Wolgan Ens
  • 385
  • 1
  • 11
  • I was passing by to check for a similar error I had, I would recommend editing your answer to put a consumer key with a dummy name like "your_consumer_key", because it seems you put a real one here. Hope this would help – Pierre Chevallier Aug 03 '18 at 12:43
  • @Wolgan Ens. Where did you place the server side app? Was it on the same project as React? – alextc May 11 '21 at 23:57