I am trying to Import Nintex workflow using API - but the API error out Response status code does not indicate success: 500 (Internal Server Error).
Detail error - StatusCode: 500, ReasonPhrase: 'Internal Server Error', Version: 1.1, Content: System.Net.Http.DecompressionHandler+GZipDecompressedContent
# ===============================
# Nintex Workflow Import Example
# ===============================
Clear-Host
# --- Configuration ---
#$apiBase = "https://us.nintex.io/workflows/v1/designs/package/import"
$bearerToken = "dsfsssssssssssssssssssssssssssssssssssssssssssssstW" # OAuth 2.0 token
$packagePath = "C:\Ddsfffffffffffe.zip" # Path to exported ZIP
# --- Query parameters ---
$name = "PSActivityReports_v3"
$assignedUse = "Production"
$overwriteExisting = "true"
$publishWhenConfigured = "true"
# --- Build URL ---
$apiUrl = "https://us.nintex.io/workflows/v1/designs/package/import?name=$name&assignedUse=$assignedUse&overwriteExisting=$overwriteExisting&publishWhenConfigured=$publishWhenConfigured"
# --- Headers ---
$headers = @{
"Authorization" = "Bearer $bearerToken"
"Accept" = "application/json"
}
# --- Import Binary ---
try {
$response = Invoke-WebRequest `
-Uri $apiUrl `
-Method POST `
-Headers $headers `
-ContentType "application/zip" `
-InFile $packagePath `
if ($response.StatusCode -in 200, 201) {
$content = $response.Content | ConvertFrom-Json
Write-Host "✅ Import successful!"
Write-Host "Workflow Name: $($content.name)"
Write-Host "Workflow ID: $($content.id)"
Write-Host "Status: $($content.status)"
} else {
Write-Host "❌ Import failed: $($response.StatusCode) $($response.StatusDescription)"
Write-Host $response.Content
}
}
catch {
Write-Host "❌ Error during import:"
# This block captures the specific response details from the exception
$errorResponse = $_.Exception.Response
if ($errorResponse) {
Write-Host "Status Code: $($errorResponse.StatusCode)"
Write-Host "Detailed Response Body:"
# This is the key part - the detailed error from Nintex
Write-Host $errorResponse
} else {
Write-Host $_.Exception.Message
}
}
Best answer by SimonMuntz
Hi @doorga,
I tested this on a machine running Windows 11, and it worked. Update the token and filepath/name, and you are good to go.
# Load System.Net.Http (needed for PS 5.1)
Add-Type -AssemblyName System.Net.Http
# === CONFIGURATION ===
$apiUrl = "https://us.nintex.io/workflows/v1/designs/package/import"
$token = "YourToken" # Replace with your token
$packagePath = "C:\workflow-export.zip" # Update path
$workflowName = "Imported Workflow"
$assignedUse = "Development" # Or "Production"
$overwriteExisting = $true
$publishWhenConfigured = $false
# === HELPER: URL-encode ===
function Encode-UriComponent {
param([string]$str)
return [uri]::EscapeDataString($str)
}
# === BUILD QUERY STRING (encoded) ===
$queryParams = @{
name = $workflowName
assignedUse = $assignedUse
overwriteExisting = $overwriteExisting
publishWhenConfigured = $publishWhenConfigured
}
$queryString = ($queryParams.GetEnumerator() | ForEach-Object {
"$(Encode-UriComponent $_.Key)=$(Encode-UriComponent $_.Value)"
}) -join "&"
$uri = "$apiUrl`?$queryString"
Write-Host "Request URI:" $uri -ForegroundColor DarkGray
# === PREPARE HTTP CLIENT ===
$handler = New-Object System.Net.Http.HttpClientHandler
$client = New-Object System.Net.Http.HttpClient($handler)
$client.DefaultRequestHeaders.Authorization = New-Object System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", $token)
$client.DefaultRequestHeaders.Accept.Add([System.Net.Http.Headers.MediaTypeWithQualityHeaderValue]::new("application/json"))
# === BUILD MULTIPART FORM DATA ===
$content = New-Object System.Net.Http.MultipartFormDataContent
$fileStream = [System.IO.File]::OpenRead($packagePath)
$fileContent = New-Object System.Net.Http.StreamContent($fileStream)
$fileContent.Headers.ContentType = [System.Net.Http.Headers.MediaTypeHeaderValue]::Parse("application/zip")
$content.Add($fileContent, "workflowDeploymentPackage", [System.IO.Path]::GetFileName($packagePath))
# === SEND REQUEST ===
Write-Host "`nUploading package '$packagePath' to Nintex..." -ForegroundColor Cyan
try {
$response = $client.PostAsync($uri, $content).Result
$body = $response.Content.ReadAsStringAsync().Result
if ($response.IsSuccessStatusCode) {
Write-Host "`n✅ Import successful!" -ForegroundColor Green
try {
$json = $body | ConvertFrom-Json
$json.workflows | Format-List
} catch {
Write-Host "Response:" $body
}
} else {
Write-Host "`n❌ Import failed: $($response.StatusCode)" -ForegroundColor Red
Write-Host "Response body:"
Write-Host $body
}
}
catch {
Write-Host "`n❌ Exception:" $_.Exception.Message -ForegroundColor Red
}
finally {
if ($fileStream) { $fileStream.Dispose() }
if ($client) { $client.Dispose() }
}