I am in the process of moving everything from Zapier and I am getting most of it, but I am stuck at the most simple thing. the error I am getting is
ERROR: NameError: name 'input_data' is not defined
Error: NameError: name 'input_data' is not defined
at PythonSandbox.getPrettyError (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Code/PythonSandbox.js:69:20)
at PythonSandbox.runCodeInPython (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Code/PythonSandbox.js:56:24)
at PythonSandbox.runCodeAllItems (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Code/PythonSandbox.js:22:33)
at Object.execute (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Code/Code.node.js:113:25)
at Workflow.runNode (/usr/local/lib/node_modules/n8n/node_modules/n8n-workflow/dist/Workflow.js:658:19)
at /usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/WorkflowExecute.js:631:5
and I have a feeling it is because I am not telling it what the input is from the previous node, the ZPID in my case.
But I have read the docs up and down and cannot find where it specifically says how to do this. it is probably my lack of experience with python that is my roadblock
Hi @djjace, n8n would reference input data in a slightly different way. Assuming the data you are interested in lives in the zpid field, you’d need to use _input.item.json.zpid instead of input_data.get('zpid').
Let me know if you run into any trouble with this!
Error: NameError: name 'zpid' is not defined
at PythonSandbox.getPrettyError (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Code/PythonSandbox.js:69:20)
at PythonSandbox.runCodeInPython (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Code/PythonSandbox.js:56:24)
at PythonSandbox.runCodeAllItems (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Code/PythonSandbox.js:22:33)
at Object.execute (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Code/Code.node.js:113:25)
at Workflow.runNode (/usr/local/lib/node_modules/n8n/node_modules/n8n-workflow/dist/Workflow.js:658:19)
at /usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/WorkflowExecute.js:631:53
I’m so sorry @djjace. Can you share the JSON data structure you are passing on to your final code node so I can reproduce (and hopefully fix) the problem? You can of course redact anything confidential, just make sure to keep the structure itself.
It looks like you’re simply referencing a non-existent field here. As for the actual logic you probably want to use the existing HTTP Request node for your request rather than write custom code. But let’s take a look at your data structure first and then worry about the exact implementation
Also, I’ll removed your own API key from your previous post. To be on the safe side you would still want to rotate it.
Yes, much better. The requests module used in your code is unfortunately not available in n8n’s Python implementation, so even once the syntax problems are sorted this wouldn’t work using the snippet provided.
On the plus side, the HTTP Request node is much easier to use and won’t require code. What your code does is this:
Send a GET request to https://zillow-com1.p.rapidapi.com/property
Use a query string including the zpid value from your previous code snippet
Add two custom headers
In a workflow using the HTTP Request node this would look like so:
This example uses credentials to store your API key. You’d need to configure them once as shown below (name = X-RapidAPI-Key, value = your actual API key) and can then re-use them in every HTTP Request node you might be using in any of your workflows, without having to add your API key in clear text to your nodes:
You can also see that I am using an expression in my HTTP Request node to read the incoming zpid value. You wouldn’t have to write this manually, simply drag and drop the value you want to use in the target field: