Method "" not found in WebAPI call

So, I'm building my scripts to communicate with LimeLM WebAPI with NodeJS. I am using Express to easily setup the app. For one of my routes, I want to retrieve all the product keys (serials) that are associated with an email address. So, here is my code thus far for this particular route:

var express = require('express');var router = express.Router();var limelm_key = '<my secret api key>';var limelm_format = 'json';var https = require('https');var qstring = require('querystring');

router.get('/:email', function(req, res, next) {

console.log('Make a call to LimeLM endpoint with API Key: ' + limelm_key); console.log('Retrieving the keys associated with the email:' + req.params.email);

var post_data = qstring.stringify({ api_key : limelm_key, method : "limelm.pkey.find", version_id : <my version int>, email : req.params.email, format : limelm_format }); var req_opt = { host: "wyday.com", method: "POST", path: "/limelm/api/rest/", headers : { 'Content-Type' : 'application/x-www-form-urlencoded', 'Content-Length': Buffer.byteLength(post_data.length) } }

var success_callback = function(response) { console.log("Successfully called LimeLM servers!"); response.on('data', function(d) { process.stdout.write(d); }); }; console.log("Starting request to find a key using data -->"); console.log(post_data); var lime_post = https.request(req_opt, success_callback); lime_post.write(post_data); lime_post.on('error', function(e){console.error(e.stack)}); lime_post.end();});

The output generated when I hit this route is the following:

Make a call to LimeLM endpoint with API Key: <my secret api key>Retrieving the keys associated with the email: <email parameter from the get to my server>Starting request to find a key using data -->api_key=<my secret api key>&method=limelm.pkey.find&version_id=<my version id>&email=test%40somedomain.com&format=jsonSuccessfully called LimeLM servers!<?xml version="1.0" encoding="utf-8"?><rsp stat="fail"><err code="101" msg="Method &quot;&quot; not found"/></rsp>

Clearly, the method is there in the query string that I write, but am not certain as to why LimeLM servers are returning that it cannot find it. Any tips?

Thanks,Arie

hey Arie,

From what it sounds like the LimeLM servers are never getting the POSTed data. So my guess is that whatever function you're using to write the data is not writing it in the "application/x-www-form-urlencoded" form. You might need to use "multipart/form-data" based on the way you're POSTing data.

http://stackoverflow.com/questions/14551194/how-are-parameters-sent-in-an-http-post-request

So it turned out to be the headers I was setting on the request options object:

So this is how I had it:

var req_opt = { host: "wyday.com", method: "POST", path: "/limelm/api/rest/", port: 443, headers : { 'Content-Type' : 'application/x-www-form-urlencoded', 'Content-Length': Buffer.byteLength(post_data.length) } };

But apparently the Content-Length header was wrong because of the .length property. That is not needed since the .byteLength method of the Buffer object calculates that for us. So all I had to do was change that header to:

'Content-Length' : Buffer.byteLength(post_data);

Now I'm seeing the response come back as json, but I'm not sure how to deal with it because it comes back in the format of:

jsonLimeLMapi({json here})

I thought it would just come back as a string that started with an open-brace and end with a closing-brace, so I'm not sure about how it is expected to handle this type of response when we set the format to json. Any ideas?

Ah, just found the nojsoncallback switch at the way bottom of this article:http://wyday.com/limelm/help/api/response.json/

Now, I can begin building out the scripts I need to get data to my app.

Thanks,Arie