How to make a correct HTTP Post request with Meteor.js to Domino Datalab's Rest API
Question: In my server side Meteor.js method, I'm trying to correctly make a request to
Domino Data Lab's (DDL) Rest API.

DDL provides a platform for makes it possible to call a data science model via
a REST API. Their documentation on this API is here:

<http://support.dominodatalab.com/hc/en-us/articles/204173149-API-Endpoints-
Model-Deployment>

But, I doubt the documentation is helpful because I think an experienced
Meteor developer will see the request examples in CURL or Python and know how
to get the params correctly into the JSON format that DDL is looking for.

Domino Datalab provides the instructions for 4 methods, but not for Meteor.js.
I'll post the examples for Curl and Python:

**Examples**

_CURL Request_

    
    
    curl -v -X POST \
    https://app.dominodatalab.com/MYURL \
    -H 'Content-Type: application/json' \
    -H 'X-Domino-Api-Key: YOUR_API_KEY' \
    -d '{"parameters": [ "FOO", "BAR", "ETC"]}'
    

_Python Request_

    
    
    import requests
    
    response =        
    requests.post("https://app.dominodatalab.com/MYURL",
    headers = {
        "X-Domino-Api-Key": "YOUR_API_KEY",
        "Content-Type": "application/json"
    },
    json = {
        "parameters": ["FOO", "BAR", "ETC"]
    }
    )
    print(response.status_code)
    print(response.headers)
    print(response.json())
    

I've tried a few different ways (using both the `data`and `params`options)
based on the documentation for Meteor, but here is my best try:

    
    
    Meteor.methods({
        score_app:  function(){
            var test = HTTP.call("POST", "https://app.dominodatalab.com/MYURL",
                {   headers:  {     
                            "Content-Type": "application/json",
                            "X-Domino-Api-Key": "YOUR_API_KEY"              
            },
            // This is where the problem is.  Have tried multiple syntax versions and tried using the `params`options for the HTTP call instead of `data`
            data: {'params': [143]
            }
            },
        function (error, result) {
    
        // The syntax below should be if not an error, log the result (for testing etc, otherwise, log "http post error".  I may have incorrectly switched this around, but the original version I got from an online example had it the console.log statements in the reverse order.
        if (!error) {
            console.log(result);
        } else{
    
            console.log("http post error");
        };
        });
        }
    });
    

I've been using this entry in the Meteor documentation to send the parameters
as a JSON object correctly: <http://docs.meteor.com/api/http.html>

The connection to Data Domino Lab (DDL) is made correctly, but it doesn't
recognize the parameters correctly because the request is not sending the
parameters in the JSON format that DDL wants.

    
    
    result: 'You must provide a JSON object in your request body 
    with a parameters key containing an array of parameters.' } }
    

I'm on the DDL free plan, but I will email a link to this question to their
tech support. This is a niche issue, but it could be important to Meteor.js
developers in the future wishing to link to a data science model in DDL.


Answer: I'm one of the engineers at Domino who has worked on the API Endpoints feature
recently. The error message you're getting means that the JSON object you're
sending to our server doesn't contain the key "parameters". I'm not an expert
in Meteor, but it looks like you're using "params" where you should use
"parameters" in your JSON payload. Around line 9 can you change...

    
    
    {'data': {'params': [143]}}
    

to

    
    
    {'data': {'parameters': [143]}}
    

If my understanding of your code is correct, that'll work correctly.

Cheers!

