Continuing with our blogs on Purchase Requisition OData API, we would like to share some insights related to how error messages and response codes are returned in PR OData API -

1.     For any response from the API with errors, the response structure in JSON format is as below –

{

    "error": {

        "code": "XX/123",

        "message": {

            "lang": "en",

            "value": "Account 12345678 does not exist in chart of accounts XXXX"

        },

        "innererror": {

            "application": {

                "component_id": "MM-PUR-REQ",

                "service_namespace": "/SAP/",

                "service_id": "API_PURCHASEREQ_PROCESS_SRV",

                "service_version": "0001"

            },

            "transactionid": "XXXXXXXXXXXXXXXX",

            "timestamp": "",

            "Error_Resolution": {

                "SAP_Transaction": "",

                "SAP_Note": "See SAP Note 1797736 for error analysis (https://service.sap.com/sap/support/notes/1797736)"

            },

            "errordetails": [

                {

                    "code": "XX/123",

                    "message": "Account 12345678 does not exist in chart of accounts XXXX ",

                    "propertyref": "",

                    "severity": "error",

                    "transition": false,

                    "target": ""

                }

            ]

        }

    }

}

 

2.     If an exception is raised from the API then the same structured response as above is returned, and you can find error message and severity in the “errordetails” block, for example –

{

    "error": {

        "code": "XX/124",

        "message": {

            "lang": "en",

            "value": "Creating operations are disabled for entity 'API_PURCHASEREQ_PROCESS~A_PURREQADDDELIVERY'"

        },

        "innererror": {

            "application": {

                "component_id": "MM-PUR-REQ",

                "service_namespace": "/SAP/",

                "service_id": "API_PURCHASEREQ_PROCESS_SRV",

                "service_version": "0001"

            },

            "transactionid": "",

            "timestamp": "",

            "Error_Resolution": {

                "SAP_Transaction": "",

                "SAP_Note": "See SAP Note 1797736 for error analysis (https://service.sap.com/sap/support/notes/1797736)"

            },

            "errordetails": [

                {

                    "code": "CX_SADL_ENTITY_CUD_DISABLED",

                    "message": "Creating operations are disabled for entity 'API_PURCHASEREQ_PROCESS~A_PURREQADDDELIVERY'",

                    "propertyref": "",

                    "severity": "error",

                    "transition": false,

                    "target": ""

                },

                {

                    "code": "/IWBEP/CX_MGW_BUSI_EXCEPTION",

                    "message": "An exception was raised",

                    "propertyref": "",

                    "severity": "error",

                    "transition": false,

                    "target": ""

                }

            ]

        }

    }

}

 

3.     If a business error like delivery date or account details etc. occurs, the same structured response is returned, and you can again find error message and severity in the “errordetails” block, for example please find below sample response with an error and warning –

{

    "error": {

        "code": "06/223",

        "message": {

            "lang": "en",

            "value": "Document number 12345678 not within defined interval"

        },

        "innererror": {

            "application": {

                "component_id": "MM-PUR-REQ",

                "service_namespace": "/SAP/",

                "service_id": "API_PURCHASEREQ_PROCESS_SRV",

                "service_version": "0001"

            },

            "transactionid": "F9B22F18B8250170E005DB11195844D8",

            "timestamp": "",

            "Error_Resolution": {

                "SAP_Transaction": "",

                "SAP_Note": "See SAP Note 1797736 for error analysis (https://service.sap.com/sap/support/notes/1797736)"

            },

            "errordetails": [

                {

                    "code": "ME/040",

                    "message": "Can delivery date be met?",

                    "propertyref": "",

                    "severity": "warning",

                    "transition": false,

                    "target": ""

                },

                {

                    "code": "06/223",

                    "message": "Document number 12345678 not within defined interval",

                    "longtext_url": "/sap/opu/odata/iwbep/message_text;o=LOCAL/T100_longtexts(MSGID='06',MSGNO='223',MESSAGE_V1='12345678',MESSAGE_V2='',MESSAGE_V3='',MESSAGE_V4='')/$value",

                    "propertyref": "",

                    "severity": "error",

                    "transition": false,

                    "target": ""

                }

            ]

        }

    }

}

 

4.     If an invalid value is passed in any of the fields, then the business logic does not get called and even before that the gateway returns the call, and in such case the error is returned in the “error” block, for example if in a text field characters more than the allowed length are passed, the response is as below –

{

    "error": {

        "code": "/IWCOR/CX_DS_EDM_FACET_ERROR/005056A509B11ED1BDCCCC5E8168819D",

        "message": {

            "lang": "en",

            "value": "Property 'PurReqnDescription' at offset '622' has invalid value 'This is a very veryyyyyyyyyyyyyyyyyyyyyyyyyyyy long longgggggggggggggggggggggggggg description'"

        },

        "innererror": {

            "application": {

                "component_id": "MM-PUR-REQ",

                "service_namespace": "/SAP/",

                "service_id": "API_PURCHASEREQ_PROCESS_SRV",

                "service_version": "0001"

            },

            "transactionid": "BD2F36725A970250E005DB0D13C820DA",

            "timestamp": "20191024060721.3521760",

            "Error_Resolution": {

                "SAP_Transaction": "For backend administrators: use ADT feed reader \"SAP Gateway Error Log\" or run transaction /IWFND/ERROR_LOG on SAP Gateway hub system and search for entries with the timestamp above for more details",

                "SAP_Note": "See SAP Note 1797736 for error analysis (https://service.sap.com/sap/support/notes/1797736)"

            },

            "errordetails": []

        }

    }

}

 

Some related links for reference –

  1. FAQs
  2. Purchase Requisition OData API – Episode 1
  3. Purchase Requisition OData API – Episode 2
  4. Business documentation

Thanks for going through the blog posts. Let us know your suggestions in comments section below.