Articles in this section

Configure an API response using API builder

An API response defines what your API returns to the caller: the status code, the headers, and the body schema. Each API has a Success response and an Error response by default, and you can add more. Configure each response so that callers receive data in a consistent shape.

For sample responses, see Get all shops, Get a chocolate, Create a new chocolate, and Composite API. To see where responses fit on the canvas, see API builder overview.

The Define API response panel for the Success response.

Name the response

  1. On the canvas, select a response step to open Define API response.
  2. Enter values for the following settings.
Setting Required What to enter
Name your API response Yes A name that identifies the response in other parts of the application.
Description No A summary of what the response does, so that other users understand it without reading every setting.

The default names are Success response and Error response. A response that you add has no name until you enter one. To control which response a request reaches, see Branching in API builder.

Choose the status code

In HTTP status code, choose the code that the response returns. You can't add codes. The Success response uses 200 - OK by default, and the Error response uses 500 by default.

Available status codes

Status code Message
100 Continue
101 Switching Protocols
102 Processing
103 Early Hints
200 OK
201 Created
202 Accepted
203 Non-Authoritative Information
204 No Content
205 Reset Content
206 Partial Content
207 Multi-Status
208 Already Reported
226 IM Used
300 Multiple Choices
301 Moved Permanently
302 Found
303 See Other
304 Not Modified
305 Use Proxy
307 Temporary Redirect
308 Permanent Redirect
400 Bad Request
401 Unauthorized
402 Payment Required
403 Forbidden
404 Not Found
405 Method Not Allowed
406 Not Acceptable
407 Proxy Authentication Required
408 Request Timeout
409 Conflict
410 Gone
411 Length Required
412 Precondition Failed
413 Payload Too Large
414 URI Too Long
415 Unsupported Media Type
416 Range Not Satisfiable
417 Expectation Failed
418 I'm a Teapot (RFC 2324)
421 Misdirected Request
422 Unprocessable Entity
423 Locked
424 Failed Dependency
425 Too Early
426 Upgrade Required
428 Precondition Required
429 Too Many Requests
431 Request Header Fields Too Large
451 Unavailable For Legal Reasons
500 Internal Server Error
501 Not Implemented
502 Bad Gateway
503 Service Unavailable
504 Gateway Timeout
505 HTTP Version Not Supported
506 Variant Also Negotiates
507 Insufficient Storage
508 Loop Detected
510 Not Extended
511 Network Authentication Required

Add HTTP headers

Add custom headers to return with the response.

  1. In HTTP headers, enter a header name in the blank row.
  2. Enter the header value. To return a value from your data, use a handlebars expression. See handlebars expressions.
  3. Enter a Description.

The only Authorization header you can return is Token. To use other authorization headers, see advanced API Management configurations.

Define the response body

Define the schema of the JSON that your API returns. The response body is always an object. Field data types are string, number, boolean, object, and array. If you need background on JSON, see JSON.

  1. In Generate schema from sample JSON, select Choose file, and then select a .json file. The same rules apply as for the request body. See Generate schema from sample JSON.
  2. To add fields yourself instead, select Add schema manually. See Add schema manually.

To remove a field, delete its row. The editor also has Visual and JSON views, which work the same way as in the request body. See Switch between Visual and JSON.

To require a field or limit its values, select Additional settings on the field's row. See Set rules on a field.

After you define the body, map your data to it. A field that you mark Required shows an asterisk (*) before its name in the mapper, whether or not validation is on. See Mapping data in API builder.

When validation is on, a response that doesn't match the schema of the response that runs returns HTTP 500 to the caller. See What callers receive.

Preview the response

  1. Select Input to review the data that reaches the response.
  2. Select Preview.
  3. Select Send.

HTTP response shows what the caller receives. When validation is on, Preview checks the response against your schema. See Preview and test runs.