среда, 13 октября 2021 г.

How to make oData service working from outside

 At first, select oData service you want to check, for example, something with business partner.

 Here is API_BUSINESS_PARTNER service - need to activate in /IWFND/MAINT_SERVICE


Then, go to "Call Browser" button:

URL with this format will be opened: 

https://s4host.net:8070/sap/opu/odata/sap/API_BUSINESS_PARTNER/?$format=xml

Here you can see some collections, which starts from "A_" patterns:


Copy such collection (A_BusinessPartner) and put it after basic service name:

https://s4host.net:8070/sap/opu/odata/sap/API_BUSINESS_PARTNER/A_BusinessPartner

It brings the list of business partners from the system:


To have information about exact BP, put BP number in such format to URL:

https://s4host.net:8070/sap/opu/odata/sap/API_BUSINESS_PARTNER/A_BusinessPartner('300000')


You can do the same from Postman for example:


To expand business partner data for some particular directions, you can add such extension (in blue):

https://s4host.net:8070/sap/opu/odata/sap/API_BUSINESS_PARTNER/A_BusinessPartner('300000')/to_BusinessPartnerAddress


To have all API structure, you can append URL by $metadata extension:
https://s4host.net:8070/sap/opu/odata/sap/API_BUSINESS_PARTNER/$metadata


To create Sales Order, you can use Postman with those POST request:

https://s4host.net:8070/sap/opu/odata/sap/API_SALES_ORDER_SRV/A_SalesOrder

Put your POST-URL and request X-CSRF-Token=fetch through GET request:


Then put the received result in header value of POST request:



More-or-less minimum POST request JSON payload looks like that (values coloured by blue)

{
    "SalesOrderType""OR",
    "SalesOrganization""RU01",
    "DistributionChannel""01",
    "OrganizationDivision""01",
    "SoldToParty""2",
    "PurchaseOrderByCustomer""Created via OData Service",
    "CustomerPaymentTerms""0001",
    "to_Partner": [
        {
            "PartnerFunction""SH",
            "Customer""2"
        }
    ],
    "to_Item": [
        {
            "Material""2000000010",
            "RequestedQuantity""2",
            "to_PricingElement": [
                {
                    "ConditionType""PR00",
                    "ConditionRateValue""125"
                }
            ]
        },
        {
            "Material""2000000011",
            "RequestedQuantity""10",
            "to_PricingElement": [
                {
                    "ConditionType""PR00",
                    "ConditionRateValue""230"
                }
            ]
        }
    ]
}



Here are some useful links:

SAP API Business Hub

How to find an API on SAP S/4HANA OP (EN) | SAP Blogs

Create Sales Order - SAP Help Portal

https://help.sap.com/docs/SAP_S4HANA_ON-PREMISE/1dad2180e6f34b75ac77afce5cb5eda1/7ab0bcc20b1611da1503000bcddc2565.html?&version=2020.001 

Other API-s examples

API_VMSVEHICLE

API_VMSVEHICLELOCATION

Operations for Vehicle Management System for Vehicle - Read - SAP Help Portal

Converting UUID between hyphened representation and RAW16 | SAP Blogs

Request syntax for vehicles