Upload package through rest windows authentication


I am not able to upload package to different tenant through rest api. Every time it uploads it to default tenant.


$FilePath = ‘C:\dev\commontask.’;
$URL = ‘https:// XXXXXXX/odata/Processes/UiPath.Server.Configuration.OData.UploadPackage’;

$fileBytes = [System.IO.File]::ReadAllBytes($FilePath);
$enc = [System.Text.Encoding]::GetEncoding(“iso-8859-1”)

$fileEnc = [System.Text.Encoding]::GetEncoding(‘UTF-8’).GetString($fileBytes);
$fileEnc = $enc.GetString($fileBytes)
$boundary = [System.Guid]::NewGuid().ToString();
#$boundary = ‘------WebKitFormBoundaryffkLf5obuxBIBu67’;
$LF = “rn”;

$bodyLines = (
“Content-Disposition: form-data; name="file”; filename="commontask."",
“Content-Type: application/octet-stream$LF”,
) -join $LF

$headers = New-Object “System.Collections.Generic.Dictionary[[String],[String]]”
$headers.Add(“X-UIPATH-OrganizationUnitId”, “2”) # not working
#$headers.Add(“tenancyName”, “UAT”) # not working

Invoke-RestMethod -Uri $URL -Headers $headers -Method Post  -ContentType "multipart/form-data; boundary=$boundary"  -Body $bodyLines  -UseDefaultCredentials

i get error : The user is no longer associated with the organization unit.
but i am added to all tenants.

Do you use a new auth token for each tenant? I think the tenant is choosen depending on the token. When receiving the token you have to post the tenant name. In REST calls using the token you don’t specify your tenant.