How to get authentication using Javascript fetch?

Hi all,

I am trying to get all subscriptions using fetch. Here is my code:

const url = 'https://[mywebsite]';

const username = [mysecrectkey];



       headers: {'Authorization': 'Basic '+btoa(username)}



        return res.json();


      .then(function(data) {



But I get the error message like this:

Failed to load resource: the server responded with a status of 405 (Method Not Allowed)

Failed to load https://*** Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin '' is therefore not allowed access. The response had HTTP status code 405. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

Uncaught (in promise) TypeError: Failed to fetch

anyone knows how to code it the right way? Thanks...

1 person likes this idea

Hi Rico

Currently, we don’t support client-side authentication(CORS). So you need to proxy your request via a server(ex: node etc) for the code to function.

Let us know if you need further details.

hi, can you allow CORS for your api?

I want to be be able to list plans and addons on my website when using my "publishable key"


Login or Signup to post a comment