postmanazure-rest-apiazure-ad-b2b

Getting 400 Bad Request error while trying to move Azure resources via Postman


I am trying to move resources from one resource group to another via Postman.

I got the access token successfully by using below parameters:

https://login.microsoftonline.com/mytenantid/oauth2/v2.0/token
client_id='myclientid'
&scope=https://management.azure.com/.default
&grant_type=client_credentials
&client_secret='appclientsecret'

I am using query like below:

POST
https://management.azure.com/subscriptions/mysubscriptionid/resourceGroups/resourcegroupname/moveResources?api-version=2021-04-01

Request Body

{  
"resources" : "/subscriptions/mysubscriptionid/resourceGroups/resourcegroupname/providers/Microsoft.KeyVault/vaults/keyvaultname",  
"targetResourceGroup" : "/subscriptions/mysubscriptionid/resourceGroups/targetresourcegroupname"  
}

But I got error like below:

{ "error": { "code": "UnsupportedMediaType", "message": "The content media type 'text/plain' is not supported. Only 'application/json' is supported." } }

After changing the type to JSON, I am getting another error like below:

{ "error": { "code": "InvalidRequestContent", "message": "The request content was invalid and could not be deserialized: 'Error converting value "/subscriptions/mysubscriptionid/resourceGroups/resourcegroupname/providers/Microsoft.KeyVault/vaults/keyvaultname" to type 'System.String[]'. Path 'resources', line 2, position 143.'." } }

Can anyone help me to resolve this error?


Solution

  • I tried to reproduce the same in my environment and was able to move resources successfully like below:

    enter image description here

    Make sure your request body is something like below:

    {
    "resources" : ["/subscriptions/XXXXXXX/resourceGroups/Test/providers/Microsoft.KeyVault/vaults/testkeyvault549","/subscriptions/XXXXXXXXX/resourceGroups/Test/providers/Microsoft.Storage/storageAccounts/sristackdem01"],
    "targetResourceGroup" : "/subscriptions/XXXXXXX/resourceGroups/Demo"
    }
    

    When I executed the same query, I got below response:

    enter image description here

    Please note that resources parameter expects list of resource IDs in [ ]. So, make sure to add them.

    When I missed giving [ ] as mentioned above, I got the same error as you like below:

    enter image description here

    Reference:

    Validate Azure Resource Move with Postman - Apostolidis Cloud Corner