B2B API Sample

This Business to Business (B2B) sample is a data integration example that illustrates a small but non-trivial system, built using . This article provides a high-level overview of  and covers beginning functionality and concepts.
This Business to Business (B2B) sample is a data integration example that illustrates a small but non-trivial system, built using 
CA Live API Creator
. This article provides a high-level overview of 
CA Live API Creator
 and covers beginning functionality and concepts.
For more logistics and training resources, see Explore the B2B API Sample.
B2B Pavlov
 and the 
B2B Northwind
 API samples are included with the single-user demonstration package of 
CA Live API Creator
 that is based on Jetty and with the 
CA Live API Creator
 Docker container installation. No additional steps are required to load these API samples.
If you have installed 
CA Live API Creator
 on another Java container, you can also load this API sample.
In this article:
The B2B sample illustrates a typical API Server that processes inputs from multiple (omni-channel) sources:
  1. Processes omni-channel requests, such as a partner order.
     API Server accepts requests from multiple channels, such as mobile devices, partners, "catching" webhooks, and web applications. The API definition is not the same as the B2B schema, providing mapping and transformation logic.
    For more information about webhooks, see Integrate Systems and Data.
  2. Enforces business logic.
    CA Live API Creator
     includes business policy for logic and security. This includes internal processing for credit checks and external processing such as sending alerts to shippers, by posting a request in an agreed-upon API format. This API definition does not match the B2B schema.
  3. Integration
    . Your API can "throw" (send) webhooks to other systems (for example, to a supplier in an agreed-upon format that may not match your schema), and integrate multiple databases.
  4. Provides UI.
     Partners (shippers, suppliers) can view their information, for example, from a mobile device or from a PC.
The following diagram shows the flow for this system:
  CA Technologies  
B2B systems are complex and time-consuming to build. They build business logic using traditional approaches that are based on interface documentation (for example, RESTful API Modeling Language (RAML)), frameworks (for example, Jersey, Jackson, Java Persistence API (JPA)), and integrated development environments (IDEs). Use the B2B sample to explore the 
CA Live API Creator
 alternative, which requires about a dozen lines of JavaScript, a dozen rules, and five point-and-click resources. 
The complete implementation using 
CA Live API Creator
 consists of several rules and a few lines of JavaScript. The B2B sample uses the Northwind sample database as the underlying database, to simplify installation.
The server for the single-user demonstration package of 
CA Live API Creator
 that is based on Jetty and the installation of 
CA Live API Creator
 on Apache Tomcat are pre-configured for the Northwind sample database. No additional configuration steps are required to access this database.
B2B Learning Guide
The B2B sample is a key resource in understanding what 
CA Live API Creator
 can do and how to use it. The following resources are provided to help you ramp as quickly as possible:
  • Explore the B2B API samples (Fundamentals)
    The API samples illustrate introductory 
    CA Live API Creator
     functionality and concepts such as API Creation, logic, and extensibility.
    For more information about this introductory functionality and these concepts, see the "Explore B2B (Fundamentals)" section.
  • Explore the B2B API samples (Intermediate)
    The API samples also illustrate deeper 
    CA Live API Creator
     concepts such as metadata action tags, multi-database resources, functions, security, Data Explorer, and scripted API deployment that you need for your own APIs.
    For more information about these intermediate functionality and concepts, see Explore the B2B API Sample.
  • Readiness Lab
    After exploring the introductory and intermediate 
    CA Live API Creator
     functionality and concepts, you can verify your readiness to use 
    CA Live API Creator
     using the set of labs that is built using this API. The labs are located in the 
    samples/b2b/readinessLabs/Readiness - CA Live API Creator.docx
     file (and in the PDF file) that is located in your install folder.
    You have completed the first lab by installing the B2B sample and testing the API.
  • Other B2B test scripts
    A key strength of the API architecture is that you can call APIs in various ways, across languages and architectures. You can test the B2B API using most any program. This includes the REST Lab, Data Explorer, scripts such as cURL or the command-line interface (CLI), or programs such as Node.js, Python, or PHP. Your API is therefore useful not only for integration, but web apps, scripting, and a host of other applications. Your install zip includes examples of each of the testing approaches.
    For more information about how to test the B2B API, see Other B2B API Sample Test Scripts.
Explore B2B (Fundamentals)
The B2B sample illustrates key 
CA Live API Creator
 features. The B2B sample API provides an excellent study in creating an API backend. Explore the B2B sample to see the code/rules that make up the 
B2B Northwind
 API. The following image illustrates these code/rules:
  B2B App Integration.png  
While this application contains only a few dozen lines of logic and code, it illustrates other patterns common to B2B systems.
  1. An order is posted through the 
     resource. This resource provides the mapping and transformation logic to process the order from a partner.
  2. The post activates the business logic:
    1. You can compute order totals with product-based discounts, adjust the customer balance, and ensure that the credit limit is not exceeded using about ten rules.
    2. The 
      Process Shipper Webhook
       event rule Posts an alert to the shipper (about 5 lines).
      CA Live API Creator
       uses the 
       resource for mapping and translation logic, to format the data as expected by the Shipper.
