Test B2B

A key strength of the API Architecture is that APIs can be called in a variety of ways, across languages and architectures.

You can test B2B in a number of ways. Several are described below.

Use 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 Resource = PartnerOrder:

{
"CustomerNumber": "VINET",
"Items": [
  {
    "ProductNumber": 16,
    "Quantity": 1
  },
  {
    "ProductNumber": 7,
    "Quantity": 2
  },
  {
    "ProductNumber": 14,
    "Quantity": 3
  },
  {
    "ProductNumber": 10,
    "Quantity": 4
  },
  {
    "ProductNumber": 13,
    "Quantity": 5
  } 
]
}

Use 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 "statusCode":201 response is expected.

Use Command Line (NodeJS)

The following example uses MAC shell. (For Windows) Precede the command with 'call lac' (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.

Use NodeJS

Prerequisite: Node is installed.

These are automatically performed in the standard Jetty install. You can repeat them as follows.

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

On Windows, issue the following commands:

post.cmd
verify.cmd

Use Python and PHP

Optional Prerequisite: Python and/or PHP are installed.

The verify scripts above 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.

Use Data Explorer

Add a new order details row entry using Data Explorer.

  1. Click 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', clicking Search, and then clicking 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 how to test the API by adding a new order details row entry using Data Explorer:
To verify:
  • Use the Rest Lab or Data Explorer on the Pavlov API to verify a row exists in the PartnerOrders table.
  • Check the logs for the update above to ensure that the rules adjust the order and customer values.