having trouble getting format right parse.cloud.httprequest deleting subscription at_period_end.
i able make request postman using x-www-form-urlencoded, key 'at_period_end' value true. (can't post screenshot due reputation sorry)
here cloud-code:
parse.cloud.httprequest({ method : 'delete', url : 'https://' + skey + ':@' + 'api.stripe.com/v1' + '/customers/' + request.params.customerid + '/subscriptions/' + request.params.subscriptionid, body : { "at_period_end": true }, success: function(httpresponse) { if (httpresponse.status === 200) { response.success(httpresponse); } else { response.error(httpresponse); } }, error: function(httpresponse) { response.error(httpresponse); } });
i have played around adding headers object content-type set, unsuccessful.
i think formatting translation issue correctly entered postman, in httprequest object...
i can't find great information on docs on httprequest method quite frustrating :(.
thanks heaps
***** edit ****** solution:
managed solve using url inline parameters:
var options = request.params.options, url = 'https://' + skey + ':@api.stripe.com/v1/customers/' + request.params.customerid + '/subscriptions/' + request.params.subscriptionid, keys; keys = object.keys(options); // disgusting, need know better way. (var = 0; < keys.length; i++) { if (i === 0) { url += '?'; } url += keys[i] + '=' + options[keys[i]]; if (i !== keys.length - 1) { url += '&'; } } parse.cloud.httprequest({ method : 'delete', url : url, success: function(httpresponse) { if (httpresponse.status === 200) { response.success(httpresponse); } else { response.error(httpresponse); } }, error: function(httpresponse) { response.error(httpresponse); } });
if show me better way write this, epic :)
cheers
this 1 has been particularly thorny me, here i've been using has worked:
parse.cloud.httprequest({ method: 'delete', url: 'https://api.stripe.com/v1/customers/' + request.params.stripeid + '/subscriptions/' + request.params.stripesubscriptionid, headers: { 'authorization': 'basic base_64_encode_secret_key' }, params: { at_period_end: true }, success: function(httpresponse) { ... }, error: function(httpresponse) { ... } });
a couple of details here.
- i had "content-type: application/json" 1 of headers, appears not correct, despite (i think) needing in past.
the base64 encode of key can generated with
echo -e 'sk_live_abcdef123456:' | openssl base64
don't forget colon (:) @ end of key, matters.
this detail however, , looks putting secret key directly in url working well.