Ghost Admin API: create members

Can you please share your workflow to see If I can spot the issue?

Alright, here it goes

{
  "name": "Create members",
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "functionCode": "items[0].json.name = $node[\"New sub activated\"].json[\"body\"][\"resource\"][\"subscriber\"][\"name\"][\"given_name\"];\nitems[0].json.surname = $node[\"New sub activated\"].json[\"body\"][\"resource\"][\"subscriber\"][\"name\"][\"surname\"];\nitems[0].json.email = $node[\"New sub activated\"].json[\"body\"][\"resource\"][\"subscriber\"][\"email_address\"];\nitems[0].json.country_code = $node[\"New sub activated\"].json[\"body\"][\"resource\"][\"subscriber\"][\"shipping_address\"][\"address\"][\"country_code\"];\n\n// You can write logs to the browser console\nconsole.log('Done!');\n\nreturn items;"
      },
      "name": "Catch response",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        700,
        380
      ]
    },
    {
      "parameters": {
        "functionCode": "return [\n  {\n    json: {\n      members: [\n      {\n         \"name\": $node[\"Catch response\"].json[\"name\"] + \" \" + $node[\"Catch response\"].json[\"surname\"], \n         \"email\": $node[\"Catch response\"].json[\"email\"],\n         \"note\": $node[\"Catch response\"].json[\"country_code\"],\n         \"subscribed\": true,\n      }\n      ]\n    }\n  },\n]"
      },
      "name": "Prepare data for export",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        900,
        380
      ]
    },
    {
      "parameters": {
        "functionCode": "const jwt = require('jsonwebtoken');\n\nconst version = 'v2';\nconst apiKey = 'key:secret';\n\t\t// Create the token (including decoding secret)\nconst [id, secret] = apiKey.split(':');\n\nconst token = jwt.sign({}, Buffer.from(secret, 'hex'), {\n\tkeyid: id,\n\talgorithm: 'HS256',\n\texpiresIn: '5m',\n\taudience: `/${version}/admin/`,\n});\n\nreturn [\n  {\n    json: {\n      token,\n    }\n  }\n]"
      },
      "name": "Create jwt token",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        1110,
        380
      ]
    },
    {
      "parameters": {
        "requestMethod": "POST",
        "url": "https://mydomain.com/ghost/api/canary/admin/members/?include=labels,email_recipients",
        "options": {},
        "bodyParametersUi": {
          "parameter": [
            {
              "name": "members",
              "value": "={{$node[\"Prepare data for export\"].json[\"members\"]}}"
            }
          ]
        },
        "headerParametersUi": {
          "parameter": [
            {
              "name": "Authorization",
              "value": "=Ghost ${{$json[\"token\"]}}"
            }
          ]
        }
      },
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        1310,
        380
      ]
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "103aa3a3-af62-4406-be5b-bbx33447b3a5",
        "options": {}
      },
      "name": "New sub activated",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [
        510,
        380
      ],
      "webhookId": "103aa3a3-af62-4406-be5b-bbx33447b3a5"
    }
  ],
  "connections": {
    "HTTP Request": {
      "main": [
        []
      ]
    },
    "Catch response": {
      "main": [
        [
          {
            "node": "Prepare data for export",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare data for export": {
      "main": [
        [
          {
            "node": "Create jwt token",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "New sub activated": {
      "main": [
        [
          {
            "node": "Catch response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create jwt token": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {},
  "id": "11"
}

Noticed that you have an extra $ in the authorization header: Ghost ${{$json["token"]}}. Remove that extra $ and try again.

Good day to you Ricardo,

that was on purpose, because the alternative returns this error:

ERROR: UNKNOWN ERROR - check the detailed error for more information
Invalid token: jwt audience invalid. expected: /\/?canary\/admin\/?$/

full


"status": "rejected",
"reason": {
"name": "StatusCodeError",
"statusCode": 401,
"message": "401 - {"errors":[{"message":"Invalid token: jwt audience invalid. expected: /\\/?canary\\/admin\\/?$/","context":null,"type":"UnauthorizedError","details":null,"property":null,"help":null,"code":"INVALID_JWT","id":"7696d5b0-4dc7-11ec-a4b0-312aea5f6t7z"}]}",
"error": {
"errors": [
{
"message": "Invalid token: jwt audience invalid. expected: /\/?canary\/admin\/?$/",
"context": null,
"type": "UnauthorizedError",
"details": null,
"property": null,
"help": null,
"code": "INVALID_JWT",
"id": "7696d5b0-4dc7-11ec-a4b0-312aea5f6t7z"
}
]
}, 

might be then that the JWT token generation flow needs another adjustment.