How to add a user to Azure DevOps using it's python client API?

后端 未结 1 966
没有蜡笔的小新
没有蜡笔的小新 2021-01-25 04:03

I am writing a python script to add a user(an existing user from the AAD backed provider) to Azure DevOps. I am using python client library of Azure DevOps for this purpose. Aft

1条回答
  •  礼貌的吻别
    2021-01-25 04:29

    GraphUserCreationContext class from the python client for azure devops REST API accepts only one input parameter which is StorageKey. Hence, whatever you provide as an input parameter to that function, be it a UPN or ID, it is set as a storage key.

    If you print the addAADUserContext object, you will get:

    {'additional_properties': {}, 'storage_key': 'anaya.john@domain.com'}
    

    But the create_user() function of Graph client needs exactly one of originId or principalName set in the GraphUserCreationContext it takes as input parameter.

    As the microsoft documentaion for the azure devops REST API (https://docs.microsoft.com/en-us/rest/api/azure/devops/graph/users/create?view=azure-devops-rest-4.1 ) :

    The body of the request must be a derived type of GraphUserCreationContext:

    • GraphUserMailAddressCreationContext
    • GraphUserOriginIdCreationContext
    • GraphUserPrincipalNameCreationContext

    We shouldn't use the GraphUserCreationContext object directly. But the classes like GraphUserPrincipalNameCreationContext aren't currently available in the python client API. They are working on it. You can track the issue here in GitHub repo: https://github.com/microsoft/azure-devops-python-api/issues/176

    You can use User Entitlements - Add REST API for azure devops instead of it's Graph API. You can use the following python client for this purpose:

    https://github.com/microsoft/azure-devops-python-api/tree/dev/azure-devops/azure/devops/v5_0/member_entitlement_management

    You can refer to the sample given in the following question to know about how to use the mentioned python client :

    Unable to deserialize to object: type, KeyError: ' key: int; value: str '

    0 讨论(0)
提交回复
热议问题