GIRISH RAMNANI
GIRISH RAMNANI

Reputation: 624

List all the regions using the azure api

I am trying get all the possible regions to which a vm can be provisioned using the azure rest api. The end point which i found is

https://management.core.windows.net/<subscription-id>/locations

which is documented here

but i am getting an error.

<Error xmlns="http://schemas.microsoft.com/windowsazure" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><Code>ForbiddenError</Code><Message>The server failed to authenticate the request. Verify that the certificate is valid and is associated with this subscription.</Message></Error>

Also i tried using the query param ?api-version=2016-04-01 and header x-ms-version: 2016-04-01 without any luck.

Upvotes: 0

Views: 2484

Answers (2)

Tom Sun
Tom Sun

Reputation: 24549

According to your error code ForbiddenError, it seems that there is no authorization or incorrect authorization in the header. If it is that case, please have a try to add the authorization in the header. Authorization format is starting with "Bearer" like "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiI…..." . More info about how to get the access token please refer to the document. It works for me correctly, and I use the x-ms-version: 2014-10-01, details please refer to the snapshot.

enter image description here

Upvotes: 1

evilSnobu
evilSnobu

Reputation: 26334

You're using an ancient management endpoint.
Here's the query for ARM (using ARMClient):

C:\>armclient.exe get https://management.azure.com/subscriptions/
        xxxxx-xxxxx-xxxxx-xxxxx/locations?api-version=2016-09-01 -verbose

---------- Request -----------------------

GET /subscriptions/xxxx-xxxx-xxxxx-xxxxx/locations?api-version=2016-09-01 HTTP/1.1
Host: management.azure.com
Authorization: Bearer eyJ0eXAiOiJKV...
User-Agent: ARMClient/1.1.1.0
Accept: application/json
x-ms-request-id: xxxxxxxxxxxx


---------- Response (326 ms) ------------

HTTP/1.1 200 OK
Pragma: no-cache
x-ms-ratelimit-remaining-subscription-reads: 14999
x-ms-request-id: xxxxxxxxxxxxx
x-ms-correlation-request-id: xxxxxxxxxxx
x-ms-routing-request-id: NORTHEUROPE:20170109T094615Z:exxxxxxxxxxxxxx
Strict-Transport-Security: max-age=31536000; includeSubDomains
Cache-Control: no-cache
Date: Mon, 09 Jan 2017 09:46:15 GMT

{
  "value": [
    {
      "id": "/subscriptions/xxxx-xxxx-xxxx-xxxx/locations/eastasia",
      "name": "eastasia",
      "displayName": "East Asia",
      "longitude": "114.188",
      "latitude": "22.267"
    },
    {
      "id": "/subscriptions/xxxx-xxxx-xxxx-xxxx/locations/southeastasia",
      "name": "southeastasia",
      "displayName": "Southeast Asia",
      "longitude": "103.833",
      "latitude": "1.283"
    },
    {
      "id": "/subscriptions/xxxx-xxxx-xxxx-xxxx/locations/centralus",
      "name": "centralus",
      "displayName": "Central US",
      "longitude": "-93.6208",
      "latitude": "41.5908"
    },
    {
      "id": "/subscriptions/xxxx-xxxx-xxxx-xxxx/locations/eastus",
      "name": "eastus",
      "displayName": "East US",
      "longitude": "-79.8164",
      "latitude": "37.3719"
    },
...

If you intentionally want to query the old RDFE management API you'll need to include the management certificate in your call.

I think you can use a token with RDFE too, but not a Bearer token. Just sniff whatever Get-AzureLocation -debug in PowerShell is doing.

Upvotes: 0

Related Questions