Call to external API from backendless with custom header and POST Method

Hi,

I need to call external API from backendless with custom header and POST Method, I found code to call external URL with GET method. But I need to call Post method. Is there any way to call Post Method with a custom Header?

Could you show the code you use now? We don’t need full code listing, just the code that makes the http request.

Hi,
Please see

  const message = {
        registration_ids: [deviceToken],
        "notification":{"body":"Active","title":"Active"}
      }
  
      let headers = {
      "Content-Type": "application/json",
      Authorization: "key=" + FIREBASE_API_KEY,
      }
      
      let URL = "https://fcm.googleapis.com/fcm/send";
      let response = await Backendless.Request.post( URL, headers, JSON.stringify(message))
      return response;

That code uses the post method. What seems to be the issue?

when I call this API from my reactNative App , It works and when I call same API with same headers from Backendless I got this response.

        {
"headers": {
    "date": "Sat, 04 Dec 2021 19:16:16 GMT",
    "server": "GSE",
    "expires": "Sat, 04 Dec 2021 19:16:16 GMT",
    "transfer-encoding": "chunked",
    "vary": "Accept-Encoding",
    "x-frame-options": "SAMEORIGIN",
    "content-security-policy": "frame-ancestors 'self'",
    "x-content-type-options": "nosniff",
    "x-xss-protection": "1; mode=block",
    "content-type": "text/html; charset=UTF-8",
    "connection": "close",
    "cache-control": "private, max-age=0",
    "alt-svc": "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000,h3-Q050=\":443\"; ma=2592000,h3-Q046=\":443\"; ma=2592000,h3-Q043=\":443\"; ma=2592000,quic=\":443\"; ma=2592000; v=\"46,43\"",
    "accept-ranges": "none"
},
"message": "<HTML>\n<HEAD>\n<TITLE>The request was missing an Authentication Key. Please, refer to section &quot;Authentication&quot; of the FCM documentation, at https://firebase.google.com/docs/cloud-messaging/server.</TITLE>\n</HEAD>\n<BODY BGCOLOR=\"#FFFFFF\" TEXT=\"#000000\">\n<H1>The request was missing an Authentication Key. Please, refer to section &quot;Authentication&quot; of the FCM documentation, at https://firebase.google.com/docs/cloud-messaging/server.</H1>\n<H2>Error 401</H2>\n</BODY>\n</HTML>\n",
"body": "<HTML>\n<HEAD>\n<TITLE>The request was missing an Authentication Key. Please, refer to section &quot;Authentication&quot; of the FCM documentation, at https://firebase.google.com/docs/cloud-messaging/server.</TITLE>\n</HEAD>\n<BODY BGCOLOR=\"#FFFFFF\" TEXT=\"#000000\">\n<H1>The request was missing an Authentication Key. Please, refer to section &quot;Authentication&quot; of the FCM documentation, at https://firebase.google.com/docs/cloud-messaging/server.</H1>\n<H2>Error 401</H2>\n</BODY>\n</HTML>\n",
"status": 401
   }

How is this a backendless problem then? I think you need to resolve it with the people from the resource you are making the call to.

I think when I call API from backendless, The headers are not SET.
Is there any way that I can check what HTTPS Request I am calling with its Params?
This means I want to see HTTPS request body and header content.

What does the firebase error tell you?

I already Paste here Please check
The request was missing an Authentication Key
And Auth key is set in headers

  {
 "headers": {
 "date": "Sat, 04 Dec 2021 19:16:16 GMT",
 "server": "GSE",
 "expires": "Sat, 04 Dec 2021 19:16:16 GMT",
 "transfer-encoding": "chunked",
 "vary": "Accept-Encoding",
 "x-frame-options": "SAMEORIGIN",
 "content-security-policy": "frame-ancestors 'self'",
 "x-content-type-options": "nosniff",
 "x-xss-protection": "1; mode=block",
 "content-type": "text/html; charset=UTF-8",
 "connection": "close",
 "cache-control": "private, max-age=0",
 "alt-svc": "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000,h3-Q050=\":443\"; ma=2592000,h3-Q046=\":443\"; ma=2592000,h3-Q043=\":443\"; ma=2592000,quic=\":443\"; ma=2592000; v=\"46,43\"",
 "accept-ranges": "none"
   },
 "message": "<HTML>\n<HEAD>\n<TITLE>The request was missing an Authentication Key. Please, refer to section &quot;Authentication&quot; of the FCM documentation, at https://firebase.google.com/docs/cloud-messaging/server.</TITLE>\n</HEAD>\n<BODY BGCOLOR=\"#FFFFFF\" TEXT=\"#000000\">\n<H1>The request was missing an Authentication Key. Please, refer to section &quot;Authentication&quot; of the FCM documentation, at https://firebase.google.com/docs/cloud-messaging/server.</H1>\n<H2>Error 401</H2>\n</BODY>\n</HTML>\n",
 "body": "<HTML>\n<HEAD>\n<TITLE>The request was missing an Authentication Key. Please, refer to section &quot;Authentication&quot; of the FCM documentation, at https://firebase.google.com/docs/cloud-messaging/server.</TITLE>\n</HEAD>\n<BODY BGCOLOR=\"#FFFFFF\" TEXT=\"#000000\">\n<H1>The request was missing an Authentication Key. Please, refer to section &quot;Authentication&quot; of the FCM documentation, at https://firebase.google.com/docs/cloud-messaging/server.</H1>\n<H2>Error 401</H2>\n</BODY>\n</HTML>\n",
 "status": 401
 }

I know you did. I mean read the error and then take a look at the headers you are passing. Hope you will see the issue.

Hi,
I found a solution for how to set header for third party APIs calling from backendless

        const message = actual_message;
        let URL = "https://fcm.googleapis.com/fcm/send";
        let response = Backendless.Request.post( URL , 
                    {
                        "registration_ids": deviceTokenArr,
                         "notification":{"body":message,"title":"Auction Update","sound": "default"}
                     }
                  )
                 .set('Content-Type', 'application/json')
                 .set({ 'Authorization': 'key='+FIREBASE_API_KEY })
         return response;