Rectangle 27 0

Option 1 Attach an empty data disk to the role by specifying the disk label and location of the disk image.

Can you try by removing the <DiskName> element from your request body and see if that works?

Also not sure how you would do this in Java but when you get a 400 exception, if you parse the response body, you should see detailed error message. For example, in .Net we do something like this:

catch (WebException webEx)
            using (var resp = (HttpWebResponse)webEx.Response)
                using (var respStreamReader = new StreamReader(resp.GetResponseStream()))
                    var errorMessage = respStreamReader.ReadToEnd();//errorMessage will be XML containing detailed error message.

So I just tried creating an empty data disk using the API, and I get 400 error under two situations:

  • If I include <DiskName> element in my request body. Once I removed this element, I was able to successfully create a data disk. So your request body should not contain this element.<subscriptionid>/services/hostedservices/<cloudservicename>/deployments/<deploymentname>/roles/<rolename>/DataDisks
<DataVirtualHardDisk xmlns="""" xmlns:i="""">

wow - love your blog! ... so I tried to remove both the DiskName and then the MediaLink tags and still got bad request. As far as I can tell, it's the con.getOutputStream method that would throw an exception - that only throws an IOException and that didn't happen when I put in a try/catch.

Just remove the DiskName and leave the MediaLink tag.

sorry - probably didn't make it clear: I tried removing DiskName first and leaving MediaLink that didn't work. Then I tried removing both - still didn't work.

That should have worked. Does the storage account specified in the media link element belong to the same subscription?

Guarav - would you be able to share your URL and request xml? also - did you set your x-ms-version to '2012-03-01' or to a later date?

Bad Request - 400 when using Azure Add Data Disk REST API - Stack Over...

rest azure
Rectangle 27 0

You have to run curl_error() after curl_exec() because curl_error() does return a string containing the last error for the current session. (source :

$response  = curl_exec($ch);
echo 'Curl error: ' . curl_error($ch);

And you should have a error telling you what is wrong.

thanks! that helped! Now I get string(194) "{"error":{"code":"BadArgument","message":"Invalid argument provided.","details":[{"code":"RequestBodyInvalid","message":"No request body provided or error in deserializing the request body."}]}}"

rest - Azure API - PHP Request - Stack Overflow

php rest azure curl
Rectangle 27 0

You had an issue with the element GlobalParameters, declare it as a StdClass instead of an empty array. Try this :


ini_set('display_errors', 1);

$url = '';
$api_key = '5ve72/xxLuzaexQu7LyRBl1iRdGqAQiQ1ValodnS7DG+F0NzgHkaLyk1J30MXrlWFovzPzlurui/o5jeH7RMiA=='; 

$data = array(
        'Inputs'=> array(
            'input1'=> array(
                'ColumnNames' => ['Client_ID'],
                'Values' => [ [ '0' ], [ '0' ], ]
        '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);

$response  = curl_exec($ch);

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


rest - Azure API - PHP Request - Stack Overflow

php rest azure curl
Rectangle 27 0


Label Required. A name for the storage account specified as a base64-encoded string. The name may be up to 100 characters in length. The name can be used identify the storage account for your tracking purposes.

  • Not related to your problem per se but you're trying to create a storage account in North Central US region. Please note that you can't create new resources in North Central and South Central US region.
<CreateStorageServiceInput xmlns=""><ServiceName>gjhgkjhgkgk</ServiceName><Description /><Label>Z2poZ2tqaGdrZ2s=</Label><Location>West US</Location><GeoReplicationEnabled>true</GeoReplicationEnabled><ExtendedProperties /></CreateStorageServiceInput>

InvalidXmlRequest error for Azure REST API request - Stack Overflow

rest azure