HTTP Request GET with body

I’m trying to use Seatable API (self hosted), and before creating a row I’d like to check if it already exists. Unfortunately the API requires GET method with the filters in the body and I can’t do that with n8n (no body field shown when GET selected).

I’m thinking of trying to use execute node to call a python script instead (but have to install python in docker, script it and so).

Any idea on how to overcome this?

This is the API documentation:
https://api.seatable.io/#65efccf8-1b3e-49a1-aeed-9df75dcadca9

thanks in advance

Welcome to the community @Lucas_Couto

I would make the HTTP request from a function node instead. By default, requiring packages it’s not allowed, but you can enable it by setting env variables below:

export NODE_FUNCTION_ALLOW_BUILTIN=util

export NODE_FUNCTION_ALLOW_EXTERNAL=request

After that, to make a GET request, you can do something similar to:

const request = require('request')
const { promisify } = require('util');
const rq = promisify(request);


const data = await rq({
uri: "https://pokeapi.co/api/v2/pokemon/ditto",
method: 'GET'
})
return [
  {
    json: JSON.parse(data.body)
  }
];
Example workflow
{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        210,
        300
      ]
    },
    {
      "parameters": {
        "functionCode": "// Code here will run only once, no matter how many input items there are.\n// More info and help: https://docs.n8n.io/nodes/n8n-nodes-base.function\nconst request = require('request')\nconst { promisify } = require('util');\nconst rq = promisify(request);\n\n\nconst data = await rq({\nuri: \"https://pokeapi.co/api/v2/pokemon/ditto\",\nmethod: 'GET'\n})\nreturn [\n  {\n    json: JSON.parse(data.body)\n  }\n];"
      },
      "name": "Function",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        840,
        170
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Function",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Of course, at all that is assuming that you are self-hosting. If you are using n8n cloud, you do not need to set the env variables.

With regards to not being able to sent a body when doing a GET request. We are aware of that limitation as it’s something that we would include in the version 2 of the node.

Hi @RicardoE105 and @Lucas_Couto,

Sorry, but I have to say that the answer above is incomplete. You cannot pass a body element in the request options if the method is ‘GET’ with the code offered. It will simply ignore it as per the request module specification:

  • body - entity body for PATCH, POST and PUT requests. Must be a Buffer, String or ReadStream. If json is true, then body must be a JSON-serializable object. (Source: request - npm)

@Lucas_Couto if you haven’t figured it out by yourself, you have to use a HAR 1.2 request to get the body to pass. Here’s an example code for your case:

const request = require('request');
const { promisify } = require('util');
const rq = promisify(request);

var body = JSON.stringify(
  // Put your request body here
  { 
    "filters":[
      {
        "column_name": "name", 
        "filter_predicate": "contains", 
        "filter_term": "bob", 
        "filter_term_modifier": ""
      },
      {
        "column_name": "name", 
        "filter_predicate": "contains", 
        "filter_term": "john", 
        "filter_term_modifier": ""
      }
    ],
    "filter_conjunction": "Or"
  }
);

const data = await rq({
  har: {
    url: "{{your-server}}/dtable-server/api/v1/dtables/{{your-base-id}}/filtered-rows/?table_name={{table_name}}",
    method: "GET",
    headers: [ 
      {
        name: "Authorization",
        value: "Token {{your-base-token}}"
      }
    ],
    postData: {
      "mimeType": "application/json",
      "text": body
    }  
  }
})
return [
  {
    json: data.body
  }
];