# How do I transform a custom connector response without masking an API failure?

Exam: AB-400 — Power Platform Developer Associate
Knowledge domain: Develop integrations (10–15%)
Updated: 2026-11-25T06:47:24.03539+00:00
HTML: https://learningpathx.com/faq/AB-400/ab400-custom-connector-code-transform-response-errors.html

## Also asked as

- How can custom connector C\# code flatten a successful response and preserve backend errors?
- What should connector code return when a successful HTTP response has the wrong shape?

Use custom code when a policy template cannot express the response transformation. In the supported C# script, implement `Script : ScriptBase` and override `ExecuteAsync`. Forward the request with `Context.SendAsync`. Preserve the backend's error statuses. For a successful response, validate the shape before converting it to the consumer's documented schema. If a 200 response is missing required fields or has the wrong types, return a deliberate contract error such as 502 rather than inventing an empty success.

For example, a quote API might wrap its result in `result`. Validate that the inner quote ID, numeric cost, and currency meet the exposed contract before returning the flattened fields. Restrict the code to the intended operation. If dispatch uses the operation identifier, consult the documented regional encoding issue and validate the identifier handling.

Check the supported namespaces and platform limitations. Microsoft documents one script file, .NET Standard 2.0, up to 1 MB and a two-minute ceiling on new or updated connectors. Custom code has documented gateway and virtual-network limitations, including the public endpoint path used by `Context.SendAsync`.

Compile against the supported interfaces, deploy to a development connector, and test valid 200, malformed success, invalid credentials, and a controlled service failure. Verify the actual downstream flow branches and output schema with code enabled.

**Microsoft references**

* [Use custom code in a custom connector](https://learn.microsoft.com/en-us/connectors/custom-connectors/write-code)
* [Create a custom connector from an OpenAPI definition](https://learn.microsoft.com/en-us/connectors/custom-connectors/define-openapi-definition)

Source: [AB-400: Custom Connectors with OpenAPI, Policies and Code](https://learningpathx.com/news/ab-400-custom-connectors-with-openapi-policies-and-code.html)
