Add mutiple contacts to a segment - 400 Bad Request

Your software
My Mautic version is: 7.0.0
My PHP version is: 8.3.30
My Database type and version is: MySQL 8.4.8

Your problem

Trying to perform a API request for adding a batch of contacts to a given segment (through n8n) always returns an HTTP 400 Bad Request error. I’m not sure how my syntax is incorrect here, I’ve tried to follow the documentation as close as possible.

{
  "errorMessage": "Bad request - please check your parameters [item 0]",
  "errorDescription": "This is a bad request.",
  "errorDetails": {
    "rawErrorMessage": [
      "400 - \"{\\\"errors\\\":[{\\\"code\\\":400,\\\"message\\\":\\\"This is a bad request.\\\",\\\"details\\\":[]}]}\""
    ],
    "httpCode": "400"
  },
  "n8nDetails": {
    "nodeName": "Segmente les contacts dans Mautic",
    "nodeType": "n8n-nodes-base.httpRequest",
    "nodeVersion": 4.4,
    "itemIndex": 0,
    "time": "30/06/2026 15:57:39",
    "n8nVersion": "2.21.1 (Self Hosted)",
    "binaryDataMode": "database",
    "stackTrace": [
      "NodeApiError: Bad request - please check your parameters",
      "    at ExecuteContext.requestWithAuthentication (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-core@file+packages+core_@opentelemetry+api@1.9.0_@opentelemetry+exporter-trace-otlp_2c2e1f47b69b34bef6f634a13cbf61d9/node_modules/n8n-core/src/execution-engine/node-execution-context/utils/request-helper-functions.ts:1368:10)",
      "    at processTicksAndRejections (node:internal/process/task_queues:104:5)",
      "    at ExecuteContext.requestWithAuthentication (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-core@file+packages+core_@opentelemetry+api@1.9.0_@opentelemetry+exporter-trace-otlp_2c2e1f47b69b34bef6f634a13cbf61d9/node_modules/n8n-core/src/execution-engine/node-execution-context/utils/request-helper-functions.ts:1711:11)"
    ]
  }
}

I’ve tried to pass the query parameters outside the request body, but I get the same error.

For the batch endpoint, Mautic returns that generic 400 when it can’t find an `ids` array in the request. Check these:

- **URL:** `POST https://your-mautic/api/segments/{SEGMENT_ID}/contacts/add`. Put the segment ID in the path, not in a query parameter.

- **Body:** send JSON with the header `Content-Type: application/json`, and make `ids` a real array of numbers:

```json

{ “ids”: [12, 34, 56] }

```

- In n8n, a common gotcha is that “Specify Body → Using Fields” sends `ids` as the string `“12,34,56”` or `“[12,34,56]”`. Mautic rejects that. Switch to **Using JSON** and build it with an expression, e.g. `{{ JSON.stringify({ ids: $json.contactIds }) }}` (or `{ “ids”: {{ JSON.stringify($json.contactIds) }} }`), so it ends up as a real array.

- If you’d rather send form-encoded data, the key has to be `ids[]`, repeated once per contact, not `ids`.

To test without n8n:

```

curl -u user:pass -X POST -H ‘Content-Type: application/json’ \

-d ‘{“ids”:[12,34]}’ https://your-mautic/api/segments/5/contacts/add

```

If curl works, the problem is the way n8n builds the body. Also make sure API and HTTP basic auth are enabled under Configuration → API Settings.