How to update data using the REST API

We have seen creating data using the REST API in the previous post.

Updating data using the REST API is similar. Just few modifications and you’re ready with the update!.

  • Data can be updated using the PUT method. Both the endpoints remain the same.

1./rest/v1
2./rest/v1/fn/mutation/upsert - equivalent to calling the Hypi upsert function in GraphQL

  • The body (--data-raw) contains the data to be updated in the table. You need to pass on hypi.id of the record to be updated.
  • The format of the input data is the same as normal update operation.

Here are the sample cURL requests. Again, the only differentiating point between two requests is the use of different endpoints.

Sample 1

curl --location --request PUT 'https://api.staging.hypi.dev/rest/v1' \
--header 'hypi-domain: inclemency.apps.hypi.app' \
--header 'content-type: application/json' \
--header 'authorization: Your_Key' \
--data-raw '{ 
    "values": {
      "StudentMedicalRecord": [
        { "hypi": {"id": "01FTDB1JQQEKZ5D4PZ5D3W1PMJ"},"height": 5.6, "weight": 60, "bloodGroup": "B+"}
       ]
    }
}'

Sample 2

curl --location --request PUT 'https://api.staging.hypi.dev/rest/v1/fn/mutation/upsert' \
--header 'hypi-domain: inclemency.apps.hypi.app' \
--header 'content-type: application/json' \
--header 'authorization: Your_Key' \
--data-raw '{ 
    "values": {
      "StudentMedicalRecord": [
        { "hypi": {"id": "01FTDB1JQQEKZ5D4PZ5D3W1PMJ"},"height": 5.6, "weight": 60, "bloodGroup": "B+"}
       ]
    }
}'

***Replace hypi-domain, authorization, and input data with your own set of values.

Check the Update Data with PUT POSTMAN collection for the data update requests in different programming languages! Click </> and choose the programming language of your choice.

Run in Postman