Request Response API Documentation for RiskModel [Predictive Exp.]

Updated: 01/10/2017 08:50

No description provided for this web service.

Request

Method Request URI HTTP Version

POST

https://ussouthcentral.services.azureml.net/workspaces/0769e412b3944b9e8fed479bb8905c1e/services/02880fc6ed4b439d9099e41c877735d7/execute?api-version=2.0&details=true

HTTP/1.1

Note: You may omit the details parameter from the query string. This would cause ColumnTypes to be omitted from the output

Request Headers

Request Header Description

Authorization:Bearer abc123

Required. Pass the API Key here. Obtain this key from the publisher of the API.

Content-Length

Required. The length of the content body.

Content-Type:application/json

Required if the request body is sent in JSON format.

Accept: application/json

Optional. Use the header to receive the response in JSON format.

Request Body

Sample Request

{
  "Inputs": {
    "input1": {
      "ColumnNames": [
        "Col1",
        "Col2",
        "Col3",
        "Col4",
        "Col5",
        "Col6",
        "Col7",
        "Col8",
        "Col9",
        "Col10",
        "Col11",
        "Col12",
        "Col13",
        "Col14",
        "Col15",
        "Col16",
        "Col17",
        "Col18",
        "Col19",
        "Col20",
        "Col21"
      ],
      "Values": [
        [
          "value",
          "0",
          "value",
          "value",
          "0",
          "value",
          "value",
          "0",
          "value",
          "value",
          "0",
          "value",
          "0",
          "value",
          "value",
          "0",
          "value",
          "0",
          "value",
          "value",
          "0"
        ],
        [
          "value",
          "0",
          "value",
          "value",
          "0",
          "value",
          "value",
          "0",
          "value",
          "value",
          "0",
          "value",
          "0",
          "value",
          "value",
          "0",
          "value",
          "0",
          "value",
          "value",
          "0"
        ]
      ]
    }
  },
  "GlobalParameters": {}
}

Response

Status Code

A successful operation returns status code 200 (OK)

For information about error codes, see Common REST API Errors Codes

Response Headers

The response may include standard HTTP headers. All standard headers conform to the HTTP/1.1 protocol specification

Response Header Description

Content-Type:application/json

Indicates that the content body is in json format.

Response Body

Sample Response

{
  "Results": {
    "output1": {
      "type": "DataTable",
      "value": {
        "ColumnNames": [
          "Scored Labels",
          "Scored Probabilities"
        ],
        "ColumnTypes": [
          "Numeric",
          "Numeric"
        ],
        "Values": [
          [
            "0",
            "0"
          ],
          [
            "0",
            "0"
          ]
        ]
      }
    }
  }
}

Input Parameters

Input name: input1

Input type: DataTable

Input columns:

Name Type Description Allowed values

Col1

String

Col2

Numeric

Col3

String

Col4

String

Col5

Numeric

Col6

String

Col7

String

Col8

Numeric

Col9

String

Col10

String

Col11

Numeric

Col12

String

Col13

Numeric

Col14

String

Col15

String

Col16

Numeric

Col17

String

Col18

Numeric

Col19

String

Col20

String

Col21

Numeric


Output Parameters

Output name: output1

Output type: DataTable

Output columns:

Name Type Description Allowed values

Scored Labels

Numeric

Scored Probabilities

Numeric


Sample Code

// This code requires the Nuget package Microsoft.AspNet.WebApi.Client to be installed.
// Instructions for doing this in Visual Studio:
// Tools -> Nuget Package Manager -> Package Manager Console
// Install-Package Microsoft.AspNet.WebApi.Client

using System;
using System.Collections.Generic;
using System.IO;
using System.Net.Http;
using System.Net.Http.Formatting;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;

namespace CallRequestResponseService
{

    public class StringTable
    {
        public string[] ColumnNames { get; set; }
        public string[,] Values { get; set; }
    }

    class Program
    {
        static void Main(string[] args)
        {
            InvokeRequestResponseService().Wait();
        }

