skip to Main Content

I’d like to change a VMSS capacity through API. On the Azure webpage there is a "Try it" button for check a request:
https://learn.microsoft.com/en-us/rest/api/compute/virtual-machine-scale-sets/update?tabs=HTTP#code-try-0

and my JSON is working fine from that link. But with curl I’ve got an answer:

"code":"UnsupportedResourceOperation","message":"The resource type ‘virtualMachineScaleSets’ does not support this operation."

My request looks like this:

curl -s -X PATCH 
  -H "Authorization: Bearer ${TOKEN}" 
  -H "Content-type: application/json" 
  -d @body.json 
  https://management.azure.com/subscriptions/${SUBSCRIPTION}/resourceGroups/${RG}/providers/Microsoft.Compute/virtualMachineScaleSets/${SCALE_SET_NAME}?api-version=2022-11-01

and the content of a body.json file is:

{
  "sku": {
  "tier": "Standard",
  "capacity": 1,
  "name": "Standard_B2s"
  }
}

The same json body is working fine on "Try it" so it may be something wrong with my curl request. I’m able to GET information using curl. Could you please show me where did I make a mistake?

2

Answers


  1. Chosen as BEST ANSWER

    My bad of course. The API version what I used in the example was 2022-11-01 instead of the latest 2023-03-01 and I used a SCALE_SET_NAME which was not defined on my host machine.


  2. I created an Azure AD Application and added API permissions like below:

    enter image description here

    Now, I generated auth-code using below authorize endpoint:

    https://login.microsoftonline.com/TenantID/oauth2/v2.0/authorize?
    &client_id=ClientID
    &response_type=code
    &redirect_uri=https://jwt.ms
    &response_mode=query
    &scope=https://management.azure.com/.default
    &state=12345
    
    

    enter image description here

    Now, I generated access token by using below parameters:

    https://login.microsoftonline.com/TenantID/oauth2/v2.0/token
    
    client_id:ClientID
    grant_type:authorization_code
    scope:https://management.azure.com/.default
    code:code
    redirect_uri:https://jwt.ms
    client_secret:ClientSecret
    
    

    enter image description here

    By using the above token, I am able to update the VMSS successfully like below:

    PATCH https://management.azure.com/subscriptions/SubID/resourceGroups/RGName/providers/Microsoft.Compute/virtualMachineScaleSets/vmss?api-version=2023-03-01
    
    {
    "sku": {
    "tier": "Standard",
    "capacity": 1,
    "name": "Standard_B2s"
    }
    }
    
    

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search