Skip to main content
Skip table of contents

REST API of the RESTifier for SAP

The RESTifier provides a REST interface. The supported content type for results and requests is JSON (application/json).

Execute BAPI function

JS
GET /sap/:functionName?parameter1=value1[&...][&callback=clientCallback]
POST /sap/:functionName?[callback=clientCallback]

If the BAPI function name as only simple parameters then both GET and POST can be used. If the BAPI function has tables or structures as input parameter only POST can be used. For POST the body must be a JSON object with all parameters as properties and Content-Type must be application/json.

ParameterDescription
functionNameBAPI function name. Slash (/) must be encoded as tilde (~).
parameter1BAPI function parameters with value. The parameters names and types can be explored with /sap/:functionName/metadata.
callbackJSON-P callback

Example for executing a BAPI

The BAPI function is called with GET.

TEXT
curl http://localhost:3000/sap/ZGETCUSTOMERDETAILS?PARTNERNUMBER=0000008889

The same BAPI function can also be called with POST.

TEXT
curl -X POST -H "Content-Type: application/json" -d '{"PARTNERNUMBER":"0000008889"}' 'http://localhost:3000/sap/ZGETCUSTOMERDETAILS'

Response

JS
{
  "result": {
    "CITY": "SPRINGFIELD  07081",
    "COUNTRY": "US",
    "DISTRICT": "UNION",
    "HOUSENUMBERSTREET": "12 BROADWAY",
    "NAME": "John Taylor",
    "POSTALCODE": "07081",
    "PARTNERNUMBER": "0000008889"
  },
  "self_url": "http://localhost:3000/sap/ZGETCUSTOMERDETAILS?PARTNERNUMBER=0000008889"
}

Per default, the RESTifier trims the response fields of whitespaces and empty data. If you need the response untrimmed, you can add ~noclean as a query parameter to your request. ~noclean is a comma-separated, multi-value parameter and allows for the following values:

ValueDescription
whitespaceDo not trim whitespaces at all.
empty-valuesKeep simple types that are empty (like empty strings).
nulls Keep fields that are NULL.
empty-objectsKeep objects that do not contain any data.

Call with GET:

TEXT
curl http://localhost:3000/sap/ZGETCUSTOMERDETAILS?PARTNERNUMBER=0000008889&~noclean=whitespace,empty-values

Call with POST:

TEXT
curl -X POST -H "Content-Type: application/json" -d '{"PARTNERNUMBER":"0000008889"}' 'http://localhost:3000/sap/ZGETCUSTOMERDETAILS?~noclean=whitespace,empty-values'

Exception

If you call a RFC function instead of a BAPI, an exception on the SAP server can happen. In this case you get HTTP status 502 and the following response:

ResultTypeDescription
errorNumberHTTP status code
messageStringSAP error description
rfcErrorInfoObjectDetails of the error
rfcErrorInfo.codeNumberReturn value of last function from SAP client
rfcErrorInfo.groupNumberSAP error group
rfcErrorInfo.keyStringSAP error key or exception
rfcErrorInfo.abapMsgClassStringSAP ABAP message ID, or class
rfcErrorInfo.abapMsgTypeStringSAP ABAP message type, e.g. 'E', 'A' or 'X'
rfcErrorInfo.abapMsgNumberStringSAP ABAP message number
rfcErrorInfo.abapMsgV1StringSAP ABAP message details field 1, corresponds to SY-MSGV1
rfcErrorInfo.abapMsgV2StringSAP ABAP message details field 2, corresponds to SY-MSGV2
rfcErrorInfo.abapMsgV3StringSAP ABAP message details field 3, corresponds to SY-MSGV3
rfcErrorInfo.abapMsgV4StringSAP ABAP message details field 4, corresponds to SY-MSGV4
self_urlStringURL to this call

Empty elements of rfcErrorInfo will be suppressed. Find below an example response.

CODE
{
  "error": 502,
  "message": " Number:000",
  "rfcErrorInfo": {
    "code": 5,
    "group": 1,
    "key": "DIV_BY_ZERO",
    "abapMsgType": "",
    "abapMsgNumber": "000"
  },
  "self_url": "http://sap.e2e.ch/sap/Z_TEST_EXCEPTION"
}

Get BAPI function signature 

JS
GET /sap/:functionName/metadata
ParameterDescription
functionNameBAPI function name. Slash (/) must be encoded as tilde (~).

The result is of type JSON with these properties.

NameJavaScript TypeDescription
functionNameStringArray of function descriptions
metadataObjectJSON Schema with additional properties.
errorStringError description

An meta objects has these properties.

