odatasap-gateways4hana

SAP S4Hana using the $filter option for 'LastChangeDate' is throwing 400 bad request error code


Using the SAP Business Accelerator Hub 'Try Out' section I have failed to filter accountingdocuments using the 'LastChangeDate' property value. While filtering by text property values like 'AccountingDocument' works as expected.

Link to SAP to try out the API: https://api.sap.com/api/API_OPLACCTGDOCITEMCUBE_SRV/tryout

https://sandbox.api.sap.com/s4hanacloud/sap/opu/odata/sap/API_OPLACCTGDOCITEMCUBE_SRV/A_OperationalAcctgDocItemCube?$top=50&$filter=AccountingDocument%20eq%20'100000032'&$inlinecount=allpages

The request above will return the response below. (The original response is a lot bigger, I have shortened it with only the important fields.)

{
    "__metadata": {
      "id": "https://sandbox.api.sap.com/s4hanacloud/sap/opu/odata/sap/API_OPLACCTGDOCITEMCUBE_SRV/A_OperationalAcctgDocItemCube(CompanyCode='1010',FiscalYear='2015',AccountingDocument='100000032',AccountingDocumentItem='1')",
      "uri": "https://sandbox.api.sap.com/s4hanacloud/sap/opu/odata/sap/API_OPLACCTGDOCITEMCUBE_SRV/A_OperationalAcctgDocItemCube(CompanyCode='1010',FiscalYear='2015',AccountingDocument='100000032',AccountingDocumentItem='1')",
      "type": "API_OPLACCTGDOCITEMCUBE_SRV.A_OperationalAcctgDocItemCubeType"
    },
    "CompanyCode": "1010",
    "FiscalYear": "2015",
    "AccountingDocument": "100000032",
    "LastChangeDate": "/Date(1502841600000)/",
}

As you can see the LastChangeDate of this AccountingDocument is '/Date(1502841600000)/'. Using this data I assumed the following request would give me the response I am looking for.

https://sandbox.api.sap.com/s4hanacloud/sap/opu/odata/sap/API_OPLACCTGDOCITEMCUBE_SRV/A_OperationalAcctgDocItemCube?$top=50&$filter=LastChangeDate%20eq%20'%2FDate(1502841600000)%2F'&$inlinecount=allpages

This is the response I get, which is basically a 400 bad request.

{
  "error": {
    "code": "005056A509B11EE1BB8AF4A65EC3CA20",
    "message": {
      "lang": "en",
      "value": "Invalid parametertype used at function 'eq' (Position: 16)"
    },
    "innererror": {
      "transactionid": "25669476CF9401C0E00665F8B4DE9B04",
      "timestamp": "20240605163836.8291520",
      "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)"
      }
    }
  }
}

Is it possible to do what I am trying?


Solution

  • After some more searching I have found the answer to my own question.

    https://sandbox.api.sap.com/s4hanacloud/sap/opu/odata/sap/API_OPLACCTGDOCITEMCUBE_SRV/A_OperationalAcctgDocItemCube?$top=50&$filter=LastChangeDate%20ge%20datetime'2024-06-05T00%3A00%3A00'&$inlinecount=allpages
    

    I assumed I had to use epoch time in the filter because that is what SAP returns, but it is possible to use a datetime like I did.