IBM Support

How to read from the new B2Bi REST API

Technical Blog Post


Abstract

How to read from the new B2Bi REST API

Body

How to access the B2Bi REST API

The new REST APIs in IBM Sterling B2B Integrator (ISBI) allow to access various types of configuration objects inside the product. The REST API is provided by a software running on top of IBM Websphere Liberty Server and is directly accessing the data structures inside ISBI. The data structures being exchanged are in JSON format to allow easy consumability in web applications. Operations like read and write are translated to HTTP GET and HTTP POST operations.

Building blocks of the sample client

To give you and idea we will show a small client application in this blog entry. The programming language go https://golang.org/ was used to create the sample client. It can be used to retrieve a piece of configuration data from the B2Bi REST API which is then stored locally in a file. In this example we decided to load a codelist from the server and to store it in a spreadsheet file.

The sample code has just a few building blocks:

  • The first part of the code
    • Imports some dependencies
    • Defines the data structure that is returned from the REST service
    • Reads parameters like connection info, credentials, name and version of the codelist.
  • After this a REST Client lib call is used to open a connection, authenticate and download the data into a buffer resp.

    resp, err := resty.R(). SetBasicAuth(username, pword). Get(url)

    Please be reminded that this is only a sample code. It is using HTTP BASIC Authentication over plain HTTP. You might get a warning depending on your runtime environment.

  • Then the JSON parser is used to convert the buffer into structured data

    err2 := json.Unmarshal([]byte(resp.Body()), &clVar)

  • Finally the structured data will be written to a file in your filesystem

    In this example we use a library to write the clVar struct to a spreadsheet file.

The sample client

The sample client has dependencies on 2 other libraries, one for executing the REST call, the other one to convert the result into a XLS file. You have to install the 2 dependencies with

  • go get github.com/go-resty/resty
  • go get github.com/tealeg/xlsx

Then you can go ahead and clone/fork/download the sample client from https://github.com/IBM-Commerce-B2B-Partner/b2biRestApiClient and play with it.

[{"Business Unit":{"code":"BU059","label":"IBM Software w\/o TPS"},"Product":{"code":"SS3JSW","label":"IBM Sterling B2B Integrator"},"Component":"","Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"","Edition":"","Line of Business":{"code":"LOB59","label":"Sustainability Software"}}]

UID

ibm11121349