ideabosque / SAP-B1-RESTful

MIT License
53 stars 20 forks source link

SAP B1 RESTful

=====================

Synopsis

The python flask application is top on the SAP B1 DI API interface to provide the RESTful capability with the following functions.

  1. Show the system information.
  2. Retrieve orders.
  3. Insert orders.
  4. Retrieve contacts of a business partner.
  5. Insert a contact under a business partner.
  6. Retrieve shipments(deliveries).

Architecture

SAP B1 RESTful

Prerequisites

64 bits

  1. Install Python 2.7.12 for Windows 64 bits.

    (https://www.python.org/ftp/python/2.7.13/python-2.7.13.amd64.msi)

  2. Install Python for Windows Extensions (pywin32-220.win-amd64-py2.7.exe)

    (https://sourceforge.net/projects/pywin32/files/pywin32/Build%20220/pywin32-220.win-amd64-py2.7.exe/download)

32 bits

  1. Install Python 2.7.12 for Windows 32 bits.

    (https://www.python.org/ftp/python/2.7.13/python-2.7.13.msi)

  2. Install Python for Windows Extensions (pywin32-220.win-amd64-py2.7.exe)

    (https://sourceforge.net/projects/pywin32/files/pywin32/Build%20220/pywin32-220.win32-py2.7.exe/download)

Installation

  1. Download and decompress the package from the following url.

    https://github.com/ideabosque/SAP-B1-RESTful/zipball/0.0.2

  2. Install the required Python packages by pip.

    pip install -r requirements.txt

Configuration and Launch

Configuration

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.
LANGUAGE Options
  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

Launch the Server

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

API

AuthAPI (JWT)

  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" }'

InfoAPI

  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

CodeAPI

  GET /v1/code?type=ExpnsName

Retrieve codes by type.

Query Parameters:

OrdersAPI

  PUT /v1/orders/fetch?num=1

Retrieve orders by parameters.

Query Parameters:

OrdersAPI

  POST /v1/orders/insert

Insert orders into SAP B1.

Request Parameters for each order:

ContactsAPI

  PUT /v1/contacts/fetch?num=1

Retrieve contacts under a business partner (CardCode) with conditions.

Query Parameters:

ContactsAPI

  POST /v1/contacts/insert

Insert contacts under a business partner (CardCode) with conditions.

Request Parameters for each contact:

OrderCancelAPI

  POST /v1/orders/cancel

Cancel orders by frontend order numbers.

Request Parameters:

ShipmentsAPI

  PUT /v1/shipments/fetch?num=1

Query Parameters:

Related Articles

Feel free to create a GitHub issue or send us an email for support regarding this application.