Dean, Can you please explain a bit on $bodyLines and $boundary variables. ? What is supposed to be there in it. I have the same problem too. Cannot upload the packages via API call from C# or Powershell.
Are you able to fix this issue? I am also trying to post a package to orchestrator from my python program but stuck with the same error you mentioned. So any suggestion or help regarding to this would be great helpful.
We also faced this issue to upload package to Orchestrator using API (because CI/CD) and I created a Powershell script for this. I’m sharing the code, it works for me so it should also work for you.
<#
.DESCRIPTION
This script is intented to upload a package (.nupkg file) to the Orchestrator over its API
.NOTES
Tested in version 2019.10
Script created on 2020/6 by Masire FOFANA (masire.fofana@natixis.com)
#>
<# Set variables below #>
# URL of the Orchestrator
$targetURL = ''
# Name of the tenant
$targetTenant = ''
# Orchestrator local user name (needs package creation right)
$targetUsername = ''
# Orchestrator local user password
$targetPassword = ''
# Full path of package to upload (needs to be an .nupkg file)
$packageLocation = ''
<# Script below #>
$headers = @{
'Accept' = 'application/json'
}
$loginModel = @{
'tenancyName' = $targetTenant
'usernameOrEmailAddress' = $targetUsername
'password' = $targetPassword
}
$uri = $targetURL + 'api/Account/Authenticate'
$result = Invoke-RestMethod -Method Post -Uri $uri -Headers $headers -Body $loginModel
if ($result.success) {
$bearer = $result.result
$headers.Add('Authorization', "Bearer $bearer")
$fileBytes = [System.IO.File]::ReadAllBytes($packageLocation);
$fileEnc = [System.Text.Encoding]::GetEncoding('ISO-8859-1').GetString($fileBytes);
$boundary = [System.Guid]::NewGuid().ToString();
$LF = "`r`n";
$bodyLines = (
"--$boundary",
"Content-Disposition: form-data; name=`"file`"; filename=`"$(Split-Path $packageLocation -Leaf)`"",
"Content-Type: application/octet-stream$LF",
$fileEnc,
"--$boundary--$LF"
) -join $LF
$headers.Add('Content-Type', "multipart/form-data; boundary=`"$boundary`"")
$uri = $targetURL + 'odata/Processes/UiPath.Server.Configuration.OData.UploadPackage'
$uploaded = $false
try {
$result = Invoke-RestMethod -Method Post -Uri $uri -Headers $headers -Body $bodyLines
$uploaded = $true
} catch {
Write-Host "An error occured: $_"
}
if ($uploaded) {
Write-Host "Yay!"
} else {
Write-Host "Sorry, not working..."
}
}
Meanwhile, for customers using Jenkins or Azure DevOps for their CI/CD pipelines, we have released two extensions that can upload packages (additionally, they are also able to deploy them as processes onto a set of environments):
Do you have any example code for deployment using Azure or Jenkins. We need to deploy our package in tenant to tenant, folder to folder and may be one orchestrator to another. Do we have any mechanism like using API we can deploy pur uipath package to different environment.
You can take a look at this article to see the integration from Azure DevOps.
I manage to do the end to end pipeline with releases and deploy to on premise Orchestrator. I can guide you if you need additional information on how to do it.
The only thing that is not yet clarified is that the packages always land into the tenant package feed and not the folder package feed.
I am trying to use this code on orchestrator 2022.10. I am getting the error (Invoke-RestMethod : {“message”:“Failed to read the request form. Multipart body length limit 16384 exceeded.”) The code I am trying to upload just writes a log message so it should not exceed any size limits. Could you help me resolve this?