SparkPost / node-sparkpost

SparkPost client library for Node.js
https://www.sparkpost.com/
Other
180 stars 42 forks source link

templates.get broken with v > 2.1.0 #220

Closed joelabair closed 7 years ago

joelabair commented 7 years ago

The error returned is 'SyntaxError: Unexpected token u' When using the callback method.

"use strict";

var SparkPost = require('sparkpost');
var client = new SparkPost(); 
client.templates.get('my-id', function(err, res) {
    if (err) {
        console.error(err);
        return process.exit(1);
    } else {
        /* got it - continue */
    }
});
aydrian commented 7 years ago

Hi. I'm not getting the error. What version of node.js are you using?

joelabair commented 7 years ago

v4.8.4

aydrian commented 7 years ago

I first ran it with v6.11.2 and it worked. I also ran it with v4.8.4 and it also worked. I am using v2.1.2 of node-sparkpost.

joelabair commented 7 years ago

Ok - I'll try to isolate the environment more.

aydrian commented 7 years ago

Yeah. Maybe include a stack trace. Just let us know what you figure out.

joelabair commented 7 years ago

My Bad. I was parsing res elsewhere in the code and the key 'body' is undefined. JSON.parse(res.body) Obviously a change in the 2.1.x series.

Sorry for the fire alarm. Thanks for your help.

aydrian commented 7 years ago

Glad you were able to track it down. That was a change from 1.x to 2.x, the second argument is the data from the request. So it is res.body.