Ruby POST request with JSON body -
i trying write post request in ruby api published via microsoft machine learning studio. returning error 400 following:
require 'unirest' require 'json' uri = "https://ussouthcentral.services.azureml.net/workspaces/a0e65d42d21c423fa4027d98f6ad364f/services/0d797f1b26d4410cae35c50d25d1c7cd/execute?api-version=2.0&details=true" apikey = "some api key" params = {some json body} response = unirest.post(uri, headers: {"content_length" =>"235", "content-type" => "application/json", "authorization" => "bearer" + " " + apikey}, parameters: params)
for life of me cannot figure out how structure request. according documentation:
authorization:bearer abc123
required. pass api key here. obtain key publisher of api.
content-length
required. length of content body.
content-type:application/json
required if request body sent in json format.
accept: application/json
optional. use header receive response in json format.
i'm not great ruby text editor doesn't seem when use : between header , value instead of =>.
the body need include in request if shown in documentation:
{ "inputs": {"input1": { "columnnames": [ "case number", "case type", "address", "description", "case group", "date case created", "last inspection date", "last inspection result", "status", "permit , complaint status url", "latitude", "longitude", "location" ], "values": [ [ "0", "value", "value", "value", "value", "", "", "value", "value", "value", "0", "0", "value" ], [ "0", "value", "value", "value", "value", "", "", "value", "value", "value", "0", "0", "value" ] ] } }, "globalparameters": {}}
everytime throw in editor , try run script kinds of errors. unexpected , expecting end, etc...
can please explain i'm doing wrong here?
try .to_json
after hash. i.e. {"content_length" =>"235"}.to_json
, params.to_json
Comments
Post a Comment