I am setting up Firebase cloud functions to make API calls to a non-google service. For testing I am using jsonplaceholder as the API. the response I am receiving is a 403 error.
I have looked at other problems similar to this but the answer stated upgrading to a paid firebase account would fix the problem. Upon upgrading to the blaze plan I fixed the Firebase blocking outgoing http calls but I now am stuck at the 403 error being returned by any API I have tried making requests from.
import * as functions from 'firebase-functions';
const cors = require('cors')({origin: true});
export const getJson = functions.https.onRequest(async (req, res) => {
cors( req, res, async ()=> {
try {
let info = await req.get('https://jsonplaceholder.typicode.com/todos/1');
res.send(info);
} catch (error) {
res.status(500).send(`catch block hit: ${error}`);
}
})
})
I expected the API call to return a json object:
{
"userId": 1,
"id": 1,
"title": "delectus aut autem",
"completed": false
}
what I am receiving back is:
"Failed to load resource: the server responded with a status of 403 ()"
NOTE: I can receive the expected result if I make the get request from postman
Your help is appreciated, thanks.