{"title":"ApiResponse - Liquid Object Reference","slug":"api-response-liquid-object-reference","url":"https://support.storeconnect.com/articles/api-response-liquid-object-reference","url_markdown":"https://support.storeconnect.com/articles/api-response-liquid-object-reference.md","subtitle":null,"summary":"An ApiResponse contains the result of an API request initiated using the api tag.","type":"Developer_Documentation","video_url":"","keywords":"liquid, objects, ApiResponse, template, storeconnect","last_modified":"2026-08-21T07:12:35+0000","body_markdown":"## Description\n\nAn `ApiResponse` holds the result of an outbound HTTP request made with the [api tag](api-tag-reference). Inside an `{% api %}...{% endapi %}` block that specifies a `url`, the response is exposed as the `response` object once the request completes, so you can branch on the status code and read the returned data.\n\nThe `response` object is only populated for **synchronous** requests (`async: false`). With `async: true` the request is dispatched fire-and-forget and no response is returned to the template.\n\n## Attributes\n\n| Attribute | Type | Description |\n|-----------|------|-------------|\n| `status` | Number | The HTTP status code of the response (e.g. `200`, `404`, `500`). It compares numerically, so `response.status \u003e= 200 and response.status \u003c 300` tests for success. |\n| `body` | Map | The HTTP response body. When the endpoint returns JSON it is parsed automatically, so nested fields are reachable directly (`response.body.access_token`, `response.body.data`). Use the [serialize filter](serialize-filter-reference) to turn a Map or List back into a JSON string for storage or output. |\n| `headers` | Map | The HTTP response headers, keyed by header name. |\n\n## Examples\n\n### Read a successful JSON response\n\n\n```liquid\n\n{% liquid\n  new Map headers = '{ \"Accept\": \"application/json\" }'\n  assign result = ''\n  api url: 'https://api.example.com/v1/status', method: 'GET', headers: headers, async: false\n    if response.status \u003e= 200 and response.status \u003c 300\n      assign result = response.body.message\n    endif\n  endapi\n%}\n{{ result }}\n```\n\n\n### Handle an error status\n\nAlways check `status` before trusting `body`, and capture the raw body when a call fails so the error is visible while developing:\n\n\n```liquid\n\n{% liquid\n  api url: 'https://api.example.com/v1/orders', method: 'GET', headers: headers, async: false\n    if response.status \u003e= 200 and response.status \u003c 300\n      assign orders = response.body.orders\n    else\n      assign error = response.body | serialize\n      debug status: response.status, error: error\n    endif\n  endapi\n%}\n```\n\n\n### Read a response header\n\n\n```liquid\n\n{% api url: 'https://api.example.com/v1/status', method: 'GET', async: false %}\n  {% assign request_id = response.headers['x-request-id'] %}\n{% endapi %}\n```\n\n\nSee the [api tag reference](api-tag-reference) for how to issue the request, set headers, and send a request body."}