i'm trying send post message square create item
var postdata = { "name": "milkshake", "variations": [ { "name": "small", "pricing_type": "fixed_pricing", "price_money": { "currency_code": "usd", "amount": 400 } } ]} request.post({ uri:"https://connect.squareup.com/v1/me/items", headers:{'authorization': 'bearer ' + access_token, 'accept': 'application/json', 'content-type': 'application/json'}, body: querystring.stringify(postdata) },function(err,res,body){ console.log(res.statuscode); console.log(body); });
but receive message square
{"type":"bad_request","message":"invalid json"}
you're getting error because used querystring.stringify
, produces url encoded request body. want json.stringify
produce json encoded body. i.e:
request.post({ uri:"https://connect.squareup.com/v1/me/items", headers:{'authorization': 'bearer ' + access_token, 'accept': 'application/json', 'content-type': 'application/json'}, body: json.stringify(postdata) },function(err,res,body){ console.log(res.statuscode); console.log(body); });
Comments
Post a Comment