Not shown in the diagram, B2B illustrates other common patterns:
  • Database Integration:
     resource integrates multiple databases and enforces row-level security. Partners can safely and directly access their data.
  • Testing:
     resource is included in the /
     B2B DevOps sample script.
    • You can test the 
       resource in the REST Lab, as explained in the comments for the 
    • For more information about this script, see the liveapicreator-devops site on GitHub.
  • DevOps Deployment Scripting:
     You can use the examples of command-line scripting and API access from Node, Python, and PHP programs using the installation scripts that are located in the 
API Creation and Customization
The first step is to create your API and customize/shape it as required. Swagger documentation is available. Use the API with various tools to generate objects, such as in C# and Java.
Connect to Create Default API
The B2B system connects to the database and creates endpoints for each table, view, and stored procedure. There is no code generation or deployment. The install scripts create the B2B system.
Resources: Mapping and Transformation
The following image shows the resource 
  Screen Shot 2017-01-06 at 5.08.27 PM.png  
The default API is a good start, but it conforms to your schema. Typically, you will want to customize your API. For example, API agreements with partners typically do not match internal schema definitions. The resources that you explicitly define using API Creator provide key services to map API agreements onto your database and logic:
  • Choose/rename columns, which is a simple approach to mapping and transformation logic. In the previous image, 
     column is aliased to 
  • Specify resource nesting so that B2B requests can include multiple kinds of data, such as the Order and Items.
  • Use non-persistent attributes (NPA) in resources. For example, in the 
     resource, the SalesRep's 
     is an NPA.
  • Combine parent subresources into the containing resource. For example, in the 
     resource, the 
     information appears with the 
  • The resources that you explicitly define using API Creator reuse the logic that is on the underlying tables.
For more information:
Logic ensures the integrity of your data when update requests are made. For example, we want to:
  • Verify that orders do not exceed customers' credit limits.
  • Provide discounts for healthy orders.
  • Post requests to the 
     supplier when orders are received for their products.
The following sections illustrate how to perform this type of multi-table logic and integration with other systems. In API Creator, the logic is done by way of spreadsheet-like reactive logic and extended with server-side JavaScript.
For more information about reactive logic rules, see the conceptual background of Logic.
Declarative Reactive Rules
Rules are spreadsheet-like expressions (coded in JavaScript) defined on tables and columns. API Server automatically applies them (reacts) to all submitted updates. You do not need to call them.
The following executable rules apply to all of the resources that you explicitly define using API Creator. Rules can reduce server-side integrity enforcement by over an order of magnitude. Rules provide clear and concise user-readable logic instead of tedious code. The requirements are captured as topics (in the following image, as blue, green, and red boxes) and linked to the logic for traceability:
  Screen Shot 2016-12-26 at 5.28.11 PM.png  
B2B Northwind
 API includes the following topics:
  • Check Credit.
     Rolls up items and orders to verify that the customer's credit limit is not exceeded. (If a validation is exceeded, the request results in an exception and the transaction is rolled back.)
  • Healthy Food Discount.
     Provides a discount to customers ordering things like fruits and fish.
  • Supplier Alert.
     When orders are detected for the 
     supplier, the business agreement requires that the order is posted to the 
  • Shipper Alert.
     When orders have an assigned shipping company, alert them to order changes.
For more information:
Extensibility: Table Events
Reactive logic is powerful. Extensibility is provided by server-side JavaScript, to ensure that no limits exist.
For more information:
  • About viewing an example of Bill of Materials that are solved with a few rules, see the Logic Tutorial.
  • About a list of the JavaScript extension points, including their supplied context, see Quick Reference Guide.
  • About logic event rule types, see Event Rule Types.
The following Orders 
Process Shipper WebHook
 commit event rule posts a webhook to alert shippers of order changes. The following image shows this commit event rule in the 
B2B Northwind
  CA Technologies  
Where the following commit event rule code posts an order and 
 to the 
var shipper = row.Shippers; // object model (row) provides accessors to related objects
if (shipper !== null && shipper.OrderChangeWebHook !== null) {
var response = logicContext.transformCurrentRow("ShipperAPIDef"); // ShipperAPIDef resource: transformation
SysUtility.restPost(shipper.OrderChangeWebHook, {}, ConstantsLib.supplierAuth, response); // find with Control-Space, or Examples
The Orders event logic is available with code completion. This code example is available from the event rule code editor.
This commit event rule illustrates several key patterns of B2B integration:
  • Transformation logic.
     A common integration pattern is to use resources for mapping and translation, leveraging their ability to choose/rename attributes and related objects. The 
     method transforms a table row to a resource instance and is typically called in an event rule. This method provides transformation logic to select/rename attributes and related objects. The 
     resource defines the format of the post.
  • Event handling. 
    Event rules react to database changes, regardless of the execution path.
  • Posting.
     The post is done in the 
  • Webhook target. 
    Shippers can register for webhooks by way of self-service APIs that set 
    For more information about this pattern, see Explore the B2B API Sample.
For more information: