# Api - Liquid Tag Reference

Source: https://support.storeconnect.com/articles/api-tag-reference · Last modified 21 August 2026

The `api` block tag makes an outbound HTTP request (an "API callout") from a Liquid template. It runs **server-side** during the render, so you can integrate with external services — payment providers, shipping rate calculators, auth servers, any REST endpoint — without writing Apex, and without exposing credentials to the browser.

The result of the request is available inside the block as the [`response` object](api-response-liquid-object-reference).

## Syntax


```liquid

{% api url: '<url>', method: '<method>', headers: <map>, data: <map>, async: false %}
  <!-- runs after the request completes; `response` is available here -->
{% endapi %}
```


| Property | Value |
|----------|-------|
| **Tag Name** | `api` |
| **Type** | Block tag |
| **Source** | StoreConnect |

## Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `url` | String | The endpoint to call. Required. |
| `method` | String | The HTTP method: `'GET'`, `'POST'`, `'PUT'`, `'PATCH'`, or `'DELETE'`. |
| `headers` | Map | Request headers. Build with a [`new` Map](new-tag-reference) — either from a JSON string or with the `set_key` filter (e.g. to add an `Authorization` header). |
| `data` | Map | The request body, sent as JSON. Use for `POST`/`PUT`/`PATCH`. |
| `bearer` | String | Bearer token; sent as an `Authorization: Bearer` header. |
| `username` | String | HTTP basic-auth username (pair with `password`). |
| `password` | String | HTTP basic-auth password. |
| `async` | Boolean | Set `false` to make a **blocking** request so the `response` is available inside the block. With `true` the request is dispatched fire-and-forget and no `response` is returned. |

## Description

When `async: false`, the body of the block runs after the request completes and the [`response` object](api-response-liquid-object-reference) exposes `response.status`, `response.body` (parsed automatically when the endpoint returns JSON), and `response.headers`. Always check `response.status` for success before reading `response.body`.

## Examples

### GET request


```liquid

{% liquid
  new Map headers = '{ "Accept": "application/json" }'
  assign forecast = ''
  api url: 'https://api.example.com/v1/forecast?city=denver', method: 'GET', headers: headers, async: false
    if response.status >= 200 and response.status < 300
      assign forecast = response.body.summary
    endif
  endapi
%}
{{ forecast }}
```


### POST request with a JSON body

Build the request body as a Map with the [`set_key`](set-key-filter-reference) filter; StoreConnect serializes it to JSON:


```liquid

{% liquid
  new Map headers = '{ "Content-Type": "application/json", "Accept": "application/json" }'

  new Map body
  assign body = body | set_key: 'name', 'Ada Lovelace'
  assign body = body | set_key: 'email', 'ada@example.com'

  api url: 'https://api.example.com/v1/contacts', method: 'POST', headers: headers, data: body, async: false
    if response.status >= 200 and response.status < 300
      assign new_id = response.body.id
    else
      debug status: response.status, error: response.body
    endif
  endapi
%}
```


### Authenticated request

Pass a bearer token with the `bearer` parameter — the tag adds the `Authorization: Bearer` header for you:


```liquid

{% api url: 'https://api.example.com/v1/account', method: 'GET', bearer: access_token, async: false %}
  {% assign account = response.body %}
{% endapi %}
```


## Additional recommendations

- **Cache expensive or rate-limited calls.** Wrap the block in a [`cache` tag](cache-tag-reference) so the storefront does not call the external service on every render — for example, cache an auth token for less than its stated lifetime and reuse it across requests.
- **Keep secrets server-side.** Because the callout runs during the render, API keys and secrets never reach the browser. Store them in store or theme variables rather than hardcoding them in the template.
- **Guard on `status`.** Treat only `2xx` as success; log `response.body` on failure while developing with the [`debug` tag](debug-tag-reference).

---

## Follow StoreConnect

- [Email Newsletter](https://getstoreconnect.com/c/lp-newsletter)
- [LinkedIn Newsletter](https://www.linkedin.com/build-relation/newsletter-follow?entityUrn=7444956928444862464)
- [YouTube](https://www.youtube.com/channel/UCngKdP2x8l1wcbAKW3tvU8g)
- [LinkedIn](https://www.linkedin.com/company/storeconnect)
- [X / Twitter](https://x.com/storeconnecthq)

## Popular Links

- [Partners](https://getstoreconnect.com/partners)
- [News](https://getstoreconnect.com/articles/news)
- [Events](https://getstoreconnect.com/articles/events)
- [Feature Comparison](https://getstoreconnect.com/how-we-compare)
- [Download a free trial](https://appexchange.salesforce.com/appxListingDetail?listingId=a0N3A00000FMkeKUAT)
- [Book a Demo](https://getstoreconnect.com/contact)

## Documentation

- [Help documentation](https://support.storeconnect.com/help-documentation)
- [AI agents](https://support.storeconnect.com/ai)
- [Videos & tutorials](https://support.storeconnect.com/videos-tutorials)
- [Developer reference](https://support.storeconnect.com/developer-reference)
- [Release notes](https://support.storeconnect.com/release-notes)
- [Troubleshooting](https://support.storeconnect.com/troubleshooting)
- [Trust Center](https://trust.getstoreconnect.com/)
- [Status Page](https://status.storeconnect.com/)

## Contact

- info@getstoreconnect.com
- US +1 415 745 3230
- AUS +61 2 8365 2308

100 S Ashley Dr, Suite 600-2461
Tampa FL 33602-600 USA

Level 22, Sydney Place
180 George Street
Sydney, NSW, 2000, AUS

---

StoreConnect Support — https://support.storeconnect.com/articles/api-tag-reference