sashoalm
sashoalm

Reputation: 79665

OData PUT request getting response of "428 Precondition Required"

I'm sending a PUT request (using PostMan) to the TripPin service from the OData Basic Tutorial.

PUT http://services.odata.org/v4/TripPinServiceRW/People('russellwhyte')

The body:

{
"@odata.id": "serviceRoot/Airlines('FM')"
}

The response I'm getting is 428 (Precondition Required). There is already a question OData : Why am I getting HTTP 428 (Precondition Required) error while performing an update, and the answer there states that:

your service uses optimistic locking and expects an If-Match header, containing the ETag of the entity, in the request

But the answer doesn't make it clear how to put a correct If-Match header, and I couldn't find any examples.

So how can I fix this error (by adding an If-Match header with the ETag or otherwise)?

Upvotes: 3

Views: 3611

Answers (1)

sashoalm
sashoalm

Reputation: 79665

I found a workaround in http://www.odata.org/documentation/odata-version-2-0/operations/

When issuing a PUT, MERGE or DELETE request, clients need to indicate an ETag in the If-Match HTTP request header. If for a given client it is acceptable to overwrite any version of the Entry in the server, then the value "*" may be used instead. If a given Entry has an ETag and a client attempts to modify or delete the Entry without an If-Match header servers should fail the request with a 412 response code.

Putting '*' for If-Match works and the server now returns 204 No Content and my changes are successfully made.

enter image description here

Otherwise we have to put the contents of the odata.etag field from the GET request. For example for "@odata.etag": "W/\"08D417AED09F4758\"", we put W/"08D417AE4EA83DB1" into the If-Match header.

Upvotes: 4

Related Questions