Suamere
Suamere

Reputation: 6238

Azure Rest API - Create Web App - Bad Request

I am attempting to consume the Azure REST API to Create a new Web App as documented here.

I am using an Authorization = Bearer xxxx token created with the Scope and Resource of https://management.azure.com/.

The Registered App has the Microsoft Graph Api permission Sites.Manage.All and Application.ReadWrite.All.

I am doing a PUT to https://management.azure.com/subscriptions/{subID}/resourceGroups/{resGrp}/providers/Microsoft.Web/sites/{newName}?api-version=2016-08-01

I am specifying a content type of application/json with the following body:

{
    "location":"Central US",
    "properties":
    {
        "cloningInfo":
        {
            "sourceWebAppId":"subscriptions/{subID}/resourceGroups/{resGrp}/providers/Microsoft.Web/sites/{cloneFromName}",
            "overwrite":true,
            "ignoreQuotas":true,
            "correlationId":"some random text??"
        }
    }
}

I have also tried this similar body

{
    "location":"Central US",
    "properties.cloningInfo":
    {
        "sourceWebAppId":"subscriptions/{subID}/resourceGroups/{resGrp}/providers/Microsoft.Web/sites/{cloneFromName}",
        "overwrite":true,
        "ignoreQuotas":true,
        "correlationId":"some random text??"
    }
}

I am able to successfully call List Sites specified at this documentation.

I assume I either have the wrong Api Permissions, or I am missing some required information in the body.

Upvotes: 1

Views: 309

Answers (1)

Tony Ju
Tony Ju

Reputation: 15609

You missed ServerFarmId in the body, the body should be

{
    "location":"Central US",
    "properties":
    {
        "cloningInfo":
        {
          "sourceWebAppId":"{Resource ID of the webpp you want to clone}",
            "overwrite":true,
            "ignoreQuotas":true,
            "correlationId":"correlationId1"
        },
      "ServerFarmId":"{Resource ID of the associated App Service plan}"
    }
}

Besides, you need to confirm if your service plan supports clone app feature. Clone app is a feature that is only available to apps hosted on Standard App Service Plans. When you click Clone App on Azure portal, you will find the tip. enter image description here

You can also find more details in the response. enter image description here

Upvotes: 1

Related Questions