2

I have a meteor application hosted on modulus.

Modulus has an api here: https://api.modulus.io/

The API code is hosted here: https://github.com/onmodulus/modulus-cli/blob/master/lib/librarian/librarian.js#L361

I want to save a domain to one of my deployments on modulus through the API.

I know this is the code I am looking to connect to: https://github.com/onmodulus/modulus-cli/blob/master/lib/librarian/librarian.js#L361

librarian.project.saveDomains = function(projectId, domains, authToken, callback) { if(checkInit(callback)) { librarian._http.request(util.format('/project/%s/domains?authToken=%s', projectId, authToken), 'POST', domains, callback); } };

And I am new to making API calls.

I believe I need to make the call from the server in my meteor app, which could be handled using a meteor method, but I don't know what the API call should look like.

I've researched online and on SO. No luck and I am battling a lack of experience with API calls so I am looking from a little direction.

I've added the http package for meteor:

meteor add http

I think the following is in the ball park, but not currently working:

POST javascript //save arguments object to options variable var options = { projectId: xxx, domains: ["example.com"], authToken: settings.Modulus.authToken } //call meteor method from client Meteor.call('saveDomainToModulus', options, function(error, result) { if (error) console.log(error) else console.log(result) } }); //on server Meteor.methods({ "saveDomainToModulus": function(options) { var apiEndpoint = "http://api.modulus.io/project/%s/domains?authToken=" + options.authToken; HTTP.post( apiEndpoint, options.projectId, options.domains, options.authToken, function( error, response ) { if ( error ) { console.log( error ); } else { console.log( response ); } }); } })

Feels like I'm starting to close in on a solution, but if anyone with more experience has any feedback, let me know.

Brian McDonough
  • 13,829
  • 4
  • 19
  • 23
  • Appears that the key to making this work lies in wrapAsync: http://stackoverflow.com/questions/26226583/meteor-proper-use-of-meteor-wrapasync-on-server. Still working on it. Any light shed is welcome – Brian McDonough Jan 07 '16 at 00:54
  • 3
    Possible duplicate of [How to make an API call using meteor](https://stackoverflow.com/questions/14320610/how-to-make-an-api-call-using-meteor) – Kyll Jul 10 '17 at 08:52

0 Answers0