Search code examples
node.jsapiexpressmongooseweb-deployment

Getting {"error": "unathorized"} every time, when trying to access any route in API on back4app


I have managed to deploy the appication with back4app as well as got it web-hosted there. However, I can't access the routes of my API (BookReadingApp). Every time I try to access any route I get an error: {"error": "unathorized"} 403 error persists no matter what type of request I'm trying to send to the server (get, post, put, patch, delete). The same thing applies to every error I get when trying to send the wrong request to the routes that don't exist (for testing purposes only).

Console logs show that "Database was connected successfully" and the server was launched with no errors (as I pointed out in my app.js file to know that api works as expected). enter image description here enter image description here

Please, help me to resolve this issue - any help is highly appreciated.

Kind Regards Vladyslav

I tried testing API (with POSTMAN and in Chrome) intentionally sending the wrong requests - the error does not change: it's always 'unathorized' (403). The console of the application shows that the server started successfully and that DB was also connected.


Solution

  • unauthorized always said when something internally failed or when you use the cloud functions and didn't specify the keys in the header:

    curl -X POST \
     -H "X-Parse-Application-Id: key_here" \
     -H "X-Parse-REST-API-Key: key_here" \
     -H "Content-Type: application/json" \
     -d "{}" \
     https://parseapi.back4app.com/functions/hello