1
votes

I am trying to get the sentiment of a piece of text using th AlchemyAPI in my meteor application. I am using HTTP.call with 'POST' as recommended by the API to make a server to server call, but I am getting an 'invalid-api-key' response.

var alchemyURL = Meteor.settings.alchemyUrl;
var postData = {
  'apikey': Meteor.settings.alchemyUrl,
  'text': txt,
  'outputMode': 'json'
};
var options = {
  data: postData
};

var sentimentData = HTTP.call('POST', alchemyURL, options);

console.log(sentimentData);

I have discovered the answer, to this hence posting it in below.

1

1 Answers

3
votes

So turns out, Meteor's HTTP package needs to be given the headers for implementing form url-encoding on the data. Also the data object needs to be passed in 'params' and not in 'data' The correct snippet to be used is given below.

var alchemyURL = Meteor.settings.alchemyUrl;
var postData = {
  'apikey': Meteor.settings.alchemyUrl,
  'text': txt,
  'outputMode': 'json'
};
var options = {
  params: postData,
  headers: {
    'Content-Type': 'application/x-www-form-urlencoded'
  } 
};

var sentimentData = HTTP.call('POST', alchemyURL, options);

console.log(sentimentData);