on 02-22-2023 11:19 AM
Hi I am working integrating SAP SF using OData V2 Services. I made a POST request for creating a USER and it works fine as shown in below screenshot.
I want to use same request for Updating the USER. If the userId is available it should create one, otherwise update the existing one but facing error.
In OData Dictionary Upsertale operation is true for User below is the screenshot, so what I am doing wrong here, please guide.
Dear vinaysharma27
You need to make below corrections.
URI for your update or PUT request must be as same as highlighted below
It cannot be below for update opertation
HTTP Method method must be: PUT
URI must be: https://<API-endpoint-URL>/odata/v2/User('<userId>')
Updating a User:
You can use the same request to update a user if it already exists. The upsert operation allows you to both insert
and update users.
Update a User with PUT
You can use a PUT request to update a user. This HTTP request replaces all property values including links in the
existing entry with the values provided in the request payload. If a property is not present in the payload, it will be
restored to the default value. A successful PUT request returns status code 204 with no response body.
Operation: Update
HTTP Method: PUT
URI: https://<API-endpoint-URL>/odata/v2/User('<userId>')
Sample Payload:
{
"__metadata":{
"uri":"User('acraig')",
"type":"SFOData.User"
},
"userId":"acraig",
"status":"t",
"password":"Abc123",
"firstName":"Amy",
"lastName":"Craig",
"username":"acraig",
"email":"amy.craig1@abc.com"
}
Alternatively
Updating a User with Merge
Unlike PUT, a merge operation does not erase any existing information of an entry. Instead, it performs an
incremental update only with the information provided in the request payload. Note that the merge operation is must be indicated in the X-HTTP-REQUEST request header of a POST request.
Operation: Merge
HTTP Method: POST
URI: https://<API-endpoint-URL>/odata/v2/User('<userId>')
Headers: X-HTTP-METHOD: MERGE
Sample Payload:
{
"email":"acraig@bestrun.com",
"mi":"Louise"
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi abdul.waheed2, I am clear on the Update Part using PUT. I am able to update and create records using PUT and POST.
My question is how I can achieve UPSERT request using a same/single endpoint?
Explanation: Using a single endpoint, I should be able to UPDATE (if the id/primary key is existing) and CREATE (if the id/primary key is not present).
I don't want to use 2 different endpoints for Updating and Creating a record.
User | Count |
---|---|
6 | |
3 | |
3 | |
3 | |
2 | |
1 | |
1 | |
1 | |
1 | |
1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.