Create multiple metafields (aka flock)
Send several metafields in one request, all-or-nothing.
Before you start
Sending a flock
async function submitFlock() {
var colour = window.FR_CUSTOMER_FAVOURITE_COLOUR; // from the Get Code panel
var size = window.FR_CUSTOMER_SHIRT_SIZE;
var score = window.FR_CUSTOMER_LOYALTY_SCORE;
var entry = function (cfg, value) {
return { raven_id: cfg.ravenId, resource_id: cfg.resourceId, raven_mac: cfg.ravenMac, value: value };
};
var res = await fetch('/apps/raven/create_multiple_metafields', {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
flock: [
entry(colour, 'blue'),
entry(size, 'M'),
entry(score, 42)
]
})
});
if (res.status === 429) return console.warn('Busy — retry shortly.');
var data = await res.json().catch(function () { return {}; });
if (!res.ok) return console.error(data.message || 'Flock rejected.');
console.log(data.message); // "Sit tight the raven is on it!"
}Last updated