Wix fetch with Bearer Authorization

Hi

I was using a code to fetch data from an endpoint that will always respond with ok 200 status, it works just fine until I use the Bearer authorization.

Backend data.jsw:

import {fetch} from 'wix-fetch';
import wixSecretsBackend from 'wix-secrets-backend';

let baseUrl = // My API URL;

export async function getTutorials() {
       let token = await wixSecretsBackend.getSecret('MyAPIKey');

       const headers = {
              "Authorization": `Bearer ${token}`,
              "Content-Type": "application/json"
        };
 
        let url = baseUrl + "tutorials"
        return fetch(url, { method: "get", headers: headers }).then( (httpResponse) => {        
               if (httpResponse.ok) {
                      return httpResponse.json();
               } else {        
                      return Promise.reject(httpResponse.body.error);
               }
        }).catch(err => {
               console.error(err);
               return Promise.reject("Fetch did not succeed");
        })
}

Any idea?

Help is appreciated.
Thanks.

Hey :raised_hand_with_fingers_splayed:

Have you checked if your API token has expired or got invalidated!?
Did you try to check online REST testers?

It should theoretically work.

Back again, nice to see you ^^

I’ve never left! Nice to see you too :raised_hand_with_fingers_splayed:

:grin: You were for some days very busy, but well i can assume why :laughing: good luck, i am watching it too :wink:

P.S. Take a look into the “Pro-Discussion” and SORRY 4 the OFF-TOPIC.

haha :joy:

Hi @ahmadnasriya , it seems to be working with external REST checkers, my API token key is working, perhaps there’s a bug or a syntax error in my code

Perhaps the current node.js on the backend doesn’t support the authorization through the Bearer, did you try fetch from the frontend ?