IBM Support

Introduction to the new Sterling B2B Integrator REST API (Part 2)

Technical Blog Post


Abstract

Introduction to the new Sterling B2B Integrator REST API (Part 2)

Body

Sterling B2B Integrator 5.2.6.1 introduced a new REST API interface to provide support for the recently released Partner Engagement Manager (formerly Multi-Enterprise Relationship Management (MRM)). The REST API provides a more efficient mechanism for onboarding trading partners and in the second of this two part blog I will show how to create a simple Java REST Client to onboard a SFTP trading partner and permit them access to upload data to a Mailbox.

Prerequisites

For this example I will use the Apache HttpClient to send and receive the REST API requests and will use the following Eclipse project layout.


image

Coding the application

Firstly we define some common variables to define our REST API Server location and listening port as well as the REST URL's for adding authorized user keys and user entries to the SB2BI server.

// REST API connection details

Stringhost="192.168.0.50";

Stringport="5074";

// REST API credentials

Stringapiuser="apiuser";

Stringpassword="sterling";

// REST API URLs

Stringsvc_userkey="B2BAPIs/svc/sshauthorizeduserkeys/";

Stringsvc_user="B2BAPIs/svc/useraccounts/";

Next we need to add the SSH Public Key that the trading partner will be using to authenticate to the SB2BI Authorized User Key store.

// Create SSH AuthorizedUserKey JSON Object

JSONObjectsshUserKey=newJSONObject();

// Define key name and set key enabled

sshUserKey.put("keyName","sftpuser1");

sshUserKey.put("keyStatusEnabled","TRUE");

// Base64 encode SSH Public key

Stringssh_pub_key="ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCpCnvNTUPtdxYen8hYKMeJYDJU+GEz7pGYPVN3GOSqy3TOXX/zQ/E6m5B9+8TAfhXL4ZlKtX/V9O1KuQ39RB <.....> 1t9+H3n2sLzMM1 martinwarnes@Martins-MacBook-Pro.local";

Base64.Encoderencoder= Base64.getEncoder();

sshUserKey.put("keyData",encoder.encodeToString(ssh_pub_key.getBytes(StandardCharsets.UTF_8) ));

Execute the REST API POST request to add the SSH Public Key to the SB2BI store.

// Add SSH AuthorizedUserKey to the SB2BI Store

StringsshUserKeyResponse= post(host,port,apiuser,password,svc_userkey,sshUserKey);

HTTP 201 indicates the post was successful

POST http://192.168.0.50:5074/B2BAPIs/svc/sshauthorizeduserkeys/ HTTP/1.1

HTTP Response: 201

{

"Location": "http://192.168.0.50:5074/B2BAPIs/svc/sshauthorizeduserkeys/sftpuser1"

}

We then need to define the specific Permissions the trading partner will need to login to his Mailbox and access the required path. Each permission is defined as a separate JSON object within a JSONArray.

// Create Array of permissions required to access the SFTP Inbox

JSONArraypermissions=newJSONArray();

// User requires access to Mailbox login ...

JSONObjectpermission=newJSONObject();

permission.put("name","Mailbox Login Without Virtual Root Permission");

permissions.put(permission);

// .. and also access to the specific mailbox

permission=newJSONObject();

permission.put("name","/SFTP Inbox Mailbox");

permissions.put(permission);

The trading partner will be required to access the SFTP servere adapter using a public key. As SB2BI permits a user to authenticate with multiple keys, each key is added as a separate JSONObject within a JSONArray.

// Create Array of available AuthorizedUserKeys

JSONArrayuserKeys=newJSONArray();

// Add the name of each key previously added that

// the user is permitte to authenticate with

JSONObjectuserKey=newJSONObject();

userKey.put("name","sftpuser1");

userKeys.put(userKey);

Finally we add the user to the SB2BI user store. Since the trading partner in this example will be using public key authentication a password is still required.

// Create User

JSONObjectuser=newJSONObject();

// Required parameters

user.put("authenticationType","local");

user.put("givenName","Martin");

user.put("surname","Warnes");

user.put("userId","sftpuser1");

user.put("password","sterling");

// Optional parameters

// Add permissions and user keys

user.put("permissions",permissions);

user.put("authorizedUserKeys",userKeys);

Execute the REST API POST request to add the SSH Public Key to the SB2BI store.

HTTP 201 indicates the post was successful and the JSON "Location" parameter displays the URL for the user account that can be used for other REST API services, e.g UPDATE or DELETE

// Add user to SB2BI User store

StringuserResponse= post(host,port,apiuser,password,svc_user,user);

POST http://192.168.0.50:5074/B2BAPIs/svc/useraccounts/ HTTP/1.1

HTTP Response: 201

{

"Location": "http://192.168.0.50:5074/B2BAPIs/svc/useraccounts/sftpuser1"

}

A check of the SI Stores shows the Public Key and User account have been created successfully.

image



image

To conclude this blog series the following example shows that our trading partner has been onboarded and is able to upload data to their mailbox.

Martins-MacBook-Pro:~ martinwarnes$ sftp -i .ssh/id_rsa -P 10022 sftpuser1@192.168.0.50

SSH Server supporting SFTP and SCP

Connected to 192.168.0.50.

sftp> ls

SFTP Inbox

sftp> cd SFTP\ Inbox/

sftp> put test.txt

Uploading test.txt to /SFTP Inbox/test.txt

test.txt 100% 1432 1.4KB/s 00:00

sftp>

References

Project code

Introduction to the new Sterling B2B Integrator REST API (Part 1)

Introduction to the new Sterling B2B Integrator REST API (Part 2)

http://www-03.ibm.com/software/products/en/partner-engagement-manager

[{"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

ibm11121601