When exporting workflows via the API, Powershell ( 7.5.0 Core) is unable to parse the returned JSON. There are some ""
fields in the output.
Does anybody have a workaround for this?
Demo script:
param (
[Parameter(Mandatory = $true)] [string] $n8nApiKey
, [Parameter(Mandatory = $true)] [System.Uri] $n8nUrl
, [Parameter(Mandatory = $true)] [System.IO.FileInfo] $OutputFolder
)
#foreach
$headers = @{
'X-N8N-API-KEY' = $n8nApiKey
accept = 'application/json'
}
# This should automatically be converted to an object, instead, I get a string
$ret = Invoke-RestMethod -Method Get -Uri ("{0}api/v1/workflows?&excludePinnedData=true&limit=250" -f $n8nUrl.AbsoluteUri) -Headers $headers -ContentType 'application/json'
Write-Host $ret.GetType().Name
$workflows = ConvertFrom-Json -InputObject $ret
foreach($workflow in $workflows.data) {
$filePath = Join-Path -Path $OutputFolder -ChildPath ("{0}.json" -f ($workflow.name -replace ':',"_"))
$workflow | ConvertTo-Json -Depth 100 | Out-File $filePath
}
Normally, Invoke-RestMethod
would automatically convert the result to an object. Instead, I get a string. When I try to convert that string, I get this exception from ConvertTo-Json
.
$workflows = ConvertFrom-Json -InputObject $ret
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| The provided JSON includes a property whose name is an empty string, this is only supported using the -AsHashTable switch.
This ""
seems to be the offending section:
{
"parameters": {
"curlImport": "",
"httpVariantWarning": "",
"method": "POST",
"url": "https://api.crowdstrike.com/identity-protection/combined/graphql/v1",
"": "",
"authentication": "predefinedCredentialType",
"nodeCredentialType": "crowdStrikeOAuth2Api",
"provideSslCertificates": false,
"sendQuery": false,
"sendHeaders": false,
"sendBody": true,
"contentType": "json",
"specifyBody": "json",
"jsonBody": "={{ $json.toJsonString() }}",
"options": {},
"infoMessage": ""
},
Information on your n8n setup
Debug info
core
- n8nVersion: 1.86.1
- platform: docker (self-hosted)
- nodeJsVersion: 20.19.0
- database: sqlite
- executionMode: regular
- concurrency: -1
- license: enterprise (production)