Get an URL from a document that is not always the same

Hello guys!
I am creating my first “advanced” workflow, I want to have an AI agent to help me creating/updating documents depending on what the user enters in the chat, the document is not always the same so the URL changes. The error I get is when updating an existing document I cannot find it. In the “Update document” node you are meant to introduce a URL, I give it this: Doc ID or URL: {{ $json.webViewLink }} - Error: The resource you are requesting could not be found.

I cannot put the whole workflow as I am new to the community but the part of the workflow that has the error is this one:

The input of the “Search files and folders” node is the output of the AI Agent (it is normally a summary of a topic) to be pasted in a new doc or if the user ask to “update” a specific document it will just add the “summary” to the document. I put the “merge” node to get the AI agent answer and {{ $json.webViewLink }}. I thought that will work when getting to the “update doc” step. Can you help me to get the “dynamic” URL to put it in this node, please?

{
“nodes”: [
{
“parameters”: {
“resource”: “fileFolder”,
“queryString”: “={{ $json.output.doc_name }}”,
“returnAll”: true,
“filter”: {},
“options”: {
“fields”: [
“webViewLink”
]
}
},
“type”: “n8n-nodes-base.googleDrive”,
“typeVersion”: 3,
“position”: [
-1344,
240
],
“id”: “3f8ef2ed-5014-44ca-8022-92a9a6410b8b”,
“name”: “Search files and folders”,
“credentials”: {
“googleDriveOAuth2Api”: {
“id”: “rOsooSdJFLSt37Sc”,
“name”: “Google Drive account”
}
}
},
{
“parameters”: {},
“type”: “n8n-nodes-base.merge”,
“typeVersion”: 3.2,
“position”: [
-1088,
144
],
“id”: “afbc6cab-1e8e-4e53-8499-60cc660bebc5”,
“name”: “Merge”
},
{
“parameters”: {
“operation”: “update”,
“documentURL”: “={{ $json.webViewLink }}”,
“simple”: false,
“actionsUi”: {
“actionFields”: [
{
“action”: “insert”,
“text”: “={{ $(‘First AI Agent’).item.json.output.content }}”
}
]
}
},
“type”: “n8n-nodes-base.googleDocs”,
“typeVersion”: 2,
“position”: [
-880,
144
],
“id”: “06def75b-35b4-4e9f-bf04-4bc9f2a77a1a”,
“name”: “Update a document”,
“executeOnce”: true,
“credentials”: {
“googleDocsOAuth2Api”: {
“id”: “p5DzvYpEkfQa1AKn”,
“name”: “Google Docs account”
}
}
}
],
“connections”: {
“Search files and folders”: {
“main”: [
[
{
“node”: “Merge”,
“type”: “main”,
“index”: 1
}
]
]
},
“Merge”: {
“main”: [
[
{
“node”: “Update a document”,
“type”: “main”,
“index”: 0
}
]
]
}
},
“pinData”: {},
“meta”: {
“templateCredsSetupCompleted”: true,
“instanceId”: “8960daadaa8aa08bf0d0a420a31a5c284303d6bfda1f02cd074ee501fc36966e”
}
}

Information on your n8n setup

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app): n8n via cloud
  • Operating system: Windows 11Pro

You’re using the Merge Node in Append mode, this is giving back 2 separate items. One is just the prompt, the other is just the result of the GDrive Upload. The next step will be then triggered twice (the amount of items). This is why your reference is not working. Because one item does not include the WebViewLink.

Solution: Change the Merge Node to Combine Mode, this will return just 1 item including all information from the Upload node and the previous Switch Node, which should include the response from the Agent.

2 Likes

Oki @salmansolutions,it seems to recognize it, thanks for that, however now I have a “Bad request” error, I tried with both URL and ID and the AI n8n gives me that solution but didn’t work, I understand the error but neither ways work…any idea if it’s me again or the google API?:

Error code

400

Full message

{ "error": { "code": 400, "message": "Request contains an invalid argument.", "status": "INVALID_ARGUMENT" } }

Are you sure that the file you want to update is an Google Docs File?
If you provide an id of lets say a pdf, or text file, this error would occur.

If you created the file prior in your workflow, make sure to set the toggle for “Convert to Google Drive Document”. Otherwise you won’t be able to update it via the “Update a document” Node.

For better assistance, copy the whole Workflow (redact sensitive information) into your response, but make sure to use the Code Block by clicking the </> Symbol.

3 Likes

All good! I fix the issue, there was another file with the same name outside of the folder and it was generating issues when reading the URL/ID. Thanks for your guidance @salmansolutions ! It help me to figured out where the confusion was!

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.