Monica
Log in
API v1
v1
View as Markdown

Preview a change of template

GET QUERY /api/v1/vaults/{vault}/contacts/{contact}/template-preview

Say what putting a contact on another template would do, without changing anything.

Call this before PUT /vaults/{vault}/contacts/{contact}/template and show the result to the person: it lists the answers that would go to Unused answers, the answers that would come back, and the reminders that would stop or run again. The change then does exactly what the preview says.

An answer follows the matching field of the new version, which is the field with the same key and type in the same section, or failing that the one such field anywhere else in the version. An answer without one is set aside, never deleted.

An answer or a reminder in a sensitive field is named only to a key holding the sensitive fields scope, because naming the field says that the contact has an answer there. Otherwise it is counted in hidden_count.

This endpoint answers GET and QUERY alike, and both return the same answer. GET sends the parameters in the address, QUERY in the request body. How QUERY works.

Parameters

Path parameters go in the address. GET sends the others in the address too, QUERY sends them as JSON in the request body. Anything not listed here is ignored.

vault string Required

The vault the contact lives in, named either by the readable name it reports as slug or by its id. Both answer.

contact string Required

The contact, named either by the readable name it reports as slug or by its id. Both answer. A readable name is rebuilt whenever the record is renamed, and the previous one stops answering, so a client that stores a reference stores the id. A name a record has released is never given to another. The contact has to be in the vault the path names: a contact of yours addressed through the wrong vault answers 404, the same as one that never existed. A contact absorbed by a merge answers 404 here, and the merge endpoints say what became of them.

template string Required

The id of the template to preview, as GET /templates gives it.

structure_version_id integer Optional

A published version of that template. Leave it out to preview what the template publishes now.

Returns

What the change would do. Nothing is written. A vault, a contact or a template of another account answers 404, and so does a version that is not in your account. A template that describes another kind of record, is turned off, or has no published version, and a version that is not a published version of that template, each answer 422 with the reason on template.

data object

What the change would do.

data.type string

Always template_change_preview.

data.attributes object

Everything the preview says.

data.attributes.is_change boolean

False when the contact already uses that version, in which case every list is empty and the change would do nothing.

data.attributes.from object

The version the contact uses now.

data.attributes.from.template string

The id of its template. Null when that template was deleted.

data.attributes.from.template_name string

What its template is called. Null when that template was deleted.

data.attributes.from.structure_version_id integer

The id of the version.

data.attributes.from.version_number integer

Its number within its template, counting from 1.

data.attributes.to object

The version the contact would use.

data.attributes.to.template string

The id of its template.

data.attributes.to.template_name string

What its template is called.

data.attributes.to.structure_version_id integer

The id of the version, which is what the change takes as structure_version_id.

data.attributes.to.version_number integer

Its number within its template, counting from 1.

data.attributes.set_aside array

The fields whose answers would go to Unused answers, because the new version has no matching field. Nothing is deleted. An empty list when none would.

data.attributes.set_aside[] object

One field.

data.attributes.set_aside[].field_id integer

The id of the field the answers sit in now.

data.attributes.set_aside[].label string

What the field is called.

data.attributes.set_aside[].section string

The section the field belongs to.

data.attributes.set_aside[].count integer

How many answers of the contact it holds, more than one for a field repeated in a block.

data.attributes.brought_back array

The fields whose answers were set aside earlier and would come back, because the new version has a place for them. Same shape as set_aside.

data.attributes.brought_back[] object

One field.

data.attributes.brought_back[].field_id integer

The id of the field the answers sit in now.

data.attributes.brought_back[].label string

What the field is called.

data.attributes.brought_back[].section string

The section the field belongs to.

data.attributes.brought_back[].count integer

How many answers of the contact it holds.

data.attributes.reminders_stopped array

The reminders that would stop, because the date they run on would go to Unused answers.

data.attributes.reminders_stopped[] object

One reminder.

data.attributes.reminders_stopped[].id string

The id of the reminder.

data.attributes.reminders_stopped[].label string

What the reminder is called.

data.attributes.reminders_restarted array

The reminders that would run again, because the date they run on would come back.

data.attributes.reminders_restarted[] object

One reminder.

data.attributes.reminders_restarted[].id string

The id of the reminder.

data.attributes.reminders_restarted[].label string

What the reminder is called.

data.attributes.hidden_count integer

How many answers and reminders in sensitive fields the lists leave out, because the key does not hold the sensitive fields scope. Always 0 for a key that holds it.

Status codes

Every code the API answers with, and what the body holds when it does.

Code When Body
422 Unprocessable Content With QUERY, a parameter was sent both in the address and in the body. A message, and an errors object naming each parameter sent twice.

