Reputation: 40163
I would like to convert this curl call:
curl -d "api_token=PUT_YOUR_API_KEY_HERE&api_action=subscription_datafeed" https://example.foxycart.com/api
To node using the request lib - https://github.com/mikeal/request but I am having issues getting the body sent. My curl call works fine but when I convert it I keep getting the same error about api_token and api_action missing. Here's what I tried:
var options = {
url: 'https://example.foxycart.com/api',
body: JSON.stringify({
api_token:'PUT_YOUR_API_KEY_HERE',
api_action:'subscription_datafeed'
}),
method: 'POST'
};
request(options, function (error, response, body) { });
Also:
var options = {
url: 'https://example.foxycart.com/api',
json: {
api_token:'PUT_YOUR_API_KEY_HERE',
api_action:'subscription_datafeed'
},
method: 'POST'
};
request(options, function (error, response, body) { });
Also this:
var options = {
url: 'https://example.foxycart.com/api',
body: '?api_token=PUT_YOUR_API_KEY_HERE&api_action=subscription_datafeed',
method: 'POST'
};
request(options, function (error, response, body) {
Also this:
var options = {
url: 'https://example.foxycart.com/api',
body: 'api_token=PUT_YOUR_API_KEY_HERE&api_action=subscription_datafeed',
method: 'POST'
};
request(options, function (error, response, body) {
And this:
request.post('https://example.foxycart.com/api?api_token=PUT_YOUR_API_KEY_HERE&api_action=subscription_datafeed', function (error, response, body) { });
Here's a PHP one that supposedly works for a similar call on same API - seems like I have the code correct but...
$foxy_domain = "myfoxydomain.foxycart.com";
$foxyData = array();
$foxyData["api_token"] = "XXXXX your api / datafeed key here XXXXXX";
$foxyData["api_action"] = "customer_save";
$foxyData["customer_id"] = "12345";
// OR use the email:
//$foxyData["customer_email"] = "[email protected]";
$foxyData["customer_password"] = "my new password";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://" . $foxy_domain . "/api");
curl_setopt($ch, CURLOPT_POSTFIELDS, $foxyData);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
Any ideas?
Upvotes: 0
Views: 1520
Reputation: 3241
Try:
var options = {
url: 'https://example.foxycart.com/api',
form: {
api_token:'PUT_YOUR_API_KEY_HERE',
api_action:'subscription_datafeed'
},
method: 'POST'
};
request(options, function (error, response, body) { });
Upvotes: 1