Create a custom package
A custom package is built from your own installer, the same as Convert Package in the portal. Creating one through the API takes three requests: create the package, upload the installer in chunks, then finalise the upload. Robopack then processes the package, and you check its state before you upload it to Intune or add it to a Robopatch flow.
This guide uses PowerShell and the ROBOPACK_API_KEY environment variable from Getting started. For packaging options in the portal, see Custom Packaging.
The POST requests below create a package in your Robopack account. Run them against a test installer for your first integration.
Create the package
Describe the package in a JSON body. Only name is required by the schema, but Robopack needs enough information to install, uninstall and detect the app:
if ([string]::IsNullOrWhiteSpace($env:ROBOPACK_API_KEY)) {
throw 'Set ROBOPACK_API_KEY to your API key.'
}
$headers = @{ 'X-API-Key' = $env:ROBOPACK_API_KEY; Accept = 'application/json' }
$installer = Get-Item 'C:\Packages\ContosoAgent.msi'
$body = @{
name = 'Contoso Agent'
publisher = 'Contoso'
version = '4.2.0'
sourceType = 'msi'
installCommand = 'msiexec /i "ContosoAgent.msi" /qn /norestart'
userContext = $false
architecture = 2
runAnalysis = $true
} | ConvertTo-Json
$package = Invoke-RestMethod -Method Post -Headers $headers -ErrorAction Stop `
-ContentType 'application/json' -Body $body `
-Uri 'https://api.robopack.com/v1/package/create'
$packageId = $package.id
$packageId
The response is the new package object. Retain its id for the upload and every later request.
| Field | What to send |
|---|---|
name | Required. The package name shown in Robopack. |
publisher, version | The publisher and version of the app. |
sourceType | msi, exe or zip. Use zip when the installer needs other files beside it, and upload the zip file. |
installCommand | The command that installs the app silently. |
uninstallCommand | The command that removes the app. Required when runAnalysis is false. |
detectionRules | An array of Intune detection rules, each with a Type of MSI, Registry, File, Script or MSIX. Required when runAnalysis is false. |
runAnalysis | true makes Robopack run an installation analysis to verify the install command and attempt to determine the uninstall command and detection rule. |
userContext | true if the app installs in the user context, false for the machine context. |
architecture | 0 None, 1 x86, 2 x64, 4 Arm64. |
scriptTemplateId | Optional. A script template ID from GET /v1/template. |
logoData | A logo as Base64-encoded PNG or JPEG data. |
If you set runAnalysis to false, supply your own uninstallCommand and detectionRules. The detection rule schemas, including the operator and option integers, are in the package create reference.
Upload the installer
Send the installer in chunks to POST /v1/package/content/{id}. The raw bytes of the chunk go in the request body, and the query string says where the chunk belongs:
| Parameter | Value |
|---|---|
index | The file's position in the upload, starting at 0. A single installer is always 0. |
chunk | The chunk's position, starting at 0. |
offset | The byte in the file where this chunk starts. |
size | The chunk's length in bytes. |
This loop reads the installer in 5 MB chunks and uploads each one in order:
$chunkSize = 5MB
$buffer = [byte[]]::new($chunkSize)
$stream = [System.IO.File]::OpenRead($installer.FullName)
try {
$chunk = 0
$offset = 0L
while (($read = $stream.Read($buffer, 0, $chunkSize)) -gt 0) {
$bytes = [byte[]]::new($read)
[Array]::Copy($buffer, $bytes, $read)
$uri = "https://api.robopack.com/v1/package/content/${packageId}?index=0&chunk=$chunk&offset=$offset&size=$read"
Invoke-RestMethod -Method Post -Headers $headers -ErrorAction Stop `
-ContentType 'application/octet-stream' -Body $bytes -Uri $uri | Out-Null
$offset += $read
$chunk++
}
}
finally {
$stream.Dispose()
}
If a chunk fails, send the same chunk again with the same chunk and offset values before moving on.
Finalise the upload
Once every chunk is uploaded, list the file you sent so Robopack can assemble it:
$finalize = @{
files = @(
@{ fileName = $installer.Name; fileSize = $installer.Length }
)
} | ConvertTo-Json -Depth 3
Invoke-RestMethod -Method Post -Headers $headers -ErrorAction Stop `
-ContentType 'application/json' -Body $finalize `
-Uri "https://api.robopack.com/v1/package/content/$packageId/finalize"
fileSize is the whole file's size in bytes, not the chunk size. The request returns no body.
Check the package before using it
Robopack processes the package after the upload is finalised, and runs the installation analysis if you asked for it. Read the package until its internalState is 3 (Completed):
$package = Invoke-RestMethod -Method Get -Headers $headers -ErrorAction Stop `
-Uri "https://api.robopack.com/v1/package/$packageId"
$package | Select-Object id, productName, manufacturer, productVersion, state, internalState
$package.errorDetails
$package.issues
7 (WaitingForContent) means Robopack is still waiting for the installer; check that every chunk was uploaded and the upload was finalised. 5 (Error) means processing failed; review errorDetails and issues before you use the package. The full list of states is in Import an app and upload to Intune.
What's next?
- Upload the package to Intune for a one-off manual upload
- Deploy to test devices with a Robopatch flow to roll the package out in waves