Other B2B API Sample Test Scripts

You can test the Business to Business (B2B) B2B Northwind API using programs such as the REST Lab, Data Explorer, scripts such as cURL, and the command-line interface (CLI), or programs such as Node.js, Python, and PHP. 
lac42
You can test the Business to Business (B2B) 
B2B Northwind
 API using programs such as the REST Lab, Data Explorer, scripts such as cURL, and the command-line interface (CLI), or programs such as Node.js, Python, and PHP. 
In this article:
Test the B2B Northwind API using the REST Lab
Test the 
B2B Northwind
 API in the REST Lab by executing a POST to the 
PartnerOrder:
 resource for 
Vins et alcools Chevalier
 customer (Customer ID: 
VINET
).
Follow these steps:
  1. In API Creator, open the 
    B2B Northwind
     API.
  2. In the Execute section, click 
    REST Lab
    .
  3. Select 
    Resource
     as the endpoint on which you want to operate and 
    PartnerOrder
     as the resource.
  4. Enter the following code into the Request Body:
        {
            "CustomerNumber": "VINET",
            "Items": [{
                "Product": {
                    "ProductName": "Pavlova"
                },
                "Quantity": 1
            }, {
                "Product": {
                    "ProductName": "Uncle Bob's Organic Dried Pears"
                },
                "Quantity": 2
            }, {
                "Product": {
                    "ProductName": "Tofu"
                },
                "Quantity": 3
            }, {
                "Product": {
                    "ProductName": "Ikura"
                },
                "Quantity": 4
            }, {
                "Product": {
                    "ProductName": "Konbu"
                },
                "Quantity": 5
            }, {
                "Product": {
                    "ProductName": "Alice Mutton"
                },
                "Quantity": 1
            }],
            "Shipper": {
                "CompanyName": "Federal Shipping"
            }
        };
  5. Click 
    POST
    .
    Repeated execution of POST eventually violates the credit limit check. That is an expected condition. You can increase the credit limit on the 
    Vins et alcools Chevalier
     customer (Customer ID: 
    VINET
    ) using Data Explorer.
You have tested the 
B2B Northwind
 API in the REST Lab.
Test the B2B Northwind API using cURL
From a command window, simulate the receipt of an order from a remote partner by issuing the following cURL 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
With some versions of cURL (for example, on some Windows versions), you must escape quote the command, for example:
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
You have tested the 
B2B Northwind
 API using cURL.
Test the B2B Northwind API using the Command Line Interface
Prerequisite: 
You have installed the 
lac
 (or the alias 
liveapicreator
) command-line interface utility.
For more information on how to install the command-line interface utility, see Install and Use the Command Line Utilities for DevOps.
Test the 
B2B Northwind
 API using the
CA Live API Creator
 CLI (using the executable
lac
(or the alias
liveapicreator
)):
The following test command examples use MAC shell. For Windows, precede the command with the following entry:
call lac
#! /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/b2bpavlovderby/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.
You have tested the 
B2B Northwind
 API using the CLI.
Test the B2B Northwing API using Data Explorer
Test the 
B2B Northwind
 API by adding a new order details row entry using Data Explorer.
Follow these steps:
  1. In API Creator, with the 
    B2B Northwind
     API open, start Data Explorer in Author Mode.
    For more information about how to start Data Explorer in Author Mode, see Author Mode.
    The following image illustrates the steps:
    B2B DX1.png
  2. Select the 
    Orders
     table from the 
    Entities
     drop-down.
    The Main Grid refreshes.
  3. In the Main Grid, select an order.
  4. Create an order details row by completing the following steps:
    1. In the Child Grid, click 
      Insert
       on the toolbar.
      A dialog opens.
    2. Select the product by entering 
      Pav
       in the search box, click 
      Search
      , and then click 
      Select
       for the 
      Pavlova
       row in the list.
      The dialog closes.
    3. Click 
      Save
      .
    The order details row is created in the 
    Orders
     table.
  5. Verify the following:
    • That a row exists in the 
      PartnerOrders
       table in the B2B Pavlov API. Test using the REST Lab in API Creator or using Data Explorer.
    • That the rules have adjusted the order and customer values. Check the logs for the previous update.
Test the B2B Northwind API using Node.js
Test the 
B2B Northwind
 API using Node.js. The 
deployProd.cmd
 and 
deployProd.sh
 scripts that you run when deploying the B2B sample use Node.js. You can test the 
B2B Northwind
 API using these scripts.
For more information about testing the 
B2B Northwind
 API using these scripts, see B2B API Sample Scripted Deployment.
Test the B2B Northwind API using Python or PHP
Prerequisites:
 
  • You have installed Python or PHP.
  • You have downloaded and extracted the following B2B sample scripts that are available for Python and PHP from the liveapicreator-devops site on GitHub:
    • For testing using Python, the scripts that are located in the 
      /liveapicreator-devops/sample-scripts/b2b-devops/deployProdTests/python
       directory.
    • For testing using PHP, the scripts that are located in the 
      /liveapicreator-devops/sample-scripts/b2b-devops/deployProdTests/php
       directory.
Test the 
B2B Northwind
 API using the sample scripts.