python – Variable Group Creation using API in Azure Devops

I am trying to create a variable group in an Azure DevOps project using the REST APIs and Python scripting. The API used is:

POST https://dev.azure.com/{organization}/_apis/distributedtask/variablegroups?api-version=7.0

The payload in use is attached:

vargroup_data = { "name": "MyVariableGroup", "description": "This is my variable group", "type": "Vsts", "variables": { "myVariable": { "value": "myValue", "isSecret": False }, "myPublicVariable": { "value": "myPublicValue", "isSecret": False } }, "variableGroupProjectReferences": { "projectReference": { "id": project_id, "name": project } } }

I am receiving an error: Failed to create variable group.

Status code: 500 Response: {"$id":"1","innerException":null,"message":"Atleast one variable group project reference is required.","typeName":"Microsoft.TeamFoundation.DistributedTask.Server.Exceptions.InvalidRequestException,Microsoft.TeamFoundation.DistributedTask.Server","typeKey":"InvalidRequestException","errorCode":0,"eventId":3000}

What might be the problem here?

The intended output was a new variable group being created in the project.

Read more here: Source link