javascript - Using request HTTP client library to post to FastSpring API -


i attempting use request post fastspring's api updating subscriptions customers. able subscriptions without problem, when comes post, cannot seem work.

here code:

      var options = {            method: 'post',            url: 'https://api.fastspring.com/subscriptions',            headers: {                'authorization': auth,                'user-agent': 'request',                'content-type': 'application/json'            },            formdata : {                'subscriptions': [                    {                        "subscription": subscriptionid,                        "quantity": newqty,                        "product": product,                        "prorate": true                    }                ]            }                    };                   request.post(options, function (error, response, body) {            _logger.error('fastspring api response: ' + json.stringify(response));            _logger.error('fastspring api error: ' + json.stringify(error));            _logger.error('fastspring api body: ' + json.stringify(body));            if (!error && response.statuscode === 200) {                res.status(200).send(json.parse(body));            } else {                _logger.error('fastspring api error: ' + error);                res.status(500).send({ 'error':  error});            }        });

the result of attempting post results in following error:

typeerror: source.on not function 

i looked , saw reason why failing request cannot accept formdata i'm sending. problem without it, cannot post fastspring's api (i error message "subscriptions not found." if send else).

my question this: can send formdata in way accepted request? i've looked issue on issues page of request , couldn't find satisfactory answer.

are trying pass json data? kind of data written in body not in formdata.

try this:

var myreq = request.post(...) myreq.write(myjsondata); myreq.end(); 

Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -