Показать сообщение отдельно
Старый 22.11.2018, 14:27   #2  
pedrozzz is offline
pedrozzz
Молодой, подающий надежды
Аватар для pedrozzz
MCBMSS
Лучший по профессии 2015
 
164 / 218 (8) ++++++
Регистрация: 18.02.2010
Адрес: Краснодар
Сам вопрос задал, сам решил. Если вдруг кому пригодится.
Сначала некоторые подготовительные работы

Цитата:
Step 1. Authentication. For authentication, it is required to create an azure based application. Once this application creation is done, then you will get your ‘Client ID’ (or it is known as Application ID as well in azure portal for the application) and then you can generate (& Save) Client secret key as well. Both ‘ClientID’ and ‘Client Secret Key’ is required

Step 2. Registering and authorizing this application ID (or client ID) in Dynamics environment. Ensure that this ‘Client ID’ exist in Dynamics environment: Modules > System administration > Setup > Azure active directory applications. If record does not exist on the form, create a new one with details about Client ID, name:, and user Id. Ensure User ID = Admin.
И сам скрипт

X++:
$axBaseURL = "https://YOUR_NAME.cloudax.dynamics.com"

function D365-LoadPackage {
    [cmdletbinding()]
    param(
        [Parameter(Mandatory=$true)]$tenantId,
        [Parameter(Mandatory=$true)]$client_id,
        [Parameter(Mandatory=$true)]$client_Secret_key
    )

    $body = "resource=" + $axBaseURL + "&client_id=" + $client_id +"&client_secret=" + $client_Secret_key + "&grant_type=client_credentials"
    $url = "https://login.windows.net/" + $tenantId + "/oauth2/token"
    $apiToken = Invoke-RestMethod Uri $url -Method POST -Body $body -ContentType 'application/x-www-form-urlencoded'
    
    $url = "$axBaseURL/data/DataManagementDefinitionGroups/Microsoft.Dynamics.DataEntities.ImportFromPackage"

    $header = @{
    'Authorization' = 'Bearer ' + $apiToken.access_token
    }
        
    $body = @"
    {
        "packageUrl":"https://YOUR_ADDRESS.blob.core.windows.net/BLOB_NAME/FileName.zip",
        "definitionGroupId":"pk test",
        "executionId":"",
        "execute":"true",
        "overwrite":"true",
        "legalEntityId":"DAT"
    }
"@
    
    Invoke-RestMethod –Uri $url –Method POST –Headers $header -Body $body -ContentType "application/json" -ErrorAction Stop
    
}
__________________
Кононов Пётр
За это сообщение автора поблагодарили: Vadik (1), sukhanchik (2), Alex_KD (3).