IBM Support

REST API Java client for B2BAPIs - How to make JSON input for complex data types

Technical Blog Post


Abstract

REST API Java client for B2BAPIs - How to make JSON input for complex data types

Body

If you are looking to implement Java based REST API Client to invoke B2B APIs, my previous articles would help you. These include working java (REST API Client) classes for 2 of the APIs.

REST API Proof Of Concept - Automate Sterling FileGateway Community and Trading Partner creation 

REST API Client - upload message to Sterling B2B Integrator Mailbox 

 

These articles covered how to generate JSON input string for primitive data type based parameters. I never used complex data types in previous articles as they were not needed there. I am going to provide sample code here for complex data types such as Collection Set.

 

Like previous articles, this one too targeted for Java coders.

 

B2BAPIs/svc/sterlingconnectdirectnetmapxrefs/

image

 

{
  "netMapName": "KK.netmap",
  "nodes": [
    {
      "nodeName": "NODE1"
    },
    {
      "nodeName": "NODE2"
    },
    {
      "nodeName": "NODE3"
    }

  ]
}

 

                                        net.sf.json.JSONArray jsonArray = new net.sf.json.JSONArray();
                                        net.sf.json.JSONObject obj = new net.sf.json.JSONObject();
                                        obj.put("nodeName", "NODE1");

                                        jsonArray.add(obj);

                                        obj = new net.sf.json.JSONObject();
                                        obj.put("nodeName", "NODE2");

                                        jsonArray.add(obj);

                                        obj = new net.sf.json.JSONObject();
                                        obj.put("nodeName", "NODE3");

                                        jsonArray.add(obj);
 

                                       JSONObject nodeJson = new JSONObject();

                                       nodeJson.put("netMapName", netmap);
                                       nodeJson.put("nodes", nodes);

 

B2BAPIs/svc/codelists/

image

 

{
  "codeListName": "IBM.CL",
  "codes": [

     {
      "description": "sample1",
      "id": null,
      "receiverCode": "reccode1",
      "senderCode": "sendcode1",
      "text1": "new1",
      "text2": "new2",
      "text3": "new3",
      "text4": "new4",
      "text5": "new5",
      "text6": "new6",
      "text7": "new7",
      "text8": "new8",
      "text9": "new9"
    },

    {
      "description": "sample2",
      "id": null,
      "receiverCode": "reccode2",
      "senderCode": "sendcode2",
      "text1": "str1",
      "text2": "str2",
      "text3": "str3",
      "text4": "str4",
      "text5": "str5",
      "text6": "str6",
      "text7": "str7",
      "text8": "str8",
      "text9": "str9"
    }

  ],
  "comments": "testing",
  "listStatus": null,
  "makeDefault": false,
  "receiverIdentity": null,
  "senderIdentity": null
}

            JSONArray addcodes = new JSONArray();


            JSONObject newcode = new JSONObject();
            newcode.put("receiverCode","reccode1");
            newcode.put("senderCode", "sendcode1");
            newcode.put("description", "sample1");
            newcode.put("id", null);
            newcode.put("text1", "new1");
            newcode.put("text2", "new2");
            newcode.put("text3", "new3");
            newcode.put("text4", "new4");
            newcode.put("text5", "new5");
            newcode.put("text6", "new6");
            newcode.put("text7", "new7");
            newcode.put("text8", "new8");

            newcode.put("text9", "new9");

           //Repeat same for 2nd list. I am not doing it here
           

             addcodes.add(newcode);

           

            JSONObject codelistJson = new JSONObject();

            codelistJson.put("codeListName", "IBM.CL");

            codelistJson.put("codes", addcodes);

            codelistJson.put("comments", "testing");

 

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

ibm11120533