Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update template with options #227

Closed
giliteho opened this issue Nov 29, 2017 · 2 comments
Closed

Update template with options #227

giliteho opened this issue Nov 29, 2017 · 2 comments
Labels

Comments

@giliteho
Copy link

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.

@jgzamora
Copy link
Contributor

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.

@giliteho
Copy link
Author

thanks @jgzamora ! it works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants