Maintain BusinessPartner Master Data using OData APIs in a SAP S/4HANA Cloud system
This blog explains how Business Partner master data can be maintained in a SAP S/4 HANA Cloud system using OData APIs. OData APIs allow the creation and consumption of queryable and interoperable REST methodologies in a simple and standard way. These API’s offer light-weight connection option for data transfer with SAP S/4HANA systems.The OData service API_BUSINESS_PARTNER is available on SAP API Business Hub, it can be used to maintain master data related to Business Partner, Customer and Supplier entities.
Prerequisites:
- A Communication User for SAP communication Scenario: SAP_COM_0008 (Business Partner, Customer and Supplier Integration). Please refer the document on how to create Communication User and Arrangements.
- A REST client like Postman.
Procedure:
1) Launch Postman Client.
- In the authorization tab, set the type as “Basic Auth”.
- Enter the communication username and password.
- HTTP method: GET
- URI: https://<system_path>/sap/opu/odata/sap/API_BUSINESS_PARTNER/$metadata
- HTTP Response 200 OK indicates the successful load of the metadata.
- The entity data model of the service can be understood by the metadata of the service.
2) To keep it simple, we shall create a Business Partner with basic details like name, address and tax entities.
- HTTP method: POST
- URI: https://<system_path>/sap/opu/odata/sap/API_BUSINESS_PARTNER/A_BusinessPartner
- JSON:
{
“BusinessPartnerCategory” : “2”,
“OrganizationBPName1” : “SAP”,
“to_BusinessPartnerAddress” : [ {
“Country” : “DE”,
“StreetName” : “Dietmar-Hopp-Allee 16”,
“PostalCode” : “69190”,
“CityName” : “Walldorf”,
“to_AddressUsage” : [ {
“AddressUsage” : “XXDEFAULT” } ]
} ],
“to_BusinessPartnerTax” : [ {
“BPTaxType”:”DE0″,
“BPTaxNumber”:”DE012345678″
}] } - HTTP response 201 Created, indicates successful creation and the Business Partner Number (1000075) for the entity created is available in the response.
3) Let us update the “OrganizationBPName1” attribute of the created entity from “SAP” to “SAP SE”.
- HTTP method: PATCH
- URI: https://{system_path}/sap/opu/odata/sap/API_BUSINESS_PARTNER/A_BusinessPartner(‘1000075’)
- JSON:
{ “OrganizationBPName1” : “SAP SE” } - HTTP response 204 No Content, indicates successful update.
4) Let us read the complete data of the created Business Partner using $expand property.
- HTTP method: GET
- URI: https://{system_path}/sap/opu/odata/sap/API_BUSINESS_PARTNER/A_BusinessPartner(‘1000075’)?$expand=to_BusinessPartnerAddress,to_BusinessPartnerTax
- HTTP response 200 OK, indicates successful read.
5) Let us see how to delete the tax number for the created Business Partner. (Note : It is not possible to delete the BusinessPartner entity, but some of its associated child entities can be deleted.)
- HTTP method: DELETE
- URI: https://{system_path}/sap/opu/odata/sap/API_BUSINESS_PARTNER/A_BusinessPartnerTaxNumber(BusinessPartner=’1000075′,BPTaxType=’DE0′)
- HTTP response 204 No Content, indicates successful delete.
The above illustrated examples are very simple, same steps can be followed for other entities and attributes in the service. Extensibility is supported in this service. Please refer to my previous blog Add Custom fields to SAP S/4HANA Business Partner OData API Entities for further details. Looking forward to your questions and feedback in the comments section.
Thanks for the great blog! I'm having an issue assigning a business partner role to the the business partner. I have tried during the POST function and also tried to PATCH the BP but neither method is working. Could there be an issue with the service?
Hi,
Please use the below json format for assigning role (say : FLCU00 ) to BP using HTTP method : POST on entity A_BusinessPartner.
{
“BusinessPartnerCategory” : “2”,
“OrganizationBPName1” : “SAP”,
“to_BusinessPartnerAddress” : [ {
“Country” : “DE”,
“StreetName” : “Dietmar-Hopp-Allee 16”,
“PostalCode” : “69190”,
“CityName” : “Walldorf”,
“to_AddressUsage” : [ {
“AddressUsage” : “XXDEFAULT” } ]
} ],
“to_BusinessPartnerRole” : [ {
“BusinessPartnerRole”:”FLCU00"
}] }
Regards,
Manasi Sridhar
Hi Manasi,
Since in BusiessPartner API's "A_CUSTOMER" EntitySet there is no "POST" operation mentioned, can you please tell how to create a Customer, or which EntitySet to be used for Creating a Customer ?
Thanks,
Kalpana.
Hi Kalpana,
When a BP is created with a customer role, Customer would be created. My previous comment has a payload of such an example. In case some customer specific data also need to created, make sure to pass the payload accordingly via "to_Customer" association when posting on A_BusinessPartner entity.
Regards,
Manasi Sridhar
Hi, would you mind to let me know if this API is available for 1709 SPS02 release?
Hi ,
API is available in OP since 1709 release.
Regards,
Manasi Sridhar
Hello,
we have the similar situation related this blog , we are currently using on premises S/4 Hana 1610 Ides version with gateway server 7.51.
we are trying to enable API_bussines_partner for our business but we are not able to find the API.
Is this because of the Lower version of S/4 Hana ?is the API available for 1610 version or do we need to have the latest version? could you please advice what is required to have the API enabale ?
Thanks,
-Satya
Hi @satyadev1, did you managed solve your issue?
This API is available in 1610 S/4 version?
Thanks advance.
Beto Lima
HI,
I am connecting from SAP PO system to S4 HANA OData adapter for using Service for Business Partner.
Reference Link for SAP API Hub: – https://api.sap.com/api/API_BUSINESS_PARTNER/resource?tag=A_BusinessPartner&path=get_A_BusinessPartner&method=get&opId=get_A_BusinessPartner
My requirement is to update following entities (A_BusinessPartner, A_AddressEmailAddress, A_AddressPhoneNumber, A_BusinessPartnerAddress) of this API_BUSINESS_PARTNER using batch mode.
I am facing following problems in doing it.
When I use this PATCH mode while forming the XML in PO, I get the following error in XPI Inspector.
—- Debugging information —-
cause-exception : java.lang.NullPointerException
cause-message : while trying to invoke the method com.sap.aii.adapter.lib.processor.util.ODataMethodEnum.ordinal() of a null object returned from com.sap.aii.adapter.lib.processor.util.ODataMethodEnum.getValueOf(java.lang.String)
class : java.util.ArrayList
required-type : java.util.ArrayList
converter-type : com.sap.aii.adapter.lib.processor.converter.ConverterXMLToList
path : /batchParts/batchChangeSet/batchChangeSetPart/A_BusinessPartner
version : 1.4.9
——————————-
[EXCEPTION]
com.thoughtworks.xstream.converters.ConversionException:
—- Debugging information —-
cause-exception : java.lang.NullPointerException
cause-message : while trying to invoke the method com.sap.aii.adapter.lib.processor.util.ODataMethodEnum.ordinal() of a null object returned from com.sap.aii.adapter.lib.processor.util.ODataMethodEnum.getValueOf(java.lang.String)
class : java.util.ArrayList
required-type : java.util.ArrayList
converter-type : com.sap.aii.adapter.lib.processor.converter.ConverterXMLToList
path : /batchParts/batchChangeSet/batchChangeSetPart/A_BusinessPartner
version : 1.4.9
Formed XML batch request: –
<batchParts>
<batchChangeSet>
<batchChangeSetPart>
<method>PATCH</method>
<A_BusinessPartner>
<A_BusinessPartnerType>
<BusinessPartner>3XXXXXX</BusinessPartner>
<BusinessPartnerCategory>1</BusinessPartnerCategory>
<CorrespondenceLanguage>DE</CorrespondenceLanguage>
<FirstName>Cegid Update SOAP UI Multi Part</FirstName>
<LastName>Development</LastName>
</A_BusinessPartnerType>
</A_BusinessPartner>
</batchChangeSetPart>
<batchChangeSetPart>
<method>PATCH</method>
<A_AddressEmailAddress>
<A_AddressEmailAddressType>
<AddressID>29882</AddressID>
<Person>29881</Person>
<OrdinalNumber>1</OrdinalNumber>
<EmailAddress>cegidMultiPart.test@HOMTAIL.com</EmailAddress>
</A_AddressEmailAddressType>
</A_AddressEmailAddress>
</batchChangeSetPart>
</batchChangeSet>
</batchParts>
In this way only the A_BusinessPartner entity is updated and there is no updates performed on the A_AddressEmailAddress entity.
XPI Inspector Batch Request: –
HTTP_CLIENT : 1663 REQUEST:
–batch
Content-Type: multipart/mixed; boundary=changeset_4d95dc09-e14a-4b14-b7c5-10d4edea3035
–changeset_4d95dc09-e14a-4b14-b7c5-10d4edea3035
Content-Type: application/http
Content-Transfer-Encoding: binary
PUT A_BusinessPartner(BusinessPartner=’300001797′) HTTP/1.1
Content-Length: 170
Accept: application/json
Content-Type: application/json
{“BusinessPartner”:”300001797″,”BusinessPartnerCategory”:”1″,”CorrespondenceLanguage”:”DE”,”FirstName”:”Cegid Update SOAP UI Multi Part”,”LastName”:”Development Request”}
–changeset_4d95dc09-e14a-4b14-b7c5-10d4edea3035
Content-Type: application/http
Content-Transfer-Encoding: binary
PUT A_AddressEmailAddress(AddressID=’29882′,Person=’29881′,OrdinalNumber=’1′) HTTP/1.1
Content-Length: 107
Accept: application/json
Content-Type: application/json
{“AddressID”:”29882″,”Person”:”29881″,”OrdinalNumber”:”1″,”EmailAddress”:”cegidMultiPart.test@HOMTAIL.com”}
–changeset_4d95dc09-e14a-4b14-b7c5-10d4edea3035–
–batch—
Response: –
HTTP_CLIENT : 1663 REPLY:
–1A552DA1A9F94F28F40E9F342AF197710
Content-Type: multipart/mixed; boundary=1A552DA1A9F94F28F40E9F342AF197711
Content-Length: 437
–1A552DA1A9F94F28F40E9F342AF197711
Content-Type: application/http
Content-Length: 71
content-transfer-encoding: binary
HTTP/1.1 204 No Content
Content-Length: 0
dataserviceversion: 2.0
–1A552DA1A9F94F28F40E9F342AF197711
Content-Type: application/http
Content-Length: 71
content-transfer-encoding: binary
HTTP/1.1 204 No Content
Content-Length: 0
dataserviceversion: 2.0
–1A552DA1A9F94F28F40E9F342AF197711–
–1A552DA1A9F94F28F40E9F342AF197710—
OData Adapter Configuration: –
Operation: CREATE
Resource Path: A_BusinessPartner
Enable Batch Processing: True
Thanks,
Varun
Thanks for the blog . Very informative . If we are using MDG for Business Partners - is there a ODATA service for that . I could only see a SOA service for MDG BP
Hi Minashi,
Thanks for this great blog.
Best regards.
Hi Manasi,
Thank you for sharing this blog, its helpful.
We have a requirement to add additional standard fields in API, which we added by extending the respective CDS. However, the code in FILL_BP_DATA does not automatically perform the mapping for additional fields.
Could you please assist on how to handle this?
Thanks in advance!
Hi Manasi,
Can i achieve the same for s/4 hana on permises, ?
If so, To access the odata service, i need to create a communication arrangement using the scenario SAP_COM_0008 ???... for s/4 hana on-permises ?...
Hi Mansi,
Nice blog illustrating the way to work with Standard API's provided by SAP.
i have a requirement where in, i need to add Email Address & Telephone Number to the business Partner. i understood that you updated business partner data with one field in the above post, but my question here is how would i pass the email address & Telephone directly while creating a BP through API_BUSINESS_PARTNER odata service. i tried different possibilities but none of those helped me. could you please let me know if you have any idea about this requirement. if you could share the payload that would be really helpful.
Thanks
Sri Ram
I am using API_BUSINESS_PARTNER.Not able to update lfa1 table but only BUT000.or BUT* .Any hints ?
That's a great blog!! I implemented this API to get Identification values.
However, can anyone help to understand how to retrieve Relationship information. Which expand property can be used or is there any separate ODATA available to fetch relationship information?