        static async Task InvokeRequestResponseService()
        {
            using (var client = new HttpClient())
            {
                var scoreRequest = new
                {

                    Inputs = new Dictionary<string, StringTable> () { 
                        { 
                            "input1", 
                            new StringTable() 
                            {
                                ColumnNames = new string[] {"Col1", "Col2", "Col3", "Col4", "Col5", "Col6", "Col7", "Col8", "Col9", "Col10", "Col11", "Col12", "Col13", "Col14", "Col15", "Col16", "Col17", "Col18", "Col19", "Col20", "Col21"},
                                Values = new string[,] {  { "value", "0", "value", "value", "0", "value", "value", "0", "value", "value", "0", "value", "0", "value", "value", "0", "value", "0", "value", "value", "0" },  { "value", "0", "value", "value", "0", "value", "value", "0", "value", "value", "0", "value", "0", "value", "value", "0", "value", "0", "value", "value", "0" },  }
                            }
                        },
                    },
                    GlobalParameters = new Dictionary<string, string>() {
}
                };
                const string apiKey = "abc123"; // Replace this with the API key for the web service
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue( "Bearer", apiKey);

                client.BaseAddress = new Uri("https://ussouthcentral.services.azureml.net/workspaces/0769e412b3944b9e8fed479bb8905c1e/services/02880fc6ed4b439d9099e41c877735d7/execute?api-version=2.0&details=true");
                
                // WARNING: The 'await' statement below can result in a deadlock if you are calling this code from the UI thread of an ASP.Net application.
                // One way to address this would be to call ConfigureAwait(false) so that the execution does not attempt to resume on the original context.
                // For instance, replace code such as:
                //      result = await DoSomeTask()
                // with the following:
                //      result = await DoSomeTask().ConfigureAwait(false)


                HttpResponseMessage response = await client.PostAsJsonAsync("", scoreRequest);

                if (response.IsSuccessStatusCode)
                {
                    string result = await response.Content.ReadAsStringAsync();
                    Console.WriteLine("Result: {0}", result);
                }
                else
                {
                    Console.WriteLine(string.Format("The request failed with status code: {0}", response.StatusCode));

                    // Print the headers - they include the requert ID and the timestamp, which are useful for debugging the failure
                    Console.WriteLine(response.Headers.ToString());

                    string responseContent = await response.Content.ReadAsStringAsync();
                    Console.WriteLine(responseContent);
                }
            }
        }
    }
}

import urllib2
# If you are using Python 3+, import urllib instead of urllib2

import json 


data =  {

        "Inputs": {

                "input1":
                {
                    "ColumnNames": ["Col1", "Col2", "Col3", "Col4", "Col5", "Col6", "Col7", "Col8", "Col9", "Col10", "Col11", "Col12", "Col13", "Col14", "Col15", "Col16", "Col17", "Col18", "Col19", "Col20", "Col21"],
                    "Values": [ [ "value", "0", "value", "value", "0", "value", "value", "0", "value", "value", "0", "value", "0", "value", "value", "0", "value", "0", "value", "value", "0" ], [ "value", "0", "value", "value", "0", "value", "value", "0", "value", "value", "0", "value", "0", "value", "value", "0", "value", "0", "value", "value", "0" ], ]
                },        },
            "GlobalParameters": {
}
    }

body = str.encode(json.dumps(data))

url = 'https://ussouthcentral.services.azureml.net/workspaces/0769e412b3944b9e8fed479bb8905c1e/services/02880fc6ed4b439d9099e41c877735d7/execute?api-version=2.0&details=true'
api_key = 'abc123' # Replace this with the API key for the web service
headers = {'Content-Type':'application/json', 'Authorization':('Bearer '+ api_key)}

req = urllib2.Request(url, body, headers) 

try:
    response = urllib2.urlopen(req)

    # If you are using Python 3+, replace urllib2 with urllib.request in the above code:
    # req = urllib.request.Request(url, body, headers) 
    # response = urllib.request.urlopen(req)

    result = response.read()
    print(result) 
except urllib2.HTTPError, error:
    print("The request failed with status code: " + str(error.code))

    # Print the headers - they include the requert ID and the timestamp, which are useful for debugging the failure
    print(error.info())

    print(json.loads(error.read()))                 
library("RCurl")
library("rjson")

# Accept SSL certificates issued by public Certificate Authorities
options(RCurlOptions = list(cainfo = system.file("CurlSSL", "cacert.pem", package = "RCurl")))

h = basicTextGatherer()
hdr = basicHeaderGatherer()


req = list(

        Inputs = list(

 
            "input1" = list(
                "ColumnNames" = list("Col1", "Col2", "Col3", "Col4", "Col5", "Col6", "Col7", "Col8", "Col9", "Col10", "Col11", "Col12", "Col13", "Col14", "Col15", "Col16", "Col17", "Col18", "Col19", "Col20", "Col21"),
                "Values" = list( list( "value", "0", "value", "value", "0", "value", "value", "0", "value", "value", "0", "value", "0", "value", "value", "0", "value", "0", "value", "value", "0" ),  list( "value", "0", "value", "value", "0", "value", "value", "0", "value", "value", "0", "value", "0", "value", "value", "0", "value", "0", "value", "value", "0" )  )
            )                ),
        GlobalParameters = setNames(fromJSON('{}'), character(0))
)

body = enc2utf8(toJSON(req))
api_key = "abc123" # Replace this with the API key for the web service
authz_hdr = paste('Bearer', api_key, sep=' ')

h$reset()
curlPerform(url = "https://ussouthcentral.services.azureml.net/workspaces/0769e412b3944b9e8fed479bb8905c1e/services/02880fc6ed4b439d9099e41c877735d7/execute?api-version=2.0&details=true",
            httpheader=c('Content-Type' = "application/json", 'Authorization' = authz_hdr),
            postfields=body,
            writefunction = h$update,
            headerfunction = hdr$update,
            verbose = TRUE
            )

headers = hdr$value()
httpStatus = headers["status"]
if (httpStatus >= 400)
{
    print(paste("The request failed with status code:", httpStatus, sep=" "))

    # Print the headers - they include the requert ID and the timestamp, which are useful for debugging the failure
    print(headers)
}

print("Result:")
result = h$value()
print(fromJSON(result))