Rate limit

Sixty requests per minute, per user, shared by every key and device. Every answer carries the budget left in X-RateLimit-Remaining.

GET
curl https://my.monicahq.com/api/v1/vaults/9d4f1c2e-7b3a-4f88-9a2d-6c1e5b0f7a31/contacts/c4a1f7b2-8e36-4d59-b0a7-2f5c9d81e364/template-preview?template=8b3c2d1e-4f5a-4b6c-9d7e-0f1a2b3c4d5e?template=8b3c2d1e-4f5a-4b6c-9d7e-0f1a2b3c4d5e \
-H "Authorization: Bearer $MONICA_TOKEN"
const response = await fetch('https://my.monicahq.com/api/v1/vaults/9d4f1c2e-7b3a-4f88-9a2d-6c1e5b0f7a31/contacts/c4a1f7b2-8e36-4d59-b0a7-2f5c9d81e364/template-preview?template=8b3c2d1e-4f5a-4b6c-9d7e-0f1a2b3c4d5e?template=8b3c2d1e-4f5a-4b6c-9d7e-0f1a2b3c4d5e', {
headers: { Authorization: `Bearer ${token}` },
})
const data = await response.json()
$response = Http::withToken($token)->get('https://my.monicahq.com/api/v1/vaults/9d4f1c2e-7b3a-4f88-9a2d-6c1e5b0f7a31/contacts/c4a1f7b2-8e36-4d59-b0a7-2f5c9d81e364/template-preview?template=8b3c2d1e-4f5a-4b6c-9d7e-0f1a2b3c4d5e?template=8b3c2d1e-4f5a-4b6c-9d7e-0f1a2b3c4d5e');
QUERY
curl https://my.monicahq.com/api/v1/vaults/9d4f1c2e-7b3a-4f88-9a2d-6c1e5b0f7a31/contacts/c4a1f7b2-8e36-4d59-b0a7-2f5c9d81e364/template-preview?template=8b3c2d1e-4f5a-4b6c-9d7e-0f1a2b3c4d5e \
-X QUERY \
-H "Authorization: Bearer $MONICA_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"template": "8b3c2d1e-4f5a-4b6c-9d7e-0f1a2b3c4d5e"
}'
const response = await fetch('https://my.monicahq.com/api/v1/vaults/9d4f1c2e-7b3a-4f88-9a2d-6c1e5b0f7a31/contacts/c4a1f7b2-8e36-4d59-b0a7-2f5c9d81e364/template-preview?template=8b3c2d1e-4f5a-4b6c-9d7e-0f1a2b3c4d5e', {
method: 'QUERY',
headers: { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json' },
body: JSON.stringify({
template: '8b3c2d1e-4f5a-4b6c-9d7e-0f1a2b3c4d5e',
}),
})
const data = await response.json()
$response = Http::withToken($token)->query('https://my.monicahq.com/api/v1/vaults/9d4f1c2e-7b3a-4f88-9a2d-6c1e5b0f7a31/contacts/c4a1f7b2-8e36-4d59-b0a7-2f5c9d81e364/template-preview?template=8b3c2d1e-4f5a-4b6c-9d7e-0f1a2b3c4d5e', [
'template' => '8b3c2d1e-4f5a-4b6c-9d7e-0f1a2b3c4d5e',
]);
Response 200
{
"data": {
"type": "template_change_preview",
"attributes": {
"is_change": true,
"from": {
"template": "3e7a1c9b-2d4f-4a6e-8b0c-5f9d1e3a7c2b",
"template_name": "Default contact",
"structure_version_id": 4,
"version_number": 2
},
"to": {
"template": "8b3c2d1e-4f5a-4b6c-9d7e-0f1a2b3c4d5e",
"template_name": "Colleague",
"structure_version_id": 11,
"version_number": 1
},
"set_aside": [
{
"field_id": 52,
"label": "Favourite artist",
"section": "Information",
"count": 1
}
],
"brought_back": [
{
"field_id": 37,
"label": "Work anniversary",
"section": "Work",
"count": 1
}
],
"reminders_stopped": [
{
"id": "2f9c4b7e-1a3d-4e6f-8b0c-7d5a9e1f3c2b",
"label": "Pam’s gallery opening"
}
],
"reminders_restarted": [
{
"id": "6a1d3f8c-9b2e-4c7a-a5d0-3e8f1b4c9d27",
"label": "Pam’s work anniversary"
}
],
"hidden_count": 0
}
}
}

Keys act as you, with exactly the access you have. Make one per integration so you can revoke it alone.