Search code examples
firebaserestfirebase-realtime-databasecrud

How can I update Firebase field value using Rest API


The result of Firebase RestAPI - https://profile-feab8-default-rtdb.firebaseio.com/user0.json - is as below.

{
  "contact":{
    "email":"topsan72@gmail.com",
    "phone":"770-777-0073"
  },
  "name":{
    "firstname":"Donggeun",
    "nickname":"Dennis",
    "secondname":"Jung"
  }
}

I wanna know the RestAPI which updates the value of "phone" key to "777-777-7777".


Solution

  • You need to issue a PATCH request. As explained in the doc: "Using a PATCH request, we can update specific children at a location without overwriting existing data".

    Concretely you need to issue the following HTTP request:

    curl -X PATCH -d '{
      "phone": "777-777-7777"
    }' \
      'https://profile-feab8-default-rtdb.firebaseio.com/user0/contact.json'