AI Protocol Mappers
Where a Message Mapper reshapes JSON into different JSON, a Protocol Mapper converts between the JSON an agent always sees and the upstream's actual wire format — XML, a SOAP 1.1 or 1.2 envelope, or form-urlencoded — so you can put a modern JSON tool interface in front of a legacy service without changing anything on the upstream side.
Like message mappers, a protocol mapper applies to one OpenAPI operationId, in one direction (request or response), and only one mapper of each direction can exist per operation.
Fields
| Field | Notes |
|---|---|
wire_format | xml or form_urlencoded |
root_element | XML only — the top-level element/tag name to wrap the JSON payload in when encoding |
soap_envelope | If true, the XML is wrapped in (or unwrapped from) a SOAP Envelope/Body |
soap_version | 1.1 (default) or 1.2 — see SOAP services |
soap_action | The operation's SOAP action — request direction, soap_envelope: true only. Sent as the SOAPAction header (SOAP 1.1) or as the action parameter of the Content-Type (SOAP 1.2) |
target_namespace | XML only — the namespace of the payload element (the service's targetNamespace in its WSDL) |
namespace_children | Default true: child elements inherit target_namespace (qualified). false prefixes only the payload element and leaves children unqualified |
endpoint_path | Request direction only — upstream path to send this operation to instead of its own path, e.g. /service.asmx |
soap_headers | Request direction, SOAP only — extra <soap:Header> elements as JSON. Not for secrets: stored and shown in clear |
content_type_override | Overrides the Content-Type header that would otherwise be inferred from wire_format/soap_envelope/soap_version |
test_cases | [{json_sample, wire_sample}] pairs used by the test endpoint |
On update, fields you leave out are kept. Sending null or "" for an optional text setting (root_element, soap_action, content_type_override, target_namespace, endpoint_path, soap_headers) clears it.
Conversion Rules
- XML element and attribute names come from your JSON keys and are validated: a key that isn't a valid XML name (for example
a><b) is rejected, so JSON input can't inject markup into the request sent upstream.root_elementis validated when you save. - Namespaces are removed from element and attribute names when decoding, so a SOAP response decodes to plain keys —
{"GetRateResponse": {"Rate": {"@currency": "INR", "#text": "83.50"}}}rather than{http://…}Rate. - Prefixed keys such as
tns:Nameneed their prefix declared: add"@xmlns:tns": "<namespace URI>"to that object or a parent, or settarget_namespaceand drop the prefix. An undeclared prefix is rejected with an error instead of being sent as XML that no parser accepts. nullvalues are left out of the XML, because most SOAP services reject an empty element where they expect a value (an empty<Age/>doesn't parse as an int). When decoding, an element withxsi:nil="true"becomesnull, andxsi:type/xsi:schemaLocationattributes are dropped.- Typing and order. XML and form bodies carry only strings. On the response side, the gateway converts decoded values to the types in the operation's OpenAPI response schema (numbers, booleans) and turns a single repeated element into a one-item list where the schema says array. On the request side, an unmapped body is sent with its fields in the order the schema declares them, since
xs:sequenceservices reject any other order. - Encoding. Upstream XML is parsed as bytes, so the document's own encoding declaration and any byte-order mark are honoured.
- Form-urlencoded encoding accepts flat values and lists of scalars (a list becomes a repeated key,
tag=a&tag=b). Nested objects have no form equivalent and are rejected with a clear error — flatten them with a request Message Mapper first. When decoding, a repeated key becomes a list. - Untrusted XML (upstream responses and samples) is parsed with protections against entity-expansion and external-entity attacks; such documents are refused.
soap_actionandcontent_type_overridecan't contain line breaks.
SOAP Services
SOAP 1.1 and 1.2
| SOAP 1.1 (default) | SOAP 1.2 | |
|---|---|---|
| Envelope namespace | http://schemas.xmlsoap.org/soap/envelope/ | http://www.w3.org/2003/05/soap-envelope |
Content-Type | text/xml; charset=utf-8 | application/soap+xml; charset=utf-8; action="<soap_action>" |
| Action | SOAPAction: "<soap_action>" header — always sent, "" when no action is set | In the Content-Type; no SOAPAction header |
Namespaces
Most SOAP services silently ignore every field sent without the right namespace. Set target_namespace to the service's targetNamespace:
- Qualified (
namespace_children: true, the default, usual for .NET/WCF and document/literal services) puts the namespace on the payload element as the default namespace, so child elements inherit it:<GetPet xmlns="http://tempuri.org/"><id>1</id></GetPet>. - Unqualified (
namespace_children: false) prefixes only the payload element:<ns:GetPet xmlns:ns="http://tempuri.org/"><id>1</id></ns:GetPet>.
One endpoint for every operation
SOAP services usually take every operation at one URL and route by the SOAP action. Set endpoint_path (for example /service.asmx) on each operation's request mapper, and the gateway sends the operation there instead of to its own OpenAPI path. The API's endpoint list shows this real upstream URL. The path must be a plain path: no query string, fragment or ...
A SOAP call is always a POST with an envelope. If the operation is modelled as a GET, the gateway builds the envelope from the call's query and path parameters (in the order the spec declares them), drops the query string and sends a POST.
Custom SOAP headers
soap_headers adds <soap:Header> elements to every request. They use the same JSON conventions as the body: one key per header element, @xmlns for its namespace, @attr for attributes. Header fragments may use the envelope's soap: prefix (for example soap:mustUnderstand).
{ "AuthHeader": { "@xmlns": "http://tempuri.org/", "ClientId": "hrida-agent" } }Values here are stored and shown in clear. For WS-Security credentials, use the API's WS-Security upstream auth; the gateway adds that header itself, after the mapper's own headers. SOAP headers can only be set through the API for now; the mapper form in API Builder doesn't edit them.
SOAP Faults
When the upstream answers with a SOAP Fault, the gateway returns it as a JSON error, never as a result, even when the service sends the fault with HTTP 200:
{ "error": { "type": "soap_fault", "code": "soap:Client", "message": "Invalid pet id", "detail": { "...": "..." } } }SOAP 1.1 faults (faultcode/faultstring/detail) and 1.2 faults (Code/Reason/Detail, plus subcode) both use this shape. Masking applies to it, since fault text often echoes the request.
- A fault the caller caused (
Clientin 1.1,Senderin 1.2) returns400, whatever status the service used, so an agent can tell "fix your input" from "the service failed". - Any other fault keeps the upstream's error status, or returns
502if the upstream sent a success status. - SOAP 1.1 sends every fault as HTTP
500. Caller faults don't count as failures for the circuit breaker, so one agent's bad input can't pause the API for everyone.
Importing a WSDL
Instead of writing the spec and mappers by hand, you can give API Builder the service's WSDL. POST /api/v1/api-definitions/wsdl/inspect reads it and proposes everything needed to call the service with JSON. Nothing is saved.
POST /api/v1/api-definitions/wsdl/inspect
{ "url": "https://example.com/calculator.asmx?WSDL" }Send either url or the WSDL itself as text, and optionally soap_version to pick the binding. The response contains:
| Field | Contents |
|---|---|
name, description | From the service and its documentation |
upstream_base_url, endpoint_path | Where the service lives |
soap_version, soap_versions | The binding used (1.1 preferred when both exist) and every version the WSDL binds |
openapi_spec | One POST /<Operation> per WSDL operation, with request and response schemas generated from the XSD: properties in xs:sequence order and repeated elements as arrays |
mappers | A request and a response protocol mapper per operation, with root element, target namespace and qualification, SOAP action and endpoint path filled in |
suggested_auth | ws_security when the WSDL's policy asks for a UsernameToken |
warnings | Anything that couldn't be mapped faithfully |
Create the API from the proposal's spec and base URL, then apply its mappers:
POST /api/v1/api-definitions/{api_definition_id}/protocol-mappers/from-wsdl
{ "mappers": [ ... ], "replace": true }This creates a mapper for each operation and direction and returns {created, updated, skipped}. Operations missing from the API's spec are skipped and reported. With replace: true (the default), an existing mapper is updated, but only with the settings the proposal sets, so a re-import keeps your custom SOAP headers and test cases. With replace: false, existing mappers are left alone. It needs the same roles as creating mappers.
- Supported: WSDL 1.1; document/literal (wrapped and bare) and rpc/literal over SOAP 1.1 and 1.2 bindings. Documents referenced by
wsdl:import,xsd:importandxsd:includeare fetched too. - Not supported (reported in
warnings): rpc/encoded, WSDL 2.0, header parts and attachments (MIME/MTOM).
Fetching goes through the same network protections and host allow-list as upstream calls. Redirects aren't followed, each document is capped at 5 MB, at most 25 documents are read, and all XML is parsed with protection against entity attacks. WSDL import is available through the API only for now; the API Builder pages don't have an import button yet.
Deterministic Detection, AI Only for the Ambiguous Cases
Converting well-formed XML, a SOAP envelope, or form-urlencoded data is entirely deterministic — parsing them doesn't need an LLM. POST /protocol-mappers/detect takes a raw sample and returns a proposed config with a confidence level:
POST /protocol-mappers/detect
{ "sample": "<Envelope xmlns=\"http://schemas.xmlsoap.org/soap/envelope/\"><Body><GetPet><id>1</id></GetPet></Body></Envelope>" }{ "wire_format": "xml", "soap_envelope": true, "root_element": "GetPet", "confidence": "high" }- A well-formed SOAP envelope or plain XML document detects with
confidence: "high"—wire_format,root_element, andsoap_envelopeare all filled in directly. - A
key=value&...-shaped sample detects asform_urlencodedwithconfidence: "medium". - Anything that fails to parse as XML, or already looks like JSON, comes back
confidence: "low"with areasonand nowire_format(a sample that's already JSON needs no protocol mapper at all).
POST /protocol-mappers/generate is the AI fallback for exactly the ambiguous cases above (anything not confidence: "high") — it's used to name a root_element or confirm SOAP framing on an unusual sample, never to parse the format itself:
{ "root_element": "GetPetResponse", "soap_envelope": true, "reason": "...", "source": "ai" }("source" is "deterministic" if the high-confidence deterministic result was returned as-is, "ai" if the LLM fallback ran.) As with Message Mapper generation, the proposal is never auto-applied — review and save it like any other mapper field.
Endpoints
All under /api/v1/api-definitions/{api_definition_id}, mirroring the Message Mapper API shape:
| Endpoint | Description |
|---|---|
GET /protocol-mappers | List all protocol mappers for this API |
POST /protocol-mappers | Create a mapper |
GET /protocol-mappers/{mapper_id} | Get one mapper |
PUT /protocol-mappers/{mapper_id} | Update a mapper (partial) |
DELETE /protocol-mappers/{mapper_id} | Delete a mapper |
POST /protocol-mappers/detect | Deterministic wire-format detection from a raw sample |
POST /protocol-mappers/generate | AI-assisted fallback for ambiguous samples |
POST /protocol-mappers/{mapper_id}/test | Round-trip test against saved test_cases |
POST /protocol-mappers/from-wsdl | Create or update mappers from a WSDL proposal |
POST /api/v1/api-definitions/wsdl/inspect (not tied to an API) reads a WSDL and returns the proposal.
Creating, editing, or deleting a mapper requires the same roles as Message Mappers — api_developer, lifecycle_manager, space_admin, or admin.
While the API is staged or published, only a lifecycle_manager, space_admin or admin can create, edit or delete its protocol mappers (an api_developer gets 403 and pulls the API back to draft first). That includes a WSDL re-import. On a published API without environments, the change is live on the next call. With environments, it changes the working copy and reaches an environment when a new version is approved and promoted.
Testing a mapper
The test compares by decoding both sides, not a brittle exact-string match — XML attribute order or whitespace can legitimately differ while being semantically identical. For each {json_sample, wire_sample} test case: json_sample is encoded to wire format and immediately decoded back, and compared against the decoded wire_sample (or against json_sample itself if no wire_sample is given). Pass/fail is cached the same way as Message Mapper tests (last_test_passed, last_tested_at).
The test uses the gateway's own encoder and decoder, so a passing test means the gateway sends and reads exactly the same thing. Each result also shows Sent on the wire (wire_output, the encoded body for json_sample, so you can check the envelope and namespaces by eye) and wire_sample as the agent gets it (decoded_wire_sample). A wire_sample holding a SOAP Fault decodes to the same soap_fault error the gateway returns.
Related
- AI Message Mappers — JSON-to-JSON reshaping; runs before protocol encoding on the request side, after protocol decoding on the response side
- API Gateway — the exact pipeline order both mapper types run in on a live call
- Upstream Auth & TLS — WS-Security UsernameToken for SOAP services