=====================
The python flask application is top on the SAP B1 DI API interface to provide the RESTful capability with the following functions.
Install Python 2.7.12 for Windows 64 bits.
(https://www.python.org/ftp/python/2.7.13/python-2.7.13.amd64.msi)
Install Python for Windows Extensions (pywin32-220.win-amd64-py2.7.exe)
Install Python 2.7.12 for Windows 32 bits.
(https://www.python.org/ftp/python/2.7.13/python-2.7.13.msi)
Install Python for Windows Extensions (pywin32-220.win-amd64-py2.7.exe)
Download and decompress the package from the following url.
Install the required Python packages by pip.
pip install -r requirements.txt
We could configure the service at "flask/config.py".
LOGGING_LOCATION = 'sapb1adaptor.log' # The RESTful log file.
LOGGING_LEVEL = logging.INFO # The log level.
LOGGING_FORMAT = '%(asctime)s %(levelname)-8s %(message)s' # The log format.
DIAPI = 'SAPbobsCOM90' # The DI version.
SERVER = 'SAP91' # SAP B1 server name.
LANGUAGE = 'ln_English'
DBSERVERTYPE = 'dst_MSSQL2014' # The MS SQL Server version.
DBUSERNAME = 'sa' # Database username.
DBPASSWORD = 'XXXXXXXX' # Database password.
COMPANYDB = 'SBODEMOUS' # Database name.
B1USERNAME = 'manager' # B1 username.
B1PASSWORD = 'XXXXXXXX' # B1 password.
ln_Arabic =32 # from enum BoSuppLangs
ln_Chinese =15 # from enum BoSuppLangs
ln_Czech_Cz =26 # from enum BoSuppLangs
ln_Danish =11 # from enum BoSuppLangs
ln_Dutch =16 # from enum BoSuppLangs
ln_English =3 # from enum BoSuppLangs
ln_English_Cy =21 # from enum BoSuppLangs
ln_English_Gb =8 # from enum BoSuppLangs
ln_English_Sg =6 # from enum BoSuppLangs
ln_Finnish =17 # from enum BoSuppLangs
ln_French =22 # from enum BoSuppLangs
ln_German =9 # from enum BoSuppLangs
ln_Greek =18 # from enum BoSuppLangs
ln_Hebrew =1 # from enum BoSuppLangs
ln_Hungarian =14 # from enum BoSuppLangs
ln_Italian =13 # from enum BoSuppLangs
ln_Japanese_Jp =30 # from enum BoSuppLangs
ln_Korean_Kr =28 # from enum BoSuppLangs
ln_Norwegian =12 # from enum BoSuppLangs
ln_Polish =5 # from enum BoSuppLangs
ln_Portuguese =19 # from enum BoSuppLangs
ln_Portuguese_Br =29 # from enum BoSuppLangs
ln_Russian =24 # from enum BoSuppLangs
ln_Serbian =10 # from enum BoSuppLangs
ln_Slovak_Sk =27 # from enum BoSuppLangs
ln_Spanish =23 # from enum BoSuppLangs
ln_Spanish_Ar =2 # from enum BoSuppLangs
ln_Spanish_La =25 # from enum BoSuppLangs
ln_Spanish_Pa =7 # from enum BoSuppLangs
ln_Swedish =20 # from enum BoSuppLangs
ln_TrdtnlChinese_Hk =35 # from enum BoSuppLangs
ln_Turkish_Tr =31 # from enum BoSuppLangs
You could launch the service by the following command at the command prompt.
python flask/manage.py runserver -h 0.0.0.0 -p 5000
-p 5000 : Bind the service with port 5000. Please check the port of Windows Firewall opened for the port.
You could also launch the service by cherrypy. The setting could be configured at flask/server.py.
python flask/server.py
POST /v1/auth
Return the JWT token. You have to request the JWT token first before sending the other API calls.
Example response body:
{
"access_token": "XXXXXXXXXXXXXXXXXXXXXXXXXXXX"
}
Example script by curl:
curl -X POST http://192.168.44.151:5000/auth -H 'content-type: application/json' \ -d '{ "username": "user1", "password": "abcxyz" }'
GET /v1/info
Return the information of the system.
Example response body:
{
"diapi": "SAPbobsCOM90",
"company_db": "SBODEMOUS",
"company_name": "OEC Computers",
"server": "SAPB191"
}
Example script by curl:
curl -H 'authorization: JWT XXXXXXXXXXXXXXXXXXXXXXXXXXXX' -X GET -H 'Content-Type: application/json' http://192.168.44.151:5000/v1/info
GET /v1/code?type=ExpnsName
Retrieve codes by type.
Query Parameters:
type(ExpnsName|TrnspName|PayMethCod|TaxCode): The amount of the records will be contained in the result.
Example response body:
[
"Freight",
"Insurance"
]
Example script by curl:
curl -H 'authorization: JWT XXXXXXXXXXXXXXXXXXXXXXXXXXXX' -X GET -H 'Content-Type: application/json' http://192.168.44.151:5000/v1/code?type=ExpnsName
PUT /v1/orders/fetch?num=1
Retrieve orders by parameters.
Query Parameters:
num: The amount of the records will be contained in the result.
Request Parameters:
params: The query condition parameters. key: The column name.
Example request body:
{
"columns": ["DocNum", "CardName", "DocDate", "Address", "Address2"],
"params": {
"DocDate": {
"op": ">=",
"value": "2016-01-01"
}
}
}
Example response body:
[
{
"DocDate": "2016-06-20 00:00:00",
"Address2": "3921 W Collins St\r\r3921 W Collins St FL 33607\rUSA",
"CardName": "Werner Richter",
"DocNum": "491",
"Address": "3921 W Collins St\r\rTampa FL 33607\rUSA"
}
]
Example script by curl:
curl -H 'authorization: JWT XXXXXXXXXXXXXXXXXXXXXXXXXXXX' -X PUT -H 'Content-Type: application/json' http://192.168.44.151:5000/v1/orders/fetch?num=1 -d '{"columns": ["DocNum", "CardName", "DocDate", "Address", "Address2"], "params": {"DocDate": {"op": ">=","value": "2016-01-01"}}}'
POST /v1/orders/insert
Insert orders into SAP B1.
Request Parameters for each order:
items: item[] The line item in the order.
Example request body:
[
{
"doc_due_date": "2016-12-12",
"card_code": "C20000",
"expenses_freightname": "Freight",
"expenses_linetotal": "2",
"expenses_taxcode": "Exempt",
"transport_name": "Fedex ON",
"payment_method": "Incoming BT 02",
"fe_order_id": "00000002",
"billto_firstname": "John",
"billto_lastname": "Smith",
"billto_email": "john.smith@xyz.net",
"billto_companyname": "",
"billto_city": "Los Angeles",
"billto_country": "US",
"billto_county": "",
"billto_state": "CA",
"billto_address": "3650 McClintock Avenue",
"billto_zipcode": "90089",
"billto_telephone": "(213) 740-8674",
"shipto_firstname": "John",
"shipto_lastname": "Smith",
"shipto_companyname": "",
"shipto_city": "Los Angeles",
"shipto_country": "US",
"shipto_county": "",
"shipto_state": "CA",
"shipto_address": "3650 McClintock Avenue",
"shipto_zipcode": "90089",
"shipto_telephone": "(213) 740-8674",
"items": [
{
"itemcode": "I00001",
"quantity": "10",
"price": "12",
"taxcode": "CA",
"linetotal": "120"
}
]
},
]
Example response body:
[
{
"doc_due_date": "2016-12-12",
"shipto_telephone": "(213) 740-8674",
"payment_method": "Incoming BT 02",
"shipto_address": "3650 McClintock Avenue",
"fe_order_id": "00000002",
"shipto_city": "Los Angeles",
"transport_name": "Fedex ON",
"billto_companyname": "",
"shipto_state": "CA",
"shipto_firstname": "John",
"tx_status": "S",
"shipto_zipcode": "90089",
"bo_order_id": "536",
"expenses_taxcode": "Exempt",
"shipto_lastname": "Smith",
"expenses_linetotal": "2",
"billto_email": "john.smith@xyz.net",
"card_code": "C20000",
"expenses_freightname": "Freight",
"billto_country": "US",
"billto_state": "CA",
"billto_lastname": "Smith",
"billto_zipcode": "90089",
"billto_address": "3650 McClintock Avenue",
"billto_county": "",
"items": [
{
"linetotal": "120",
"itemcode": "I00001",
"taxcode": "CA",
"price": "12",
"quantity": "10"
}
],
"shipto_county": "",
"shipto_companyname": "",
"shipto_country": "US",
"billto_city": "Los Angeles",
"billto_telephone": "(213) 740-8674",
"billto_firstname": "John"
}
]
Example script by curl:
curl -H 'authorization: JWT XXXXXXXXXXXXXXXXXXXXXXXXXXXX' -X POST -H 'Content-Type: application/json' http://192.168.44.151:5000/v1/orders/insert -d '[{"doc_due_date": "2016-12-12", "card_code": "C20000", "expenses_freightname": "Freight", "expenses_linetotal": "2", "expenses_taxcode": "Exempt", "transport_name": "Fedex ON", "payment_method": "Incoming BT 02", "fe_order_id": "00000002", "billto_firstname": "John", "billto_lastname": "Smith", "billto_email": "john.smith@xyz.net", "billto_companyname": "", "billto_city": "Los Angeles", "billto_country": "US", "billto_county": "", "billto_state": "CA", "billto_address": "3650 McClintock Avenue", "billto_zipcode": "90089", "billto_telephone": "(213) 740-8674", "shipto_firstname": "John", "shipto_lastname": "Smith", "shipto_companyname": "", "shipto_city": "Los Angeles", "shipto_country": "US", "shipto_county": "", "shipto_state": "CA", "shipto_address": "3650 McClintock Avenue", "shipto_zipcode": "90089", "shipto_telephone": "(213) 740-8674", "items": [{"itemcode": "I00001", "quantity": "10", "price": "12", "taxcode": "CA", "linetotal": "120"}]}]'
PUT /v1/contacts/fetch?num=1
Retrieve contacts under a business partner (CardCode) with conditions.
Query Parameters:
num: The amount of the records will be contained in the result.
Request Parameters:
contact(required): contact{} The query condition parameters.
Example request body:
{
"columns": ["cntctcode", "Name"],
"card_code": "C20000",
"contact": {
"FirstName": "John",
"LastName": "Smith",
"E_MailL": "john.smith@xyz.net"
}
}
Example response body:
[
{
"cntctcode": "60",
"Name": "John Smith 1476166090.01"
}
]
Example script by curl:
curl -H 'authorization: JWT XXXXXXXXXXXXXXXXXXXXXXXXXXXX' -X PUT -H 'Content-Type: application/json' http://192.168.44.151:5000/v1/contacts/fetch?num=1 -d '{"columns": ["cntctcode", "Name"], "card_code": "C20000", "contact": {"FirstName": "John", "LastName": "Smith", "E_MailL": "john.smith@xyz.net"}}'
POST /v1/contacts/insert
Insert contacts under a business partner (CardCode) with conditions.
Request Parameters for each contact:
contacts(required)[]:
Example request body:
[
{
"card_code": "C20000",
"contacts": [
{
"FirstName": "Joe",
"LastName": "Brown",
"Tel1": "(213) 345-6789",
"E_MailL": "joe.brown@xzy.net",
"Address": "1st st. Los Angles, CA 90089"
}
]
}
]
Example response body:
[
{
"Tel1": "(213) 345-6789",
"contact_code": "63",
"FirstName": "Joe1",
"LastName": "Brown",
"E_MailL": "joe.brown@xzy.net",
"Address": "1st st. Los Angles, CA 90089"
}
]
Example script by curl:
curl -H 'authorization: JWT XXXXXXXXXXXXXXXXXXXXXXXXXXXX' -X POST -H 'Content-Type: application/json' http://192.168.44.151:5000/v1/contacts/insert -d '{"card_code": "C20000", "contacts": [{"FirstName": "Joe1", "LastName": "Brown", "Tel1": "(213) 345-6789", "E_MailL": "joe.brown@xzy.net", "Address": "1st st. Los Angles, CA 90089"}]}'
POST /v1/orders/cancel
Cancel orders by frontend order numbers.
Request Parameters:
fe_order_id: Front end order id.
Example request body:
[
{
"fe_order_id": "000000011"
}
]
Example response body:
[
{
"tx_status": "X",
"fe_order_id": "000000011",
"bo_order_id": "540"
}
]
Example script by curl:
curl -H 'authorization: JWT XXXXXXXXXXXXXXXXXXXXXXXXXXXX' -X POST -H 'Content-Type: application/json' http://192.168.44.151:5000/v1/orders/cancel -d '[{"fe_order_id": "000000011"}]'
PUT /v1/shipments/fetch?num=1
Query Parameters:
num: The amount of the records will be contained in the result.
Request Parameters:
itemColumns(optional):
Example request body:
{
"columns": [ "DocDueDate", "CardName"],
"params": {
"DocDate": {
"op": ">=",
"value": "2015-01-01"
}
},
"itemcolumns": ["BaseDocNum", "Price", "ShipDate"]
}
Example response body:
[
{
"items": [
{
"ShipDate": "2015-06-19 00:00:00",
"BaseDocNum": "452",
"Price": "140.000000"
},
{
"ShipDate": "2015-06-19 00:00:00",
"BaseDocNum": "452",
"Price": "0.000000"
}
],
"DocDueDate": "2015-07-20 00:00:00",
"DocEntry": "364",
"CardName": "Maxi-Teq"
}
]
Example script by curl:
curl -H 'authorization: JWT XXXXXXXXXXXXXXXXXXXXXXXXXXXX' -X PUT -H 'Content-Type: application/json' http://192.168.44.151:5000/v1/shipments/fetch?num=1 -d '{"columns": [ "DocDueDate", "CardName"], "params": {"DocDate": {"op": ">=", "value": "2015-01-01"}}, "itemcolumns": ["BaseDocNum", "Price", "ShipDate"]}'
Feel free to create a GitHub issue or send us an email for support regarding this application.