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
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.
Parameter | Description |
---|---|
functionName | BAPI function name. Slash (/) must be encoded as tilde (~). |
parameter1 | BAPI function parameters with value. The parameters names and types can be explored with /sap/:functionName/metadata. |
callback | JSON-P callback |
Example for executing a BAPI
The BAPI function is called with GET
.
curl http://localhost:3000/sap/ZGETCUSTOMERDETAILS?PARTNERNUMBER=0000008889
The same BAPI function can also be called with POST
.
curl -X POST -H "Content-Type: application/json" -d '{"PARTNERNUMBER":"0000008889"}' 'http://localhost:3000/sap/ZGETCUSTOMERDETAILS'
Response
{
"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:
Value | Description |
---|---|
whitespace | Do not trim whitespaces at all. |
empty-values | Keep simple types that are empty (like empty strings). |
nulls | Keep fields that are NULL . |
empty-objects | Keep objects that do not contain any data. |
Call with GET
:
curl http://localhost:3000/sap/ZGETCUSTOMERDETAILS?PARTNERNUMBER=0000008889&~noclean=whitespace,empty-values
Call with POST
:
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:
Result | Type | Description |
---|---|---|
error | Number | HTTP status code |
message | String | SAP error description |
rfcErrorInfo | Object | Details of the error |
rfcErrorInfo.code | Number | Return value of last function from SAP client |
rfcErrorInfo.group | Number | SAP error group |
rfcErrorInfo.key | String | SAP error key or exception |
rfcErrorInfo.abapMsgClass | String | SAP ABAP message ID, or class |
rfcErrorInfo.abapMsgType | String | SAP ABAP message type, e.g. 'E', 'A' or 'X' |
rfcErrorInfo.abapMsgNumber | String | SAP ABAP message number |
rfcErrorInfo.abapMsgV1 | String | SAP ABAP message details field 1, corresponds to SY-MSGV1 |
rfcErrorInfo.abapMsgV2 | String | SAP ABAP message details field 2, corresponds to SY-MSGV2 |
rfcErrorInfo.abapMsgV3 | String | SAP ABAP message details field 3, corresponds to SY-MSGV3 |
rfcErrorInfo.abapMsgV4 | String | SAP ABAP message details field 4, corresponds to SY-MSGV4 |
self_url | String | URL to this call |
Empty elements of rfcErrorInfo will be suppressed. Find below an example response.
{
"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
GET /sap/:functionName/metadata
Parameter | Description |
---|---|
functionName | BAPI function name. Slash (/) must be encoded as tilde (~). |
The result is of type JSON with these properties.
Name | JavaScript Type | Description |
---|---|---|
functionName | String | Array of function descriptions |
metadata | Object | JSON Schema with additional properties. |
error | String | Error description |
An meta objects has these properties.
Property | JavaScript Type | Description |
---|---|---|
title | String | Name of the object or property. |
type | String | JavaScript type. |
length | Number | Length of a simple type or structure. |
description | String | Description of parameters from SAP. Can be empty. |
sapType | String | Native SAP type. |
sapDirection | String | Input or output parameter. RFC_IMPORT | RFC_EXPORT | RFC_CHANGING | RFC_TABLES |
sapTypeName | String | Name of a structure or name of a structure of a table. |
dbTable | String | Name of the SAP database table |
dbTableField | String | Field of the SAP database table |
label | String | Short description |
Example for getting metadata
Get description of BAPI function STFC_STRING.
curl http://localhost:3000/sap/ZGETCUSTOMERDETAILS/metadata
{
"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
GET /sap/functions/:searchTerms[/:pageNumber]&[description=1]
Parameter | Description |
---|---|
searchTerms | One or more parts of BAPI function name. Several terms should be separated by a URL encoded space. |
pageNumber | Which result page should be returned. |
description=1 | The searchTerms will also be used to search in BAPI function descriptions. |
The result is of type JSON with these properties.
Property | JavaScript Type | Description |
---|---|---|
functionList | Array | Array of function descriptions |
currentPage | Number | The current result page. Result is divided into pages. Each page has up to 25 entries. |
totalPages | Number | Total count of result pages. |
error | String | Error description |
An object in array functionList has these properties.
Property | JavaScript Type | Description |
---|---|---|
FUNCNAME | String | Function name |
GROUPNAME | String | Group name |
APPL | String | Application to which function module is assigned |
HOST | String | Remote host (CPIC) |
STEXT | String | Function description |
Example /sap/functions
Search for customer and get the first 25 functions.
curl http://localhost:3000/sap/functions/customer
{
"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.
curl 'http://localhost:3000/sap/functions/customer%20get/2?description=1'
{
"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 endpoint | New 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.