Skip to content

SAP BTP

Connecting Two Companies with SAP Integration Suite and API Management

HarderTech LLC

How CardQuest purchases packs from CreatureWorks through API Management, Cloud Integration, and a restricted CAP B2B service — including the OAuth 403 that wasn’t a CAP config bug.

Building a secure B2B purchase-order path using Cloud Integration, OAuth, API Management, and SAP CAP.

In Part 1 I described how a reward-based collectible-card game for my son led to CreatureWorks Distribution — a lightweight supplier application on SAP BTP. CardQuest Collectibles is the in-game store that will eventually spend earned currency on packs. Those packs shouldn’t appear from nowhere; they should come from CreatureWorks inventory, purchased through APIs the way two independent systems would talk.

If CardQuest “buys” only because I open Sales Order Management and type the order myself, there isn’t a real boundary between supplier and game. Part 2 is that boundary.

CardQuest sends a purchase order. CreatureWorks validates the customer, applies wholesale prices, creates a sales order, and returns an acknowledgement — without giving the game (or any technical client) SupplierAdmin access.

Architecture bridge between CreatureWorks and CardQuest

CreatureWorks on BTP; CardQuest as an external application. Integration Suite and API Management carry the purchase-order conversation. The reward game itself is still under development.

Part 3 covers what happens after I confirm and ship — the events CardQuest will eventually use to know inventory is available.

The challenge

Why separate systems at all? Because the game needs a purchasing contract, not a shared database table and unlimited packs. CardQuest needs a way to say: I want ten Forest Discovery packs and five Ocean Discovery packs. That’s the same 190.00 CRD scenario from Part 1 — PO number, SKUs, quantities.

What CardQuest must not do:

  • Log into Work Zone as a supplier admin
  • Dictate unit prices
  • Call internal OData operations meant for warehouse actions

CreatureWorks keeps pricing and inventory rules. The game keeps a simple purchasing API.

The design

Three layers, each with a job:

CAP B2BService — restricted purchase-order action for a technical client. Business rules live here.

Cloud Integration — accepts the external JSON, validates and transforms it, calls CAP, and gives me message monitoring.

API Management — managed external edge: identify the consuming app, apply policies, monitor the product.

Integration Suite does not decide wholesale prices or reserve inventory. CAP does. That split is the architecture, not a configuration preference.

Separate CAP services

I already had SupplierService for Fiori. I added B2BService:

@path: 'b2b'
@requires: 'B2BIntegration'
service B2BService {
    action submitPurchaseOrder(
        externalOrderRef : String(80),
        lines            : many PurchaseOrderLine
    ) returns OrderAcknowledgement;
}

The technical client gets B2BIntegration, not SupplierAdmin. The handler resolves CardQuest by customer code (CQ-001 by default) — it does not trust a customer ID from the payload. It maps SKUs to products, then calls the same createSalesOrder logic used internally.

Order creation still produces a SUBMITTED sales order with prices copied from the catalog. Inventory reservation still happens later on confirm (Part 1). Duplicate PO references with matching lines return an acknowledgement with duplicate: true. Conflicting line content on the same PO gets HTTP 409.

A direct CAP acknowledgement looks like this — status SUBMITTED, catalog total, and duplicate: false when the PO is new:

B2BService submitPurchaseOrder acknowledgement for CQ-PO-0002

OrderAcknowledgement from B2BService — supplier order ID, external PO reference, and 190.00 CRD.

Following one purchase order through the stack

Cloud Integration iFlow

I built CardQuest Purchase Order to CreatureWorks.

Creating the purchase-order iFlow

Starting the inbound flow in the CreatureWorks B2B Integrations package.

The completed flow is the useful picture: HTTPS sender, Groovy mapping, HTTP call to CAP, response handling, and an exception subprocess for technical failures.

Inbound iFlow with mapping, CAP call, and exception subprocess

Notice the path: external message is validated and transformed before a restricted CAP service runs the business transaction. Technical failures route through the exception subprocess.

CardQuest’s JSON is retailer-friendly. CAP expects externalOrderRef and lines. Groovy bridges that gap and rejects empty carts early.

Groovy mapping from CardQuest PO to CAP contract

Field rename and basic validation before the CAP call — mapping, not pricing.

Example external request (same pack mix as Part 1):

{
  "purchaseOrderNumber": "CQ-PO-0003",
  "items": [
    { "sku": "CW-FOR-001", "quantity": 10 },
    { "sku": "CW-OCN-001", "quantity": 5 }
  ]
}

(CQ-PO-0003 is a real test PO from this integration work. Part 1’s shipped example used CQ-PO-0001 on an earlier run. Same catalog and pricing pattern.)

Error handling that matches the business

Not every non-2xx from CAP is the same kind of problem.

  • Duplicate PO / invalid product / inactive customer are business outcomes. The iFlow should capture the response, log useful custom properties, and return a clear result to the caller.
  • Timeouts, DNS failures, or an unreachable CAP route are technical failures. Those belong in the exception path.

Early on it was easy to stare at a green Completed Message Processing Log entry and miss that CAP had returned a business error. Improving response capture and exception routing made monitoring usable. Completed should mean the integration finished its job — not that every business rule passed silently in the payload.

Security: three authentication boundaries

Once API Management was in front, the inbound path had three credential relationships. Mixing them up is how troubleshooting burns an afternoon.

ConnectionAuthenticationWhy it exists
CardQuest → API ManagementAPI keyIdentifies the consuming application
API Management → Cloud IntegrationProcess Integration Runtime OAuthLets the gateway invoke the iFlow
Cloud Integration → CAPCreatureWorks XSUAA OAuth (B2BIntegration)Lets the technical client submit purchase orders

The API key is not a substitute for the XSUAA token CAP enforces. Process Integration Runtime credentials are not the CreatureWorks application XSUAA instance. Each hop has a reason.

OAuth2 client credentials security material

CPI security material used for the Cloud Integration → CAP hop (empty form; secrets stay in the platform).

Process Integration Runtime instance

Runtime credentials that support calling integration flows — separate from CreatureWorks XSUAA.

One more honesty point: putting API Management in front doesn’t magically unpublish a direct CPI endpoint. Locking down who can reach the integration runtime is a separate hardening step. On a trial lab I treated the managed product as the intended consumer path; production would need the network and policy story finished more carefully.

When everything looked correct, but CAP still returned 403

This was the most useful troubleshooting of the inbound work.

The HTTPS sender worked. Groovy transformed the message. The HTTP receiver reached CAP. CAP answered with authorization failure — essentially that the caller lacked B2BIntegration.

My first instinct was “the XSUAA config is wrong.” I checked xs-security.json. The B2BIntegration scope, role template, and authority were already there. I issued a fresh JWT outside the iFlow and confirmed it contained the expected scope and audience.

That narrowed the problem. CAP wasn’t inventing a missing role definition. Something about the token the receiver was actually sending didn’t match the token I had just inspected.

Integration Suite was still using cached OAuth security material issued before the authorization we needed was available. The config screens looked right. The runtime credential was stale.

Refreshing the OAuth2 credentials and forcing a new token acquisition fixed it. The next call succeeded.

The lesson I keep: when CAP says you’re missing a role, verify the descriptor, then verify the JWT that crossed the wire, then ask whether a middleware component is clinging to an older token. Don’t keep redeploying CAP while CPI happily reuses yesterday’s credentials.

I don’t have a clean screenshot of that 403 body in the published set — the investigation sequence matters more than another config dialog.

API Management as the external product

I introduced API Management because I didn’t want a retailer calling an internal integration endpoint with shared technical credentials meant for system-to-system hops.

Instead I wanted a managed interface where:

  • Verify API Key identifies the CardQuest application subscription
  • Spike Arrest and Quota limit abuse on a trial-facing endpoint
  • JSON threat protection rejects obviously hostile payloads early
  • Developer Hub publishes a product someone can subscribe to

API provider CreatureWorks_CPI_Provider

API provider pointing API Management at the Cloud Integration runtime for the purchase-order path.

API proxy creation

API proxy in front of the purchase-order path — the managed edge CardQuest is meant to call.

Add Resources dialog for /orders on CardQuestPurchaseOrdersAPI

Resource path and operations on the proxy — the external shape of the purchase-order API.

Verify API Key policy

Application identity at the gateway, before traffic reaches Cloud Integration.

Developer Hub product CreatureWorks B2B Services

Published API product for subscription — separate from supplier Work Zone access.

Following the managed path end to end

In the steady state, the intended inbound story looks like this:

  1. CardQuest (or a test client standing in for it) calls the API Management product with an application key and the purchase-order JSON.
  2. API Management applies key verification and traffic policies, then invokes Cloud Integration with Process Integration Runtime OAuth.
  3. The iFlow maps the retailer payload and calls CAP submitPurchaseOrder with a CreatureWorks XSUAA token that carries B2BIntegration.
  4. CAP creates a SUBMITTED sales order for CardQuest with catalog prices on the lines — still no inventory reservation.
  5. Work Zone Sales Order Management shows the order so I can confirm and fulfill as in Part 1.

That single path is what I mean by independent systems. The game never needs my Fiori role collection. The supplier never lets the purchaser set wholesale price.

Result

I tested with curl (token in an environment variable, not pasted into the article):

curl posting CQ-PO-0003

Simulated CardQuest request: Forest and Ocean packs, same quantities as the running example.

Then in Work Zone, the sales order appeared as SUBMITTED with supplier-calculated totals — ready for me to confirm and ship the way Part 1 described.

Sales order CQ-PO-0002 SUBMITTED after B2B submit

Sales Order Management after the integration path — 190.00 CRD, still SUBMITTED, reservation not yet taken.

Sales order object page after the B2B path

Outcome that matters: the PO entered through the managed integration path and landed as a real CreatureWorks sales order.

What Part 2 demonstrates

An external purchasing client can buy without supplier administration access. CAP owns the business transaction. Integration Suite owns transformation, connectivity, and monitoring. API Management owns the external product and consumer policies. Three credential boundaries stay distinct on purpose — and the 403 taught me to inspect tokens, not just descriptors.

Next: when packs ship, CardQuest still needs events so the game can treat inventory as available — that’s Part 3.


Next

Part 3 — Closing the B2B Loop


Further reading