Hello! I just discovered this forum yesterday and it helped me to start on n8n. However after a few hours of search, I’m definitely hitting a road-block :
I’m trying to simply read a Google Sheet, then HTTP request each result (via an API successfully tested for a single result). What worked :
- Node : Read the google sheet → Got all the results line by line.
- Node : HTTP request GET → The result was a success with the details I want to fetch, if I write the query manually.
However what didn’t work, is the input data from the Google Sheet into the HTTP request.
-
Read Google Sheet (usernames) : column A → A1:A100 :
Data Property : data (= output result I think)
Edward
Pascal
Thomas
… these show in successive rows
-
HTTP request (GET) :
URL : https://****************rapidapi.com/user/details
…
…
Query Parameters : Name : username and value : {data}
- WORKFLOW :
- OUTPUT (LAST NODE) :
[
{
"detail": "Twitter user with username = {data} not found"
}
]
The flow look like this :
So each node works good separately, but can’t input the variable {data} into the HTTP request node …
Thank you for your ideas… !
Hi @David_Steg, welcome to the community!
What you’re looking for here are n8n’s expressions. The easiest way to add them (assuming you are using a recent version of n8n) would be to first run your Google Sheets node, then drag and drop the value you want to use into your query parameter field.
Like so:
In this example, the email value of each item would be used in the HTTP Request (though only the first one is shown in the preview). You can then click on the field to inspect the expression being used here. If your Google Sheet column is called data, the expression would be something like {{ $json["data"] }}
Hope this helps!
Thank you for your reply! A lot !
Apparently the n8n Dekstop app version I use isn’t updated, and can’t find a way to update it. So I can’t drag and drop like you did, unfortunately.
- I tried to input in “Value” the {{ $json[“data”] }} as you said, but it returned this :
[{
"body": {
"detail": "Twitter user with username = {{ $json[\"data\"] }} not found"
},
"headers": {
"date": "Tue, 20 Sep 2022 12:45:45 GMT",
"content-type": "application/json",
"content-length": "73",
"connection": "close",
"via": "1.1 vegur",
"x-ratelimit-requests-limit": "50000",
"x-ratelimit-requests-remaining": "49966",
"x-ratelimit-requests-reset": "2577635",
"server": "RapidAPI-1.2.8",
"x-rapidapi-version": "1.2.8",
"x-rapidapi-region": "AWS - eu-central-1"
},
"statusCode": 200,
"statusMessage": "OK"
}]
- Ideally, I woull also need to put a delay between Google Sheet (Read) and the HTTP request, is the delay node of 2 seconds between those 2 nodes, and looping all those 3 nodes would be a good idea ?
Thank you so much!
Hi @David_Steg, the error coming from your API sounds like you’re using {{ $json["data"] }}
as text rather than as an expression. Can you make sure to add an expression like so:
The expression editor should then open and after entering your expression should also show a preview of how the value is resolved:
- Ideally, I woull also need to put a delay between Google Sheet (Read) and the HTTP request, is the delay node of 2 seconds between those 2 nodes, and looping all those 3 nodes would be a good idea ?
Building a loop shouldn’t be necessary though, the HTTP Request node will (like most n8n nodes) for all incoming items automatically. If you want to slow down the requests made by the node you can use the Batch Interval and Batch Size options offered by the node:
Thanks so much! I could successfully make the expression as you said, in the expression editor. The problem with that editor is that the “Value” returned is an array (as shown on the picture) and the result says : Rejected, “field required” and “value_error.missing”
It works perfectly with 1 username as a value, but not with all the values as an array, that the editor returned. Am I missing some syntax error here ?
Thanks a lot
About the Batch Interval, it should work once the first iteration of the array can make it !
Hi @David_Steg, this looks like a rather unusual data structure. Perhaps you can normalize it a bit before using it in the HTTP Request node? For example, like so?
In this example I am first using the Item Lists node to split up the single item and its data
array into individual items, followed by a Rename Keys node to give the first array element (0
) a name of data again. This ultimately transforms the input structure you have into individual n8n items the HTTP Request node should be able to process more easily:
Thanks so much. It worked perfectly, i was able to make the calls and get the results back.
The last step is to write to the Google Sheet and I think I’m quite close to it !
I used the Google Sheet Update operation, like on the screenshot. In short, I want the results that are being read from A1:A100 of the sheet, to be paster on the rows D1:D100 ; what should be pasted is each result (“body” on the left of screenshot). So it would write “Username not found” for example.
Looks like the Key row is messing with me, and I couldn’t find any informations about it. Or maybe the Update operation isn’t the right one ?
Thank you so much