You have an example using CUD ODataXXXRequestBuilders

Throughout the documentation, I found examples for ODataQueryBuilder. But do you have an example of using the Create, Update, and Delete methods of the com.sap.cloud.sdk.odatav2.connectivity package:

  • ODataCreateRequestBuilder
  • ODataDeleteRequestBuilder
  • ODataUpdateRequestBuilder

How is the CSRF token handled?

Please provide a working example?

+4
source share
1 answer

CSRFs are retrieved with a HEAD request at the OData service metadata endpoint.

Some notes:

  • The following examples assume that you have a destination named "DestinationName" configured in the SAP Cloud Platform cab.
  • , , S/4HANA, , .

ODataCreateRequestBuilder

Map<String, Object> body = new HashMap<>();
body.put("FirstName", "John");
body.put("LastName", "Doe");
body.put("BusinessPartnerCategory", "1");

ODataCreateRequest createRequest =
    ODataCreateRequestBuilder
        .withEntity("/sap/opu/odata/sap/API_BUSINESS_PARTNER", "A_BusinessPartner")
        .withBodyAsMap(body)
        .build();

createRequest.execute("DestinationName");                 

ODataUpdateRequestBuilder

Map<String, Object> keys = new HashMap<>();
keys.put("BusinessPartner", "12345");

Map<String, Object> params = new HashMap<>();
params.put("FirstName", "John");
params.put("MiddleName", "D.");
params.put("LastName", "Doe");
params.put("BusinessPartnerCategory", "1");

final ODataUpdateRequest updateRequest =
    ODataUpdateRequestBuilder
        .withEntity("/sap/opu/odata/sap/API_BUSINESS_PARTNER", "A_BusinessPartner", keys)
        .withBodyAsMap(params)
        .build();

updateRequest.execute("DestinationName");      

ODataDeleteRequestBuilder

Map<String, Object> keys = new HashMap<>();
keys.put("BusinessPartner", "12345");
keys.put("AddressID", "98765");

ODataDeleteRequest deleteRequest =
    ODataDeleteRequestBuilder
        .withEntity("/sap/opu/odata/sap/API_BUSINESS_PARTNER", "A_BusinessPartnerAddress", keys)
        .build();

deleteRequest.execute("DestinationName");
+7

Source: https://habr.com/ru/post/1694002/


All Articles