Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
4 views
in Azure by (5.8k points)

I tried integrating Azure ML API with PHP but unfortunately getting an error in response.

Updated: I have used request-response API sending through JSON response

Below is the response obtained on executing the PHP script:

array(1) { ["error"]=> array(3) { ["code"]=> string(11) "BadArgument" 

    ["message"]=> string(26) "Invalid argument provided." ["details"]=> array(1)

    {[0]=> array(2) { ["code"]=> string(18) "RequestBodyInvalid" ["message"]=>

    string(68) "No request body provided or error in deserializing the request

    body." } } } }

PHP script:

$url = 'URL';

$api_key = 'API';

$data = array(

    'Inputs'=> array(

        'My Experiment Name'=> array(

            "ColumnNames" => [['Column1'],

                              ['Column2'],

                              ['Column3'],

                              ['Column4'],

                              ['Column5'],

                              ['Column6'],

                              ['Column7']],

            "Values" => [ ['Value1'],

                          ['Value2'],

                          ['Value3'],

                          ['Value4'],

                          ['Value5'],

                          ['Value6'],

                          ['Value7']]

            ),

        ),

        'GlobalParameters' => new StdClass(),

    );

$body = json_encode($data);

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);

curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Authorization: Bearer '.$api_key, 'Accept: application/json'));

curl_setopt($ch, CURLOPT_POST, 1);

curl_setopt($ch, CURLOPT_POSTFIELDS, $body);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

$response  = json_decode(curl_exec($ch), true);

//echo 'Curl error: ' . curl_error($ch);

curl_close($ch);

var_dump ($response);

I have followed few examples, still unable to crack it. Please let me know the solution for this.

1 Answer

0 votes
by (9.6k points)
edited by

You can check the body of json. This might be happening because of incorrect json body. 

You can check this question here for more understanding.

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...