Monday 21 January 2019

HTTP PATCH for batch method in JSON

For updating IndividualCustomer in C4C using ODATA standard service for IndividualCustomerCollection

If required to test directly C4C system then add CSRF token.

Note: Need to maintain proper spacing as below, which will also cause an issue while triggering it.

POSTMAN Testing: POSTMAN - CPI -C4C 

--batch_1

Content-Type: multipart/mixed; boundary=changeset_guid_01


--changeset_guid_01

Content-Type: application/http

Content-Transfer-Encoding: binary


PATCH IndividualCustomerCollection('OBJECT ID') HTTP/1.1

Content-Length: 5000

Accept: application/json

Content-Type: application/json


{ "Phone": "+1 188-888-23", "Fax": "+1 0012346032324" }


--changeset_guid_01--

--batch_1--




HTTP POST using batch mode

For creating IndividualCustomer in C4C using ODATA standard service for IndividualCustomerCollection

If required to test directly C4C system then add CSRF token.

POSTMAN Testing: POSTMAN - CPI -C4C 


POST /http/dev/c4c/fixzone/individualcustomercollection_http HTTP/1.1
Host: Tenant URL
Content-Type: multipart/mixed;boundary=batch_1
Authorization: Basic UzAwMjAwMDQ0Nzk6QisxflhSLy0=
cache-control: no-cache
Postman-Token: 1188e0bb-7c63-4b46-920a-811da6c6ca79

--batch_1
Content-Type: multipart/mixed; boundary=changeset_guid_01
  
--changeset_guid_01
Content-Type: application/http
Content-Transfer-Encoding: binary

POST IndividualCustomerCollection HTTP/1.1
Content-Length: 5000
Accept: application/json
Content-Type: application/json

{
      "RoleCode": "CRM000",
      "LifeCycleStatusCode": "2",
      "TitleCode": "0001",
      "FirstName": "Ravi",
      "LastName": "Kumar",
      "LanguageCode": "EN",
      "CountryCode": "GB",
      "StateCode": "AN",
      "AddressLine1": "Ram Nagar",
      "Street": "Ram Nagar",
      "City": "US",
      "StreetPostalCode": "11214",
      "Phone": "+1 888-888-88",
      "Fax": "+1 0012346001234",
      "Email": "ravi.kumar1@gmail.com"
}

--changeset_guid_01--
--batch_1--





Remove XML node in XML using groovy script

Groovy script for removing the xml tag from the XML.

Below code is working:

import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
import groovy.xml.XmlUtil;
import groovy.util.*;

def Message processData(Message message) {
    //Body
       //def body = message.getBody();
       def body = message.getBody(java.lang.String) as String;
        def xml = new XmlSlurper().parseText(body)
 xml.children().findAll { it.name() == 'CustomerID' }.replaceNode {}
   
   body = XmlUtil.serialize(xml)
   message.setBody(body);
       return message;
}

Input:
<?xml version="1.0" encoding="UTF-8"?>
<IndividualCustomerCollection>
        <IndividualCustomer>
                               <CustomerID>343565</CustomerID>
                               <RoleCode>CRM000</RoleCode>
                               <TitleCode>0001</TitleCode>
        </IndividualCustomer>
</IndividualCustomerCollection>

Output:
<?xml version="1.0" encoding="UTF-8"?>
<IndividualCustomerCollection>
        <IndividualCustomer>
                               <RoleCode>CRM000</RoleCode>
                               <TitleCode>0001</TitleCode>
        </IndividualCustomer>
</IndividualCustomerCollection>