0

First time trying out Firebase Functions and I cannot get this to work. I've tested in Postman with no problems. Is it something obvious? I also tried with Axios as well and no luck.

The error in the logs: Request has invalid method. GET

The error at the endpoint:

{"error":{"message":"Bad Request","status":"INVALID_ARGUMENT"}}

This is my attempt in the functions index.js

const functions = require("firebase-functions");
const https = require('follow-redirects').https;
const fs = require('fs');

const options = {
    'method': 'GET',
    'hostname': 'industrial.api.ubidots.com',
    'path': '/api/v2.0/devices/',
    'headers': {
      'X-Auth-Token': '***********'
    },
    'maxRedirects': 20
  };
  
  exports.getDevices = functions.https.onCall((data, context) => {
    var req = https.request(options, function (res) {
        var chunks = [];
    
        res.on("data", function (chunk) {
        chunks.push(chunk);
        });
    
        res.on("end", function (chunk) {
        var body = Buffer.concat(chunks);
        console.log(body.toString());
        });
    
        res.on("error", function (error) {
        console.error(error);
        });
    });
    
    req.end();
})
RJC
  • 920
  • 11
jjhi11
  • 11
  • 2
  • Does this answer your question? [How to call Firebase Callable Functions with HTTP?](https://stackoverflow.com/questions/49476231/how-to-call-firebase-callable-functions-with-http) – RJC Apr 05 '22 at 07:01

0 Answers0