Skip to Content
Technical Articles
Author's profile photo Saranya Baskaran

SAP Cloud Integration – OData V2 Conditional Update

Introduction

The HTTP Protocol has a concept of conditional requests.

HTTP conditional requests are requests that are executed differently, depending on the value of specific headers like If-Match

If-Match can be used to prevent the modification of a resource without overriding another change that has been done since the original resource was fetched. If the request cannot be fulfilled, the 412(Precondition Failed) response is returned.

 

How to achieve conditional update via OData V2 adapter in SAP Cloud Integration?

OData V2 adapte allows propagation of “If-Match” header to the receiver.
The value for the header “If-Match” has to be fetched by READ operation on the resource that is being updated.

 

Simple Update

The Update operation can be configured via PUT, MERGE or PATCH.
Assume the below service accepts only conditional Update. i.e., PUT operation requires “If-Match” header in the request.

https://services.odata.org/V2/(S(ifmatch))/OData/OData.svc/

Here we will update the Product with ID=1

The Update payload is as below

<Products>
	<Product>
		<ID>1</ID>
		<Rating>5</Rating>
	</Product>
</Products>

 

Assume the GET of <serviceURL>/Products(ID=1) returns an Etag header that has to be passed in the If-Match header of PUT request.

  1. The Integration Flow is modeled with sequential multicast.
  2. Branch 1 does the GET request
  3. The Etag response header is stored using Write Variable.
  4. Branch 2 will set the “If-Match” header from the global variable from step 3. PUT operation is configured.

1. Content Modifier 1

The update payload is set in this content Modifier.

2. Sequential Multicast: Branch 1
2.1. Content Modifier 2

The value of the key property (ID) is stored from the update payload in exchange property “keyValue”

2.2. Request Reply 1

OData receiver is configured for GET call. ID is set from the exchange property “keyValue”

2.3. Write Variables 1

The response header “Etag” value is stored in global variable “etag”.

3. Sequential Multicast: Branch 2
3.1. Content Modifier 3

If-Match exchange header is created with the value from global variable “etag”.

3.2. Request Reply 2

OData receiver is configured for PUT call. The “If-Match” header set in Content Modifer 3 is passed to receiver endpoint and conditional PUT will be executed.

Update in Batch

  1. The Integration Flow is modeled with sequential multicast.
  2. Branch 1 does the GET request
  3. The Etag response header is stored using Write Variable.
  4. Branch 2 will set the “If-Match” header from the global variable from step 3.
  5. Message mapping maps the update payload to batch payload and sets the “If-Match” header in the batch Payload.

Message Mapping 1
  1. Map the batch payload for the entitySet and its properties.
  2. The headerName will be constant
  3. Click the header value. Create a script file.
  4. Define a function getHeader() to get the header value that is set in Content Modifier 3.
  5. Pass the constant “If-Match” as an argument to get the header value and assign it to headerValue.

 

Assigned Tags

      4 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Vinay Avva
      Vinay Avva

      Hi Saranya,

      Awesome article. Thanks for sharing. Is there any article for just performing Create operation.

      Author's profile photo Saranya Baskaran
      Saranya Baskaran
      Blog Post Author

      Hi Vinay,

      You can refer to https://blogs.sap.com/2017/09/06/payload-structures-in-odata-v2-adapter-for-sap-cloud-platform-integration/ for the payload structure.

      I'm not sure if there is a step by step blog for Create operation.

       

      Author's profile photo Pratibha Singh
      Pratibha Singh

      Great Saranya, i was looking for this answer that how is it possible and its here. Simply superb

      Author's profile photo Christopher Linke
      Christopher Linke

      Awesome, thank you so much!!