IBM Sterling products unofficial blog

IBM Sterling B2B Integrator, IBM Sterling Filegateway, Node.js, REST API

Create a Sterling B2B Integrator Trading Partner with a Node.js REST API client

In this example, we create a trading partner using a node.js REST API client.

Node.js and npm should be installed.

This code sample requires node-rest-client.

To install this module run:

$ npm install node-rest-client

Node.js program:

var Client = require('node-rest-client').Client;
//Define URI constants
//TODO: Change
var address = "http://0.0.0.0";
var port = "5074"
var apiUri = "/B2BAPIs/svc/"
var baseUri = address + ":" + port + apiUri;
//Setup HTTP auth info, B2Bi/SFG user with "APIUser" permission
//TODO: Change
var auth_info = {user:"User", password:"password"};
//Create client instance with auth info
client = new Client(auth_info);

//Define required headers
var headers = {
 "Content-Type": "application/json",
 "Accept": "application/json"
};

//The community used here called SFG should Exist 
//Example to create a community is provided here:
//https://sterlingsync.com/sample-node-js-rest-api-client-for-ibm-sterling-b2b-integrator/
var jsonData=
{
 "addressLine1": null,
 "addressLine2": null,
 "appendSuffixToUsername": false,
 "asciiArmor": false,
 "authenticationHost": null,
 "authenticationType": "External",
 "authorizedUserKeyName": null,
 "city": null,
 "code": null,
 "community": "SFG",
 "consumerCdConfiguration": null,
 "consumerFtpConfiguration": null,
 "consumerFtpsConfiguration": null,
 "consumerSshConfiguration": null,
 "consumerWsConfiguration": null,
 "countryOrRegion": null,
 "customProtocolExtensions": null,
 "customProtocolName": null,
 "doesRequireCompressedData": false,
 "doesRequireEncryptedData": false,
 "doesRequireSignedData": false,
 "doesUseSSH": false,
 "emailAddress": "test@email.com",
 "givenName": "test",
 "isInitiatingConsumer": true,
 "isInitiatingProducer": false,
 "isListeningConsumer": false,
 "isListeningProducer": false,
 "keyEnabled": false,
 "mailbox": null,
 "partnerName": "partner1",
 "password": "password",
 "passwordPolicy": null,
 "phone": "00124205505",
 "pollingInterval": null,
 "postalCode": null,
 "producerCdConfiguration": null,
 "producerFtpConfiguration": null,
 "producerFtpsConfiguration": null,
 "producerSshConfiguration": null,
 "publicKeyID": null,
 "remoteFilePattern": null,
 "sessionTimeout": null,
 "stateOrProvince": null,
 "surname": "surname",
 "textMode": false,
 "timeZone": null,
 "useGlobalMailbox": false,
 "username": "partner1"
}


// set content-type header and data as json in args parameter
var args = {
 data: jsonData,
 headers: headers
};


//create a trading Partner
client.post(baseUri + "tradingpartners/",args, function (data, response) {
 if(Buffer.isBuffer(data)){
 data = data.toString('utf8');
}
console.log(data);
});

To run the program: save the code above into a file and run with node.js runtime:

node createPartner.js

The trading partner will be created in IBM Sterling Filegateway:

partnerSFG

Leave a Reply

We’ve detected that you’re using an ad blocker. Please disable it to support our website.