SAP Knowledge Base Article - Public

2930423 - How to Download Accounts Within Their Account Hierarchy Using OData

Symptom

You are aware that the SAP OData Service accounthierarchylist is modeled to fetch the details of a single account at a time. You are wondering if there is an alternative approach to get the account hierarchy for multiple accounts.

Environment

SAP Cloud for Customer

Resolution

The following approach allows to download all business partners within their account hierarchy. This can be achieved in three steps, and you may have to build an interim custom code to do this.

1. Download all account hierarchy records:

https://myxxxxxx.crm.ondemand.com/sap/c4c/odata/v1/accounthierarchylist/BusinessPartnerHierarchyBusinessPartnerCollection

This will return up to 1000 records. You can check how many accounts there are in the hierarchy using the following query:
https://myxxxxxx.crm.ondemand.com/sap/c4c/odata/v1/accounthierarchylist/BusinessPartnerHierarchyBusinessPartnerCollection/$count

To download more than 1000 records, you can use client side paging (https://github.com/SAP/C4CODATAAPIDEVGUIDE#client-side-paging) or use the built-in server side paging. You can check https://github.com/SAP/C4CODATAAPIDEVGUIDE#server-side-paging to see more on this.

2. Download the IDs of the accounts within the accounthierarchy:

https://myxxxxxx.crm.ondemand.com/sap/c4c/odata/v1/accounthierarchylist/BusinessPartnerHierarchyBusinessPartnerCollection('<ObjectID of each record returned from the previous call>')/BusinessPartnerBusinessPartner

These individual calls can be combined and executed in one round trip using $batch (https://www.odata.org/documentation/odata-version-2-0/batch-processing/).

3. Download the Business Partner Data for each InternalID returned from the above calls:

https://myxxxxxx.crm.ondemand.com/sap/c4c/odata/v1/c4codataapi/CorporateAccountCollection?$filter=AccountID eq 'InternalID 1' or AccountID eq 'InternalID 2' or ...

Note: If the $filter query parameters becomes too large, in order to avoid URL size limits, the above call can also be executed as a $batch call.

Note: You can use the same endpoint to update existing Account Hierarchy

See Also

See also KBA 2796677

Keywords

not possible able enable get customer customers account export business partner partners , KBA , LOD-LE-BP-HIE , Business Partner Hierarchy , LOD-CRM-INT-API , OData API (C4C Only) , How To

Product

SAP Cloud for Customer add-ins all versions ; SAP Cloud for Customer core applications all versions