最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - cloud function testing failing "Invalid request, unable to process." - Stack Overflow

programmeradmin5浏览0评论

I have written a simple cloud function which I also deployed already to firebase and the code works. It is the following function:

exports.testfunction = functions.https.onCall(async (data) => {
     const mydata = JSON.parse(data)
     const mydata1 = JSON.parse({const1: "AAA", const2: "BBB", const3: "CCC"})
     return{mydata1}
 });

Now that I want to test this function localy, Im running the following mand in my terminal: firebase emulators:start and I get no errors so far. Anyways as soon as I try to call the function with http://localhost:5001/MYPROJECTNAME/us-central1/testfunction in my browser, Im receiving the following error message which I can not find any workaround for:

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

The thing is, the function itself is working great if I deploy it and call it from inside my app, but Im failing to run it from my firebase emulator inside the console. What am I doing wrong here?

I have written a simple cloud function which I also deployed already to firebase and the code works. It is the following function:

exports.testfunction = functions.https.onCall(async (data) => {
     const mydata = JSON.parse(data)
     const mydata1 = JSON.parse({const1: "AAA", const2: "BBB", const3: "CCC"})
     return{mydata1}
 });

Now that I want to test this function localy, Im running the following mand in my terminal: firebase emulators:start and I get no errors so far. Anyways as soon as I try to call the function with http://localhost:5001/MYPROJECTNAME/us-central1/testfunction in my browser, Im receiving the following error message which I can not find any workaround for:

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

The thing is, the function itself is working great if I deploy it and call it from inside my app, but Im failing to run it from my firebase emulator inside the console. What am I doing wrong here?

Share Improve this question asked Nov 3, 2021 at 14:03 Kubaguette The TestobunKubaguette The Testobun 2932 silver badges17 bronze badges 2
  • Doesn't this one - stackoverflow./questions/62091410/… - answer your question? – raina77ow Commented Nov 3, 2021 at 14:10
  • @raina77ow It goes in the right direction. The answer over there suggests to add an argument to the call itself but how can I do this if I just copy paste the link in my browser? Im sorry if this ment sounds little bit stupid, Im really new to this and its hard for me to understand those cloud functions. – Kubaguette The Testobun Commented Nov 3, 2021 at 23:13
Add a ment  | 

1 Answer 1

Reset to default 6

As explained in the documentation for Callable Cloud Functions:

It's important to keep in mind that HTTPS callable functions are similar but not identical to HTTP functions. To use HTTPS callable functions you must use the client SDK for your platform together with the functions.https backend API (or implement the protocol).

So, if you want to directly call the function via it's URL, your HTTP Request needs to follow the protocol specification for https.onCall.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论