Multiple call twitter node according to results set

Hi,

I have a very basic workflow that created with 3 nodes; cron → http request → twitter

Screen Shot 2022-01-05 at 12.28.12

I got multiple results from http requests and I want to send this data one by one through twitter node. Is this possible?

Sample data set;

[
    {
        "body":  {
            "count": 10,
            "next": null,
            "previous": null,
            "results": [
                {
                    "id": 6,
                    "title": "lorem ipsum dolor ..."
                },
                ...
            ]
        },
        "headers": {},
        "statusCode": 200,
        "statusMessage": "OK"
    }
]
  • n8n version: 0.157.1
  • Running n8n via: Docker

Hey @ued, welcome to the community!

This should be possible with the workflow you have described. Nodes will run once for each item they receive (with a few exceptions). So if your HTTP Request node returns 5 items, your Twitter node would run through each of these 5 items.

Looking at the example data you have provided you would need to transform the single result into individual n8n items first though. The Item Lists node can help you with that and split out the body.results field from your example data.

1 Like

@MutedJam Thank you for the quick response.

I am just read the documentation about Item lists and this is awesome. Split out the results set as list items and then twitter node can handle loop per item. Thank you!

1 Like

Awesome, glad to hear this works for you!

@MutedJam Is there any way to use twitter node with essential account type?

I have seen that answer but we’re planning to use n8n on cloud. So, don’t know how to change that url.

Thanks.

Not via the node at the moment, I am afraid. However, you should be able to request elevated access by following the steps in the documentation (from step 14 onwards, assuming you have completed the previous ones):

We actually requested for elevated access but it was not approved :disappointed:

Oh no :frowning_face:, I am really sorry to hear that. If Twitter doesn’t grant you elevated access, it’s unfortunately not possible to use their API v1.1 endpoints used by the Twitter node.

That means until we have developed a node using Twitter’s v2 API you would have to use the HTTP Request node to talk to this Twitter API directly. A simple example workflow fetching Tweets would be available here. Other endpoints are listed in their docs, e.g. this one for posting Tweets.

The credentials I’ve used to authenticate with Twitter here are OAuth1 credentials with the following values:

Authorization URL: https://api.twitter.com/oauth/authorize
Access Token URL: https://api.twitter.com/oauth/access_token
Request Token URL: https://api.twitter.com/oauth/request_token
Consumer Key: The API Key shown in Twitter’s developer portal
Consumer Secret: The API Key Secret shown in Twitter’s developer portal
Signature Method: HMAC-SHA1

Let me know if you run into any trouble with this!

1 Like

Thank you for the idea!

We did everything you said but this time we got error like;

{"status":"rejected","reason":{}}

NodeApiError: UNKNOWN ERROR - check the detailed error for more information
    at Object.execute (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/HttpRequest/HttpRequest.node.js:882:27)
    at async /usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/src/WorkflowExecute.js:447:47

Can you expand the error details (assuming you are seeing this error on the HTTP Request node)? This should reveal the full response from Twitter, like so:

Here it is;

Oh, so Twitter is not saying why they are rejecting your request? That’s very odd, I have not seen this before. Were you able to authenticate with Twitter previously, like so?

image

And could you share your HTTP Request node (seeing it seems to differ from the one in the example flow)? Simply select it on your canvas and press Ctrl+C, you should then be able to share the JSON here on the forum.

Yes, account connection was succesful.

Screen Shot 2022-01-06 at 13.51.27

It’s seem a little bit weird.

HTTP Request Node

It seems that I had a problem with my local docker container. I restarted docker container and this time it’s worked perfectly :rocket:

@MutedJam thank you again for your help!

1 Like

Well, the very same node works for my account (I’ve just put a Set node in front of it setting a title field) :frowning:

image

So your syntax seems to be correct. I also assume you’re not tweeting something Twitter might reject because of the content? Or in other words, does this also happen when trying to Tweet something like “hello world”?

Edit: Missed your last response, glad to hear it’s now working. Thanks so much for confirming @ued!

1 Like