skip to Main Content

I am sucessfully running local cloud function from postman with this url:

http://127.0.0.1:5001/spotnik-7de37/us-central1/getUsers

But on my app using:

val functions = Firebase.functions
functions.useEmulator("10.0.2.2", 5001)
functions.getHttpsCallable("http://127.0.0.1:5001/spotnik-7de37/us-central1/getUsers")

I get:
Failed com.google.firebase.functions.FirebaseFunctionsException: INTERNAL

2

Answers


  1. Need to use HTTPS protocol and not HTTP. See https://firebase.google.com/docs/emulator-suite/connect_functions

    Instrument your app for HTTPS functions emulation Each HTTPS function
    in your code will be served from the local emulator using the
    following URL format:

    http://$HOST:$PORT/$PROJECT/$REGION/$NAME

    For example a simple helloWorld function with the default host port
    and region would be served at:

    https://localhost:5001/$PROJECT/us-central1/helloWorld

    Login or Signup to reply.
  2. Take a look at Call functions from your app. Just use the name of the function for the getHttpsCallable() call:

    private Task<String> addMessage(String text) {
      // Create the arguments to the callable function.
      Map<String, Object> data = new HashMap<>();
      data.put("text", text);
      data.put("push", true);
    
      return mFunctions
        .getHttpsCallable("addMessage")
        .call(data)
        .continueWith(new Continuation<HttpsCallableResult, String>() {
            @Override
            public String then(@NonNull Task<HttpsCallableResult> task) throws Exception {
                // This continuation runs on either success or failure, but if the task
                // has failed then getResult() will throw an Exception which will be
                // propagated down.
                String result = (String) task.getResult().getData();
                return result;
            }
        });
    }
    

    In your case I might try the above example using:

    httpsCallable('spotnik-7de37')

    Or use this:

    getHttpsCallableFromUrl("http://127.0.0.1:5001/spotnik-7de37/us-central1/getUsers")

    Also ensure you are using the proper IP for your emulator:

    functions.useEmulator("127.0.0.1", 5001);

    Additionally, if you want to use the entire URL string for the call, you can use getHttpsCallableFromUrl.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search