1

I'm trying to create a new AutomationAccount using Python SDK. There's no problem if I get, list, update or delete any account, but I'm getting a BadRequest error when I try to create a new one.

Documentation is pretty easy: AutomationAccountOperations Class > create_or_update()

#!/usr/bin/env python3 # -*- coding: utf-8 -*- import os from azure.identity import AzureCliCredential from azure.mgmt.automation import AutomationClient credential = AzureCliCredential() automation_client = AutomationClient(credential, "xxxxx") result = automation_client.automation_account.create_or_update("existing_rg", 'my_automation_account', {"location": "westeurope"}) print(f'Automation account {result.name} created') 

This tiny script is throwing me this error:

Traceback (most recent call last): File ".\deploy.py", line 10 result = automation_client.automation_account.create_or_update("*****", 'my_automation_account', {"location": "westeurope"}) File "C:\Users\Dave\.virtualenvs\new-azure-account-EfYek8IT\lib\site-packages\azure\mgmt\automation\operations\_automation_account_operations.py", line 174, in create_or_update raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) azure.core.exceptions.HttpResponseError: (BadRequest) {"Message":"The request body on Account must be present, and must specify, at a minimum, the required fields set to valid values."} Code: BadRequest Message: {"Message":"The request body on Account must be present, and must specify, at a minimum, the required fields set to valid values."} 

I've tried to use this method (create_or_update) on a different sdk like powershell using same parameters and it worked.

Some thoughts?

2
  • 1
    So I'm just scrolling the docs you linked, one thing I notice, for the AutomationAccountCreateOrUpdateParameters class as the last parameter: name, tags and sku are all listed as "required" in addition to location which you provide. Is it possible those need to be included in your request as well? Commented Apr 3, 2022 at 1:02
  • Solved! Those params are not required (doc says are required but are optional in code) but sku seems to be the key. I've filled the sku field and now is creating the AutomationAccount. Thanks @UpQuark Commented Apr 3, 2022 at 8:03

1 Answer 1

1

Solution is setting the Azure SKU parameter.

For some reason is not necessary on Powershell but it is on Python SDK. Now this snippet is creating my AutomationAccount successfully.

credential = AzureCliCredential() automation_client = AutomationClient(credential, "xxxxx") params = {"name": my_automation_account, "location": LOCATION, "tags": {}, "sku": {"name": "free"}} result = automation_client.automation_account.create_or_update("existing_rg", 'my_automation_account', params) print(f'Automation account {result.name} created') 

Docs about this:

Thanks @UpQuark

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.