Amol Kumar
Amol Kumar

Reputation: 63

Swift, Firebase Cloud Function - INVALID ARGUMENT error

I am trying to call a cloud function from firebase by using the following code.

Client code -

func checkUserStatus() {
    let functions = Functions.functions(region: "us-central1")
    
    let argument  = [
        "currentUser":
            [
                "email": "[email protected]",
                "uid": "LP8R4yZroyMTj"
            ]
    ]
    
    functions.httpsCallable("subscriptionStatus").call(argument) { (result, error) in
        if error != nil {
            print("FAILED")
            print(error)
        } else {
            print("PASSED")
           print(result)
        }
    }
}

Cloud Function code -

exports.subscriptionStatus = functions.https.onRequest(async (request: Request<RequestBody>, response) => {

    const {
        currentUser,
    } = request.body

 // Logic goes here

 }

But getting the following error when running it

Error Domain=com.firebase.functions Code=3 "INVALID ARGUMENT" UserInfo={NSLocalizedDescription=INVALID ARGUMENT}

The function takes in a parameter called currentUser which further comprises of user's email and uid. Any lead would be highly appreciated on the matter.

Upvotes: 1

Views: 2246

Answers (1)

Torewin
Torewin

Reputation: 907

Just to have an answer to the question for anyone else having a similar issue.

To call an onRequest() cloud function you need to use the URL where it's deployed at i.e. https://us-central1-<project-id>.cloudfunctions.net/<function-name>?<var-name>=<var-value>

If you're wanting to call it in the client app using call, then you'll need to use an onCall() cloud function.

Firebase has a one of the best documentation on their services: https://firebase.google.com/docs/functions/get-started

OnCall functions:
https://firebase.google.com/docs/functions/callable

onRequest functions:
https://firebase.google.com/docs/functions/http-events

Upvotes: 3

Related Questions