Custom API's — Veldform — vanrossum.dev                    

       vanrossum.dev 

Custom API's — Veldform
=======================

  [home](https://vanrossum.dev)/[veldform](https://vanrossum.dev/products/veldform)/docs 

Veldform / Docs

Custom API's
============

Veldform talks to APIs in both directions: it can send entry data to any API on submit, and it can pull data from an API to populate options or prefill values. Credentials for all of this live in [connections](/products/veldform/docs/connections).

- [Sending data to an API](#sending-data-to-an-api)
- [Populating options from an API](#populating-options-from-an-api)
- [Prefilling field values](#prefilling-field-values)
- [Prefilling a whole form](#prefilling-a-whole-form)

Sending data to an API
----------------------

Add the `Send to external API` action to your form. It has the following settings:

### Connection

Optional — pick a saved [connection](/products/veldform/docs/connections). Its base URL is prepended to the endpoint and its auth headers are added to the request. This is how you handle authentication: API keys, Bearer tokens, Basic auth and OAuth2 are all configured on the connection, not on the action.

You can also leave it at `None` and use a full URL instead.

### Endpoint URL and method

The URL (or path, when using a connection) to send to. Merge tags are allowed. The method can be POST, PUT, PATCH or DELETE.

### Body

Three options:

- **Entry as JSON** — sends `{ "form_id": ..., "entry_id": ..., "data": { ... } }`
- **Entry as form-encoded** — the same data, form-encoded
- **Custom** — a [Liquid](/products/veldform/docs/merge-tags) template, for when the API expects a specific shape

With a custom body, use the `json` filter on every value — it quotes and escapes strings and leaves numbers and booleans bare, so your JSON stays valid:

```liquid
{
  "email": {{ field.f_email | downcase | json }},
  "firstname": {{ raw.f_name.first | json }},
  "guests": {{ field.f_guests | to_int | json }}
}

```

### Custom headers

Under `Advanced` you can add headers, one per line as `Name: value`. Merge tags are allowed here too.

### Capture from response

You may store parts of the API response as outputs. Define an output key and the path in the response — if your API responds with `{ "data": { "id": 123 } }`, a capture of `order_id
