Firebase Cloud Functions - Error when sending email [duplicate] - firebase

Trying to make a request to Paypal's API using PayPal-node-SDK
exports.requestPayment = functions.https.onRequest((req, res) => {
return new Promise(function (fullfilled, rejected) {
paypal.payment.create(create_payment_json, {}, function (error, payment) {
if (error) {
rejected(error);
} else {
console.log("Create Payment Response");
console.log(payment);
res.status(200).send(JSON.stringify({
paymentID: payment.id
})).end();
fullfilled(payment);
}
});
});
});
but I'm constantly getting an error:
Error: getaddrinfo ENOTFOUND api.sandbox.paypal.com api.sandbox.paypal.com:443
at errnoException (dns.js:28:10)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:76:26)
Things I've tried:
Making a request to a totally different host, still ENOTFOUND
Wrapping the request with cors(req,res, ()=>{...})
Prepending https:// to the host
What is the problem?

You'll need to be on a paid plan to make external API requests.
Firebase's Blaze plan (pay as you go) has a free allotment for Cloud Functions. https://firebase.google.com/pricing/

in my situation I had to wait and let what ever lag was happening pass. Now it's fine again.

I was having this issue because of weak internet, change the internet connection.

You need to include service account to the admin initialization. this fixed the same issue for me

Switch to the Firebase "Blaze" plan, which includes the free usage tier of the Spark plan before incurring any costs. Use the Blaze pricing calculator to see what you'd be charged for a given usage.
The first 5GB of outbound (egress) networking is free, which is the same as what "native" Google Cloud Functions would give you.

Related

Firebase emulator: see outgoing HTTP traffic

I have a Cloud Function that calls to Chargebee. In index.ts:
const chargeBee = new ChargeBee();
...
chargeBee.configure({
site,
api_key: apiKey
});
...
export const finalizeSignup = https.onCall(
async (info: SignupInfo, ctx: CallableContext) => {
const cbCmd = chargeBee.hosted_page.retrieve(info.cbHostedPage);
const callbackResolver = new Promise<any>((resolve, reject) => {
// cbCmd.request returns a Promise that seems to do nothing.
// The callback works, however.
// Resolve/reject the Promise with the callback.
void cbCmd.request((err: any, res: any) => {
if (err) {
reject(err);
}
resolve(res);
});
});
// Calling Promise.resolve subscribes to the Promise.
return Promise.resolve(callbackResolver);
}
);
I am testing this function using the Firebase emulators, started via firebase emulators:start --only functions. Chargebee is responding strangely. They require the domain of their incoming requests to be whitelisted: my first guess is that the domain being used by my locally emulated Cloud Function is not whitelisted on the Chargebee side.
How do I see outgoing HTTP information sent by my locally emulated Cloud Function?
The connection is actually HTTPS, not HTTP.
The emulators provide no functionality to intercept network traffic of any form.
For HTTP: you have to apply your own tooling to monitor the HTTP traffic (ie Wireshark).
For HTTPS: possible to monitor using Wireshark, but impossible to analyze without knowing the SSL key. And in the setup above, where a third-party library is handling the request, there is currently no way to obtain the SSL key. I entered a feature request with Firebase to gauge the interest of developing a way to define an SSL key log when starting the Functions emulator, similar to Chrome. A user only identifying themselves as 'Oscar' told me in a private email that "I've already filed a feature regarding this topic to our engineering team regarding this matter, which will be discussed internally." So that tells us that (1) Firebase is aware that the feature is currently lacking, and (2) there is no progress to report on the feature.

Firebase Cloud Functions post to Telegram API [duplicate]

Trying to make a request to Paypal's API using PayPal-node-SDK
exports.requestPayment = functions.https.onRequest((req, res) => {
return new Promise(function (fullfilled, rejected) {
paypal.payment.create(create_payment_json, {}, function (error, payment) {
if (error) {
rejected(error);
} else {
console.log("Create Payment Response");
console.log(payment);
res.status(200).send(JSON.stringify({
paymentID: payment.id
})).end();
fullfilled(payment);
}
});
});
});
but I'm constantly getting an error:
Error: getaddrinfo ENOTFOUND api.sandbox.paypal.com api.sandbox.paypal.com:443
at errnoException (dns.js:28:10)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:76:26)
Things I've tried:
Making a request to a totally different host, still ENOTFOUND
Wrapping the request with cors(req,res, ()=>{...})
Prepending https:// to the host
What is the problem?
You'll need to be on a paid plan to make external API requests.
Firebase's Blaze plan (pay as you go) has a free allotment for Cloud Functions. https://firebase.google.com/pricing/
in my situation I had to wait and let what ever lag was happening pass. Now it's fine again.
I was having this issue because of weak internet, change the internet connection.
You need to include service account to the admin initialization. this fixed the same issue for me
Switch to the Firebase "Blaze" plan, which includes the free usage tier of the Spark plan before incurring any costs. Use the Blaze pricing calculator to see what you'd be charged for a given usage.
The first 5GB of outbound (egress) networking is free, which is the same as what "native" Google Cloud Functions would give you.

