Update template with options
giliteho opened this issue · 2 comments
When using the update(id, template[, options]) API with some options object (modifying open_tracking, click_tracking, transactional) the options fields are not updated.
But when we try the same API directly with SparkPost (not using the API node.js client) data is updated correctly.
expamle of a call:
let template = { name : data.name, content: { html: data.html, from : somemail@mail.com, subject : subject }, description: data.description }; let options = { open_tracking: false, click_tracking: false, transactional: true, update_published: true }; let result = await client.templates.update(templateId, template, options); return result;
template fields are updated, but the option fields stay the same.
Hey @giliteho, thanks for reporting this. It looks like the templates update method sets the options param as the query string for the request, I think this might be a library wide convention.
The options object you defined has both template options and a query string param option. To get the expected behavior, set the template options on the template
object you defined, and leave the query string option (update_published
) in the options object you defined, like so:
let template = {
name : data.name,
content: { html: data.html, from : somemail@mail.com, subject : subject },
description: data.description,
options: {
open_tracking: false,
click_tracking: false,
transactional: true
}
};
let options = { update_published: true };
let result = await client.templates.update(templateId, template, options);
return result;
Let me know if this helps!
Also, I see that the templates examples do not have an case showing this confusing situation, so we'll get that updated ASAP.