Describe the problem/error/question
I am trying to update the credentials on a workflow so that I can cycle through several sets of credentials I need to pull the same data for.
So in the beginning of the workflow, I get the contents of the other workflow with a n8n Get Workflow node.
Subsequently, in a code node, I update the credentials to an exact copy of the credentials object in the node like so:
workflow = items[0].json.workflow;
workflow.nodes.forEach(node => {
if (node.credentials && node.credentials.someOAuth2Api) {
node.credentials = items[0].json.credentials;
}
});
var results = { workflow: {}};
results.workflow.nodes = JSON.stringify(workflow.nodes);
results.workflow.settings = workflow.settings
results.workflow.name = workflow.name;
results.workflow.connections = workflow.connections;
return results;
However, no matter what I do when I try to send the Update Workflow it gives me the following error:
NodeApiError: The 'workflowObject' property must be valid JSON, but cannot be parsed
at RoutingNode.runNode (/usr/local/lib/node_modules/n8n/node_modules/n8n-workflow/dist/RoutingNode.js:117:23)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at Workflow.runNode (/usr/local/lib/node_modules/n8n/node_modules/n8n-workflow/dist/Workflow.js:733:23)
at /usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/WorkflowExecute.js:656:53
I have tried a million different ways to format workflowObject but it fails. I am also not quite sure what that error means. What is the expected format for this endpoint?
Here is the workflow object:
"connections": {
"Execute Workflow Trigger": {
"main": [
[
{
"index": 0,
"node": "getCompanyInfo",
"type": "main"
}
]
]
}
},
"name": "Dev - QBO - GetCompanyInfo",
"nodes": "[{\"parameters\":{},\"id\":\"someId\",\"name\":\"Execute Workflow Trigger\",\"type\":\"n8n-nodes-base.executeWorkflowTrigger\",\"typeVersion\":1,\"position\":[460,240]},{\"parameters\":{\"url\":\"=https://quickbooks.api.intuit.com/v3/company/{{ $json.QuickbooksCompanyId }}/query\",\"authentication\":\"predefinedCredentialType\",\"nodeCredentialType\":\"quickBooksOAuth2Api\",\"sendQuery\":true,\"queryParameters\":{\"parameters\":[{\"name\":\"query\",\"value\":\"SELECT Metadata.CreateTime from CompanyInfo \"}]},\"options\":{}},\"id\":\"someThatId\",\"name\":\"getCompanyInfo\",\"type\":\"n8n-nodes-base.httpRequest\",\"typeVersion\":4.1,\"position\":[660,240],\"credentials\":{\"quickBooksOAuth2Api\":{\"id\":\"someOtherId\",\"name\":\"Quickbooks - someClient\"}}}]",
"settings": {
"executionOrder": "v1"
},
"staticData": null
}
and here is the workflow itself:
- n8n version: Latest
- Database (default: SQLite): Postgres
- n8n EXECUTIONS_PROCESS setting (default: own, main): Not sure how to find this out
- Running n8n via (Docker, npm, n8n cloud, desktop app): kubernetes Google Cloud self hosted