Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Get all orders for a specific SoldToParty via API (A2X)

Rohling
Discoverer
0 Kudos
524

Hi Community,

I would like to create an Order History feature in our Commerce Cloud by listing all orders of a specific customer. To achieve this, I need to retrieve all orders of the customer (SoldToParty) at both header and item level (although item level information can be obtained later using the order number from the header).

My aim is to retrieve all orders from ERP (S4/Hana) via an API request regardless of the SalesOrderType.

Can you please advise which A2X API can be used for this purpose and provide guidance on the Request for such a GET call?

Thank you.

7 REPLIES 7

raymond_giuseppi
Active Contributor
0 Kudos
502

Did you already look at documentation/reference such as Sales Order (A2X) ?

0 Kudos
431

For filters look at Filtering for example.

0 Kudos
292

You can also find the API to get subsequent/preceding item in the document flow at header or item level in the previously page provided link (example) ...

S0011572494
Participant
452

You can use the A2X A_SalesOrder GET Request for this and use the correct filter parameters. 

https://<your-sap-host>/sap/opu/odata/sap/API_SALES_ORDER_SRV/A_SalesOrder?$top=20&$filter=SoldToParty eq '229670'&$inlinecount=allpages&$orderby=SalesOrder&$format=json

$top,$skip and $inlinecount is used usually to page the request

You can use the $select parameter to strip down the answer or the $expand if you want to have certain information of underlying objects. Nevertheless be aware that the expand can have serious performance impact. For further information look at the documentation linked in the API doc 
https://api.sap.com/api/API_SALES_ORDER_SRV/path/get_A_SalesOrder

Rohling
Discoverer
0 Kudos
415

Thanks a lot! That was quite easy with your great example :-), Don't know why but I use "=" instead of "eq"!

One more topic where you maybe can help. I checked the documentation without a getting a solution.

Is there a possibility to create the request above also with a time time interval of 3 month for CustomerPurchaseOrderDate? E.g. last three month or from Date 01.04.2024 to date 01.07.2024

0 Kudos
406

I tend to use the eq, ne, lt etc. operators to differ better from the URL parameters that are set. 

You can use the datetime formatter to send a date value and the date range has to be calculated as two dates accordingly

https://<your-host>/sap/opu/odata/sap/API_SALES_ORDER_SRV/A_SalesOrder?$top=20&$filter=SoldToParty eq '229670' and CreationDate ge datetime'2024-01-31T01:00:00' and CreationDate le datetime'2024-02-03T00:00:00' &$inlinecount=allpages&$orderby=SalesOrder

Rohling
Discoverer
0 Kudos
308

@S0011572494 Thank you very much! It works fine! However, I noticed that it would be great to receive also all the documents attached to an order (such as invoices, delivery documents, and general attachments). Is it possible to retrieve all the attached documents for an order, too? And can I later select a specific document to obtain a URL for opening or downloading it?