Data API: Writing records
This article explains how to create, change and delete records with the Xpoda Data API. Paths are relative to the base URL https://{your-xpoda-service}/api/v1/{moduleId}.
Endpoints
| Request | Does | Success |
|---|---|---|
POST /forms/{form}/records | Creates a record. | 201, the saved record, Location and ETag |
PATCH /forms/{form}/records/{id} | Changes only the fields in the body. | 200, the saved record and its new ETag |
PUT /forms/{form}/records/{id} | Replaces the record: writable fields left out are cleared. | 200, the saved record and its new ETag |
DELETE /forms/{form}/records/{id} | Deletes the record and its lines. | 204, no body |
The key needs the Create, Update or Delete permission for the form, and the API user must be allowed the same on the form. GET /forms shows what the key may do.
How a write is processed
A write is saved by the same code that saves the form screen in the Xpoda Client, so the form behaves the same way:
- The body is checked against the form's fields: unknown fields, wrong types, text that is too long, read-only fields and missing required values are refused with
422 validation_failed, and nothing is saved. - For an update or delete, the
If-Matchheader is compared with the record's current version. - The form's Record Control rules for Before save (or Before delete) run. A rule that refuses the change gives
422 action_rejected, with the rule's message indetail. - The record is saved in one database transaction, together with its grid lines.
- After save actions (integrations, e-mails) run, as they do after saving on the form screen.
- The response returns the record as it is now in the database, including anything the actions changed.
If any step fails, nothing is saved.
Create a record
POST /forms/stock-items/records
Content-Type: application/json
Idempotency-Key: 6f1c2b8e-2d4a-4a0e-9a57-1f0c7c5d9e21
{
"Code": "B-200",
"Name": "Steel bolt M8",
"Price": 120.5
}
HTTP/1.1 201 Created
Location: /api/v1/7/forms/stock-items/records/3
ETag: W/"639286201022270000"
{ "id": 3, "Code": "B-200", "Name": "Steel bolt M8", "Price": 120.5, "_meta": { ... } }
- Fields you leave out get the form's default empty value.
idand_metain the body are ignored, so you can send back a record you read.createdByandupdatedByare the API user.
Retry safely with Idempotency-Key
If the connection drops after a POST, you cannot know whether the record was created. Send an Idempotency-Key header with a unique value (a new GUID per record) and retry with the same key and the same body:
- If the first request succeeded, the retry returns the same record with
201and the headerIdempotent-Replayed: true; no second record is created. - The same key with a different body gives
422 idempotency_key_reused. - While the first request is still running, a retry gets
409 request_in_progress.
Keys are remembered for 24 hours.
Change a record
Updates and deletes must say which version of the record they are based on. Read the record first, then send its ETag in If-Match:
GET /forms/stock-items/records/3
ETag: W/"639286201022270000"
PATCH /forms/stock-items/records/3
Content-Type: application/json
If-Match: W/"639286201022270000"
{ "Price": 99.9 }
- Without
If-Matchyou get428 precondition_required. - If someone saved the record after you read it, you get
412 precondition_failedand nothing is changed. Read the record again, apply your change to the new version, and retry with the new ETag. - The response carries the new ETag, so you can make another change without reading again.
If-Match: *skips the version check. Use it only when overwriting other people's changes is acceptable.
PATCH or PUT
- PATCH changes only the fields in the body. Use it in almost every case.
- PUT replaces the record: every writable field missing from the body is cleared, and on a form with a grid, leaving out
linesdeletes all lines. Use it only when your system holds the complete record.
To clear a single field with PATCH, send it as null.
Delete a record
DELETE /forms/stock-items/records/3
If-Match: W/"639286201045330000"
HTTP/1.1 204 No Content
Deleting removes the record, its grid lines, its attached files and records linked to it through additional forms, as deleting on the form screen does. The form's Before delete Record Control rules run first. If-Match is required, as for updates.
Values
| Field type | Send | Empty value (null) is stored as |
|---|---|---|
| Text | "text", at most maxLength characters | empty text |
| Whole number | 42 | 0 |
| Decimal | 12.5 (a JSON number, never a string) | 0 |
| Yes / no | true or false | false |
| Date / date-time | "2026-10-26" or "2026-10-26T14:30:00" | the empty date of Xpoda (1899-12-30) |
The empty values are the ones the form screen stores when a field is left blank.
- Dates without a time zone are taken as the Xpoda server's local time. A date with a time zone (
2026-10-26T11:30:00Z) is converted to the server's local time. - File, image and signature fields cannot be written through the API.
What is not run
The API does not run what happens only in the browser on the form screen: field formulas, on change queries, default values filled by the screen, and screen-side checks other than Record Control. If a field is calculated on the screen, calculate it in your system and send it.
Examples
cURL
curl -i -X POST "$BASE/forms/stock-items/records" -H "Authorization: Bearer $XPODA_API_KEY" -H "Content-Type: application/json" -H "Idempotency-Key: $(uuidgen)" -d '{"Code": "B-200", "Name": "Steel bolt M8", "Price": 120.5}'
curl -i -X PATCH "$BASE/forms/stock-items/records/3" -H "Authorization: Bearer $XPODA_API_KEY" -H "Content-Type: application/json" -H 'If-Match: W/"639286201022270000"' -d '{"Price": 99.9}'
curl -i -X DELETE "$BASE/forms/stock-items/records/3" -H "Authorization: Bearer $XPODA_API_KEY" -H 'If-Match: W/"639286201045330000"'
C# (.NET 6 or later)
using System.Net.Http.Headers;
using System.Net.Http.Json;
using System.Text.Json;
var http = new HttpClient { BaseAddress = new Uri("https://service.example.com/api/v1/7/forms/stock-items/") };
http.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Bearer", Environment.GetEnvironmentVariable("XPODA_API_KEY"));
// Create
var create = new HttpRequestMessage(HttpMethod.Post, "records")
{
Content = JsonContent.Create(new { Code = "B-200", Name = "Steel bolt M8", Price = 120.5 })
};
create.Headers.Add("Idempotency-Key", Guid.NewGuid().ToString());
var created = await http.SendAsync(create);
created.EnsureSuccessStatusCode();
var id = JsonDocument.Parse(await created.Content.ReadAsStringAsync()).RootElement.GetProperty("id").GetInt32();
// Change, based on the version just saved
var patch = new HttpRequestMessage(HttpMethod.Patch, $"records/{id}")
{
Content = JsonContent.Create(new { Price = 99.9 })
};
patch.Headers.IfMatch.Add(created.Headers.ETag!);
var updated = await http.SendAsync(patch);
updated.EnsureSuccessStatusCode();
// Delete
var delete = new HttpRequestMessage(HttpMethod.Delete, $"records/{id}");
delete.Headers.IfMatch.Add(updated.Headers.ETag!);
(await http.SendAsync(delete)).EnsureSuccessStatusCode();
JavaScript (Node.js 18 or later)
const BASE = 'https://service.example.com/api/v1/7/forms/stock-items';
const auth = { Authorization: `Bearer ${process.env.XPODA_API_KEY}` };
async function call(path, { method = 'GET', body, etag, idempotencyKey } = {}) {
const headers = { ...auth };
if (body) headers['Content-Type'] = 'application/json';
if (etag) headers['If-Match'] = etag;
if (idempotencyKey) headers['Idempotency-Key'] = idempotencyKey;
const res = await fetch(`${BASE}/${path}`, { method, headers, body: body && JSON.stringify(body) });
if (res.status === 204) return null;
const data = await res.json();
if (!res.ok) throw new Error(`${res.status} ${data.code}: ${data.detail} ${JSON.stringify(data.errors ?? '')}`);
return { ...data, etag: res.headers.get('ETag') };
}
const created = await call('records', {
method: 'POST',
body: { Code: 'B-200', Name: 'Steel bolt M8', Price: 120.5 },
idempotencyKey: crypto.randomUUID()
});
const updated = await call(`records/${created.id}`, { method: 'PATCH', body: { Price: 99.9 }, etag: created.etag });
await call(`records/${created.id}`, { method: 'DELETE', etag: updated.etag });
Troubleshooting
| You get | Check |
|---|---|
403 scope_missing | Tick the permission for the form in the key's Permissions in Studio. |
403 form_authority | The API user's form authorities forbid adding, changing or deleting on this form. |
422 validation_failed with "read-only" | The API user may not change that field (field authority cannot change). |
422 action_rejected | A Record Control rule refused it; the rule's message is in detail. |
422 save_rejected | The database or the form's save refused the record, for example a required column that was left empty. detail has the message. |
412 on every update | Send the ETag of the latest read or write, exactly as received, including W/ and the quotes. |