使用REST API创建资源组部署

时间:2017-04-11 12:09:11

标签: rest azure

PUT /subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}
    /providers/Microsoft.Resources/deployments/{deploymentName}?api-version=2016-09-01

REST调用正文:

{
    "properties": {
        "template": {
            "schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
            "contentVersion": "1.0.0.0",
            "resources": []
        }
    }
}

这是一个最小的有效JSON模板,如果我收到请求:

{
  "error": {
    "code": "InvalidRequestContent",
    "message": "The request content was invalid and could not be deserialized: 'Could not find member 'schema' on object of type 'Template'. Path 'properties.template.schema', line 4, position 16.'."
  }
}

好的,这没有意义,让我们尝试删除“schema”属性,这就是我得到的:

{
  "error": {
    "code": "InvalidRequestContent",
    "message": "The request content was invalid and could not be deserialized: 'Required property '$schema' not found in JSON. Path 'properties.template', line 6, position 4.'."
  }
}

模板对象的模式未在docs中描述。那么WTH?

1 个答案:

答案 0 :(得分:0)

根据错误消息,我们可能知道我们需要使用 $ schema 而不是schema,请尝试使用以下正文和模式。它在我身边正常工作,我用小提琴手测试过。

{
      "properties": {
        "template": {
          "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
          "contentVersion": "1.0.0.0",
          "resources": []
        },
        "mode": "Incremental"
      }

}

enter image description here