Making an API request on Firebase Cloud Functions

I'm trying to use OpenWeatherAPI for my Actions on Google project. I'm using Firebase Cloud Functions through Dialogflow. How can I make an API request to get data from OpenWeatherAPI?
request.get('http://api.openweathermap.org/data/2.5/uvi?appid=XXX&lat=37.75&lon=-122.37', function (error, response, body) {
console.log('error:', error);
console.log('statusCode:', response && response.statusCode);
console.log('body:', body);
});
Here are Firebase logs:
statusCode: undefined
body: undefined
error: { Error: getaddrinfo ENOTFOUND api.openweathermap.org api.openweathermap.org:80
at errnoException (dns.js:28:10)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:76:26)
code: 'ENOTFOUND',
errno: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: 'api.openweathermap.org',
host: 'api.openweathermap.org',
port: 80 }
By default, Firebase Cloud Functions and the Dialogflow editor use a project that is on Firebase's Spark plan. This is completely free, but does have some restrictions, including no network access outside of Google's services.
In order to access openweathermap.org, you will likely need to upgrade to a paid plan. I suggest the Blaze plan, which is pay as you go over a certain level of usage each month. You will need to register with a credit card, but the usage level for development (and even for a modest level of production usage) should be enough to keep you in the free tier.

Fetching google sheets data from firebase "Billing account not configured" even if it's google api

I'm trying to fetch some data from a google spreadsheet. According to the firebase pricing it says that cloud functions are limited to Google services which means that this should work. However when I try to fetch the data I get the the error:
Error: getaddrinfo ENOTFOUND spreadsheets.google.com spreadsheets.google.com:443
at errnoException (dns.js:28:10)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:76:26)
I am trying with the following code:
export const fetchExcel = functions.https.onRequest((req, res) => {
const query = "https://spreadsheets.google.com/feeds/list/hidden/od6/public/values?alt=json"
https.get(query, resp => {console.log (resp)});
});
so I am not making an api call to a non-google service yet somehow I believe it's blocking me. How else can you do it?
Without a payment plan required, Cloud Functions can make outgoing HTTP requests to APIs under control of Google. Typically these are well documented APIs, and are protected from abuse. It's worth noting however, this does not necessarily include anything in the google.com domain. An API has to be specifically whitelisted for use without a payment plan.
If you run into a formal Google-controlled API that is not whitelisted, please file a feature request to have that evaluated.

If I can use axios library for requesting 3rd api in firebase cloud functions [duplicate]

Trying to make a request to Paypal's API using PayPal-node-SDK
exports.requestPayment = functions.https.onRequest((req, res) => {
return new Promise(function (fullfilled, rejected) {
paypal.payment.create(create_payment_json, {}, function (error, payment) {
if (error) {
rejected(error);
} else {
console.log("Create Payment Response");
console.log(payment);
res.status(200).send(JSON.stringify({
paymentID: payment.id
})).end();
fullfilled(payment);
}
});
});
});
but I'm constantly getting an error:
Error: getaddrinfo ENOTFOUND api.sandbox.paypal.com api.sandbox.paypal.com:443
at errnoException (dns.js:28:10)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:76:26)
Things I've tried:
Making a request to a totally different host, still ENOTFOUND
Wrapping the request with cors(req,res, ()=>{...})
Prepending https:// to the host
What is the problem?
You'll need to be on a paid plan to make external API requests.
Firebase's Blaze plan (pay as you go) has a free allotment for Cloud Functions. https://firebase.google.com/pricing/
in my situation I had to wait and let what ever lag was happening pass. Now it's fine again.
I was having this issue because of weak internet, change the internet connection.
You need to include service account to the admin initialization. this fixed the same issue for me
Switch to the Firebase "Blaze" plan, which includes the free usage tier of the Spark plan before incurring any costs. Use the Blaze pricing calculator to see what you'd be charged for a given usage.
The first 5GB of outbound (egress) networking is free, which is the same as what "native" Google Cloud Functions would give you.

Resources