Code Tool Example with a RapidAPI Python code

Hi, i´m just testing the CODE TOOL ( LANGCHAIN) and wonder if you have any example of how to use it with a GET REQUEST for example. I had tested with Python with no success. ( ERROR UNDEFINDED)
And also how to Pass the Payload with-in the CODE. thanks!

here es the code use it:
import http.client

conn = http.client.HTTPSConnection(“”)

headers = {
‘X-RapidAPI-Host’: “

conn.request(“GET”, “/search-social-links?query=John%20Smith&social_networks=facebook%2Ctiktok%2Cinstagram%2Csnapchat%2Ctwitter%2Cyoutube%2Clinkedin%2Cgithub%2Cpinterest”, headers=headers)

res = conn.getresponse()
data =


Hi @Juan_Merodio, welcome to the community!

The Python support in n8n is based on Pyodide, which means you can only use some packages: Code node | n8n Docs

http.client is not among these, the respective issue is still open:

So perhaps you want to consider using JS code here? You can use this.helpers.httpRequest to make HTTP Requests as part of n8n’s code snippets, our documentation and this forum have a few examples (mostly for the original Code node and custom nodes, but they should work regardless of where they are used).

1 Like

Thanks a lot! :wink: by the way will be great if you can point me to the JS code as i´m not sure what i have to look for. thanks again! :wink:

You can try something like this. I can’t test it without valid credentials, though.

const headers = {
    'X-RapidAPI-Host': ''

const options = {
    uri: '',
    qs: {
        query: 'John Smith',
        social_networks: 'facebook,tiktok,instagram,snapchat,twitter,youtube,linkedin,github,pinterest'
    headers: headers,
    method: 'GET',
    json: true

return this.helpers.httpRequest(options)
    .then(response => {
        // Assuming response is an array of objects
        return => {
            return {
                json: item
    .catch(error => {
        // Return an empty array on error
        return [];
1 Like