UIPATH Orchestrator API: Upload Package

Hi community!!

I am dealing with the orchestrator API, both with Uipath HttpRequest dedicated activities, and also in python.

I am trying to perform “Upload Package” action, as follows (indicated in the API guide)(Python).


url = myOrchestratorURL + “/odata/Processes/UiPath.Server.Configuration.OData.UploadPackage”
headers = {
‘authorization’: "Bearer " + bearer,
‘content-type’: “multipart/form-data”,
}
multipart_form_data = {
‘Content-Disposition’ : ‘form-data; name=“file”; filename=“CHARO_A.1.0.6515.17422.nupkg”’,
‘Content-Type’ : ‘application/octet-stream’
}
response = requests.post(url, headers=headers , files=multipart_form_data)
print(response.text):


And the result obtained is:


{“error”:{“code”:“”,“message”:“You have to upload one package.”}}


At one point I guess I am missing something, but I can’t guess… Any help would be appreciated!

Thanks a lot and have a good day

1 Like

I am having this exact same issue. Were you ever able to figure it out?

Hello,
Is there a solution for upload packages ?

I was finally able to get this to work. I am using Powershell, and the specific line of relevance is:

$status = Invoke-RestMethod -Method Post -Headers $headers -Uri ($server+$uri) -Body $bodyLines -ContentType “multipart/form-data;boundary=$boundary” -Verbose

1 Like

Thank You Dean,
You make us turn the right way.
We finnaly use postman to test and automate it in curl (impossible to do it in Python) :

curl -X POST https://${MY_URL}/odata/Processes/UiPath.Server.Configuration.OData.UploadPackage%28%29 -H ‘Authorization: Bearer ${MYTOKEN}’ -H ‘Cache-Control: no-cache’ -H ‘Postman-Token: c49b38fc-d701-4603-882a-a72e971db984’ -H ‘content-type: multipart/form-data’ -F ‘file=@/mnt/Dossier_Windows/mytest.nupkg’

1 Like

Your welcome @GeneraliDevops :slight_smile:

1 Like

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.

Hi @rmadrigal,

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.

Thank you in advance.

Best,
Sid

Can you please help me with this curl command? When i try to follow the curl command you posted am getting the following exception.

  • CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
    • FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

Thank you for your help in advance.

Best,
Sid

Hi everyone,

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..."
    }
}
1 Like

Thank you for your contribution @Masire!

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):

For other CI/CD platforms and an on-premise deployment, this script should do just fine.

1 Like

Is there any documentation explaining this step:

$fileBytes = [System.IO.File]::ReadAllBytes($packageLocation);
$fileEnc = [System.Text.Encoding]::GetEncoding(‘ISO-8859-1’).GetString($fileBytes);
$boundary = [System.Guid]::NewGuid().ToString();
$LF = “rn”;

I get what it does, but can’t really find any information about if from UiPath.

Best regards

Hi @hl8z,

This step is necessary to convert the file using ISO-8859-1 encoding. I tried with UTF-8 also but it did not work.

Regards,

Masiré

Hi Alvin,

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.

regards,
Sushila

Hi Sushila,

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.

Regards.

1 Like

@sushila.kumari i found this article a while back, maybe it can help you setting it up. I haven’t tested it (yet). https://rpabotsworld.com/ci-cd-pipeline-for-uipath/

Check this Python example:

import requests

url = "https://your_orchestrator_hostname/Processes/UiPath.Server.Configuration.OData.UploadPackage()"

payload={}
files=[
  ('',('TestSumWin6.1.0.1.nupkg',open('/C:/Marian/NupkgFileToUpload/TestSumWin6.1.0.1.nupkg','rb'),'application/octet-stream'))
]
headers = {
  'Content-Type': 'multipart/form-data',
  'x-uipath-organizationunitid': '1',
  'Authorization': 'Bearer your_access_token'
}

response = requests.request("POST", url, headers=headers, data=payload, files=files)

print(response.text)

Thanks @marian.platonov …Perfect …It’s worked for me

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?

Hi Marian,

Thank you for the code!

Can you please post a code which will take input as tenant name, Orchestrator URL with Authorization of Username and password instead of accesstoken