Test B2B

You can test the Business to Business (B2B) API using the following approaches:

  • Test using the REST Lab.
  • Test using cURL.
  • Test using the command line.
  • Test using Node.js.
  • Test using Python and PHP.
  • Test using Data Explorer.


Test using the REST Lab

In the B2B API, use the REST Lab to post this to the Resource PartnerOrder: for customer named Vins et alcools ChevalierSelect End Point Type = Resource, and ResourcePartnerOrder:

{
  "CustomerNumber":"VINET",
  "Items":[  
      {  
        "Product":{  
            "@metadata":{  
              "action":"LOOKUP",
              "key":"ProductName"
            },
            "ProductName":"Pavlova"
        },
        "Quantity":1
      },
      {  
        "Product":{  
            "@metadata":{  
              "action":"LOOKUP",
              "key":"ProductName"
            },
            "ProductName":"Uncle Bob's Organic Dried Pears"
        },
        "Quantity":2
      },
      {  
        "Product":{  
            "@metadata":{  
              "action":"LOOKUP",
              "key":"ProductName"
            },
            "ProductName":"Tofu"
        },
        "Quantity":3
      },
      {  
        "Product":{  
            "@metadata":{  
              "action":"LOOKUP",
              "key":"ProductName"
            },
            "ProductName":"Ikura"
        },
        "Quantity":4
      },
      {  
        "Product":{  
            "@metadata":{  
              "action":"LOOKUP",
              "key":"ProductName"
            },
            "ProductName":"Konbu"
        },
        "Quantity":5
      },
      {  
        "Product":{  
            "@metadata":{  
              "action":"LOOKUP",
              "key":"ProductName"
            },
            "ProductName":"Alice Mutton"
        },
        "Quantity":1
      }
  ],
  "Shipper":{  
      "@metadata":{  
        "action":"LOOKUP",
        "key":"CompanyName"
      },
      "CompanyName":"Federal Shipping"
  }
}

The following image shows the steps to test the B2B API in the REST Lab:

Warning: credit limit check

Note: Repeated execution of this will eventually violate the credit limit check. That is an expected condition. You can increase the credit limit using Data Explorer on the Vins et alcools Chevalier (Customer ID: VINET) customer.

Test using cURL

From a command window, simulate the receipt of an order from a remote partner by issuing the following command:

curl -H "Authorization: CALiveAPICreator Bzn8jVyfOTiIpW6UQCgy:1" -H "Content-type: application/json" -d '{"CustomerNumber": "VINET","Items": [{"ProductNumber": 16,"Quantity": 1}]}' -X POST http://localhost:8080/rest/default/b2bderbynw/v1/PartnerOrder

On some versions of cURL (for example, on some Windows versions), escape quote the command by issuing the following command:

curl -H "Authorization: CALiveAPICreator Bzn8jVyfOTiIpW6UQCgy:1" -H "Content-type: application/json" -d "{\"CustomerNumber\": \"VINET\",\"Items\": [{\"ProductNumber\": 16,\"Quantity\": 1}]}" -X POST "http://localhost:8080/rest/default/b2bderbynw/v1/PartnerOrder"

The following response is expected:

"statusCode":201

Test B2B using the Command Line (Node.JS)

The following test command examples use MAC shell. For Windows, precede the command with call lac (lac is an alias for liveapicreator):

#! /bin/bash
#login to 2 different servers (For WAR change to localhost:8080/APIServer)
liveapicreator login -u demo -p Password1 http://localhost:8080/rest/default/b2bderbynw/v1 -a b2b
liveapicreator login -u demo -p Password1 http://localhost:8080/rest/default/b2bderbypavlov/v1 -a pavlov
liveapicreator status
#Show current state
liveapicreator use pavlov
liveapicreator get main:PARTNERORDERS


#switch projects
liveapicreator use b2b


#Post an order to b2b Partner
liveapicreator post PartnerOrder -j '{ "CustomerNumber": "VINET","Items": [ {"ProductNumber": 16, "Quantity": 1 },{"ProductNumber": 7,"Quantity": 2},{"ProductNumber": 14,"Quantity": 3},{"ProductNumber": 10,"Quantity": 4},{"ProductNumber": 13,"Quantity": 5} ] }'


#Switch Projects and show new partner orders
liveapicreator use pavlov
liveapicreator get main:PARTNERORDERS
lac use b2b
lac get nw:Orders -f "equal(OrderID: 2000, AmountTotal: 301.20)" --format json

Verify the following:

  • The script runs without error.
  • The created order has an AmountTotal of 301.20, and a discountedAmount of 298.19.
  • The last two lines return data.

Test using Node.js

Prerequisite: Node is installed.

These commands are automatically performed in the self-contained, single-user version of Live API Creator, which is a demonstration package and is based on Jetty. You can repeat them as follows.

  1. cd to your b2b folder.
  2. Issue the following commands:

(On Mac/Linux)

sh post.sh
sh verify.sh

(On Windows)

post.cmd
verify.cmd

Test using Python and PHP

Optional Prerequisite: Python and/or PHP are installed.

The previous verify scripts also run Python and PHP scripts. These are used (in the post script), but not required by the install scripts. You can explore the code from the b2b/scs/projects/test directory.

Test using Data Explorer

Test the API by adding a new order details row entry using Data Explorer.

  1. Go to Execute, Data Explorer.
  2. Select the Orders table.
  3. Click an order from the table and then click Insert in the Order Details grid.
  4. Select the product by entering product name 'Pav', click Search, and then click Select for the Pavlova row in the list. The dialog closes.
  5. Click Save. The new order details row is inserted into the Orders table.
The following image illustrates these steps:
To verify:
  • Verify a row exists in the PartnerOrders table using the REST Lab or Data Explorer on the Pavlov API.
  • Ensure that the rules adjust the order and customer values by checking the logs for the previous update.