PropertyJavaScript TypeDescription
titleStringName of the object or property.
typeStringJavaScript type.
lengthNumberLength of a simple type or structure.
descriptionStringDescription of parameters from SAP. Can be empty.
sapTypeStringNative SAP type.
sapDirectionStringInput or output parameter. RFC_IMPORT | RFC_EXPORT | RFC_CHANGING | RFC_TABLES
sapTypeNameStringName of a structure or name of a structure of a table.
dbTableStringName of the SAP database table
dbTableFieldStringField of the SAP database table
labelStringShort description

Example for getting metadata

Get description of BAPI function STFC_STRING.

TEXT
curl http://localhost:3000/sap/ZGETCUSTOMERDETAILS/metadata
JS
{
  "error": null,
  "metadata": {
    "title": "Signature of SAP RFC function ZGETCUSTOMERDETAILS",
    "type": "object",
    "properties": {
      "PARTNERNUMBER": {
        "type": "string",
        "length": "10",
        "sapType": "RFCTYPE_CHAR",
        "description": "Character Field Length = 10",
        "sapDirection": "RFC_IMPORT",
        "label": "Character Field Length = 10",
        "title": "PARTNERNUMBER"
      }
    }
  },
  "functionName": "ZGETCUSTOMERDETAILS",
  "exec_url": "http://localhost:3000/sap/ZGETCUSTOMERDETAILS{?callback}",
  "self_url": "http://localhost:3000/sap/ZGETCUSTOMERDETAILS/metadata"
}

Find BAPI function /sap/functions

JS
GET /sap/functions/:searchTerms[/:pageNumber]&[description=1]
ParameterDescription
searchTermsOne or more parts of BAPI function name. Several terms should be separated by a URL encoded space.
pageNumberWhich result page should be returned.
description=1The searchTerms will also be used to search in BAPI function descriptions.

The result is of type JSON with these properties.

PropertyJavaScript TypeDescription
functionListArrayArray of function descriptions
currentPageNumberThe current result page. Result is divided into pages. Each page has up to 25 entries.
totalPagesNumberTotal count of result pages.
errorStringError description

An object in array functionList has these properties.

PropertyJavaScript TypeDescription
FUNCNAMEStringFunction name
GROUPNAMEStringGroup name
APPLStringApplication to which function module is assigned
HOSTStringRemote host (CPIC)
STEXTStringFunction description

Example /sap/functions

Search for customer and get the first 25 functions.

TEXT
curl http://localhost:3000/sap/functions/customer
CODE
{
  "functionList": [
    {
      "FUNCNAME": "/DSD/ME_CR_CUSTOMERCPD",
      "GROUPNAME": "/DSD/ME_SYNCBO",
      "APPL": "",
      "HOST": "",
      "STEXT": ""
    },
// ... cut of functions
    {
      "FUNCNAME": "BAPI_CUSTOMEREXPINV_GETLIST",
      "GROUPNAME": "2144",
      "APPL": "W",
      "HOST": "",
      "STEXT": "Agency Business: BAPI - Determine Detailed Data for Expenses Settlement"
    }
  ],
  "error": null,
  "self_url": "http://localhost:3000/sap/functions/customer",
  "first_url": "http://localhost:3000/sap/functions/customer",
  "last_url": "http://localhost:3000/sap/functions/customer/8"
}

Search for customer and/or get in function name and description. Return the 26th-50th (2nd page) functions.

TEXT
curl 'http://localhost:3000/sap/functions/customer%20get/2?description=1'
CODE
{
  "functionList": [
    {
      "FUNCNAME": "BAPI_CUSTOMEREXPINV_GETLIST",
      "GROUPNAME": "2144",
      "APPL": "W",
      "HOST": "",
      "STEXT": "Agency Business: BAPI - Determine Detailed Data for Expenses Settlement"
    },
// ... cut of functions
    {
      "FUNCNAME": "BAPI_SERVICENOTIFICAT_GETLIST",
      "GROUPNAME": "IWWW",
      "APPL": "I",
      "HOST": "",
      "STEXT": "Select service notifications according to customer or contact person"
    }
  ],
  "error": null,
  "self_url": "http://localhost:3000/sap/functions/customer%20get/2?description=1",
  "next_url": "http://localhost:3000/sap/functions/customer%20get/3?description=1",
  "previous_url": "http://localhost:3000/sap/functions/customer%20get/1?description=1",
  "first_url": "http://localhost:3000/sap/functions/customer%20get?description=1",
  "last_url": "http://localhost:3000/sap/functions/customer%20get/5?description=1"
}

Migrating from version 0.3.2 and below

Change in endpoints:

Old endpointNew endpoint
/sap/exec/:functionName/sap/:functionName
/sap/metadata/:functionName/sap/:functionName/metadata
/sap/findFunction/:searchTerms/sap/functions/:searchTerms

Changes in response:

  • Addition of *_url properties - this should require no changes to the clients
  • The result of a BAPI call has been moved to "result" property of the response.
  • Properties "currentPage" and "totalPages" are no longer present in function search results.
JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.