Utsav Gupta
Utsav Gupta

Reputation: 3971

How to perform PATCH operation in Firebase APi?

The firebase doc sys this is how it is supposed to be done:

curl -X PATCH -d '{"last":"Jones"}' \ 'https://[PROJECT_ID].firebaseio.com/users/jack/name/.json'

But I dont know how to convert this to a rest based request.

TO be clear I need to send a web request from javascript/java, hence I want to know what should be the body , and header and operation type for this request.

Can someone please help?

Upvotes: 0

Views: 3504

Answers (2)

Serge Angéloz
Serge Angéloz

Reputation: 51

You need teh following structure:

HTTP Request:

https://firestore.googleapis.com/v1/projects/*YOUPROJECT_ID*/databases/(default)/documents/users_admin/*DOCUMENT_ID*?**updateMask.fieldPaths=user_name&updateMask.fieldPaths=permisos.Administrador&updateMask.fieldPaths=user_email**

JSON Body (must be exactly the same structure and type as your database):

 {
  "fields": {
    "user_name": { "stringValue": "Test Actualización 2" },
    "permisos": {
      "mapValue": {
        "fields": {
          "Administrador": {
            "booleanValue": true
          }
        }
      }
    },
    
    "user_email": { "stringValue": "[email protected]" } 
  
  }
}

Upvotes: 0

Doug Stevenson
Doug Stevenson

Reputation: 317828

If you use the documentation for curl, you can figure out what that command line you showed is trying to tell you.

The HTTP method is: PATCH

The request body is: {"last":"Jones"}

The url is: https://[PROJECT_ID].firebaseio.com/users/jack/name/.json

Where PROJECT_ID is the name of your project. That's all there is to it.

Upvotes: 2

Related Questions