I'm looking at implementing Summry, and they only give PHP API connection examples - is there any chance someone could turn it into a JS request for me?
I essentially just want it to parse the text I give it, nothing super fancy yet.
I've tried to see what CURLOPT_POSTFIELDS, and CURLOPT_HTTPHEADER match to in a JS request, to no avail. I'm probably looking in the wrong place, however.
PHP example
$long_article = "Long article text goes here";
$ch = curl_init("http://api.smmry.com/&SM_API_KEY=XXXXXXXXX&SM_LENGTH=14&SM_WITH_BREAK");
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Expect:")); // Important do not remove
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, "sm_api_input=".$long_article);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
$return = json_decode(curl_exec($ch), true);
curl_close($ch);
JavaScript replication
...
const request = require('request-promise');
...
const long_article = 'Long article text goes here';
const r = request({
method: 'POST',
uri: `http://api.smmry.com/&SM_API_KEY=${process.env.SMMRY_API_KEY}`,
// headers: { Authorization: 'array(Expect:)' },
// body: { sm_api_input: long_article },
json: true,
});
request(r)
.then((parsedBody) => { debug(parsedBody); })
.catch((err) => { debug(err); });
The error I'm getting is { sm_api_error: 1, sm_api_message: 'INSUFFICIENT VARIABLES' } so I'm atleast hitting the right URL - so that's a start :)
Thanks in advance!
Ollie