Giter Club home page Giter Club logo

node-sapb1's Introduction

SAPb1

A simple and easy to use library for SAP Business One Service Layer API.

Installation

npm install node-sapb1

Usage

Create an object to store your SAP Business One Service Layer configuration details. If you are using an https connection, you can attach the certificate by specifying the ca property of the configuration object as shown below.

var config = {
    host : 'http(s): ip or hostname',
    port : 50000,
    version : 2,
    username : 'SAP usernmae',
    password : 'SAP password',
    company : 'Company name',
    ca : fs.readFileSync('/path/to/certificate.crt')
}

Login to the Service Layer to obtain a session as shown below.

const SAPb1 = require('node-sapb1');

SAPb1.createSession(config, sap => {
    // Success 
}, (error, type) => {
    // Error
    // type = 1, Connection errors
    // type = 2, SAP response errors.
});

If the connection is successful, the success callback function is called and passed a new instance of SAPb1 as the callback argument. The SAPb1 object provides a resource(name) method which returns a new instance of Resource with the specified name. Using this Resource object you can perform CRUD actions.

Querying A Service

The following code sample demonstrates how to query a Sales Order service and return a JSON object with multiple entries using the queryBuilder() method. The queryBuilder() method returns a new instance of Query.

SAPb1.createSession(config ,  sap => {
    sap.resource('Orders')
        .queryBuilder()
        .select('DocNum, DocEntry, CardCode, DocumentLines')
        .orderBy('DocNum', 'asc')
        .findAll(data => {
            console.log(data);
        }, (error, type) => {
            console.log(error, type);
        });
}, (error, type) =>{
    console.log(error, type);
});

To return a single entry, use the find(id, success, error) method as shown below.

SAPb1.createSession(config ,  sap => {
    sap.resource('Orders')
        .queryBuilder()
        .select('DocNum, DocEntry, CardCode, DocumentLines')
        .orderBy('DocNum', 'asc')
        .find(1474, data => {
            console.log(data);
        }, (error, type) => {
            console.log(error, type);
        });
}, (error, type) =>{
    console.log(error, type);
});

Depending on the service, id may be a numeric value or a string.

Creating A Service

The following code sample shows how to create a new Sales Order using the create() method of the Resource object.

SAPb1.createSession(config ,  sap => {
    sap.resource('Orders').create({
        CardCode: "BP Card Code",
        DocDueDate: "Doc due date",
        DocumentLines: [
            {
                ItemCode: "Item Code",
                Quantity: "200",
            }
        ]
    }, (data) => {
        console.log(data);
    }, (error, type) => {
        console.log(error, type);
    });
}, (error, type) =>{
    console.log(error, type);
});

You must provide any User Defined Fields that are required in the create object. If successful, the newly created Sales Order will be returned as a JSON object.

Updating A Service

The following code sample demonstrates how to update a service using the update() method of the Resource object.

SAPb1.createSession(config ,  sap => {
    sap.resource('Orders').update(19165, {
        Comments: "This is a comment",
    }, (data) => {
        console.log(data);
    }, (error, type) => {
        console.log(error, type);
    });
}, (error, type) =>{
    console.log(error, type);
});

Note that the first argument to the update() method is the id of the entity to update. In the case of a Sales Order the id is the DocEntry field. If the update is successful and empty JSON object is returned.

You can find more examples and the full documentation at https://syedhussim.com/sap-b1/node-sapb1-library-documentation-v1.html

Please report any issues on the github repository https://github.com/syedhussim/node-sapb1/issues

node-sapb1's People

Contributors

syedhussim avatar juliuscosmoromeo avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.