# n8n (/growsocmed/docs/n8n)

Use GrowSocmed from n8n workflows.

n8n can work with GrowSocmed in three ways: an AI agent that uses GrowSocmed's MCP tools, plain HTTP requests to the REST API, and webhooks that start a workflow when something happens in GrowSocmed. All three need an API key from **Developer** → **API keys** and a paid plan.

## Before you start [#before-you-start]

1. In GrowSocmed, open **Developer** → **API keys** → **Create API key**. Pick the workspace (or all workspaces) and **Read & write** or **Read only**.
2. Copy the key (`gs_…`). It is shown only once.
3. In n8n, create a credential that sends it as a bearer token (`Authorization: Bearer gs_…`).

## An AI agent with GrowSocmed tools [#an-ai-agent-with-growsocmed-tools]

1. Add an **AI Agent** node and give it an **MCP Client Tool**.
2. Fill in the tool:

```txt
Endpoint: https://socmed.growpaces.com/api/mcp
Server Transport: HTTP Streamable
Authentication: Bearer Auth
Token: gs_...
```

The agent can then list accounts, create posts, read comments and so on, the same tools as in [Connect an AI assistant](/growsocmed/docs/connect-ai). For a key that covers all your workspaces, see the `X-Workspace` header on [MCP server](/growsocmed/docs/developers/mcp).

## HTTP requests to the REST API [#http-requests-to-the-rest-api]

Use an **HTTP Request** node with your bearer credential. For example, to schedule a post:

```txt
Method: POST
URL: https://socmed.growpaces.com/api/v1/posts
Headers: Idempotency-Key = {{ $json.id }}
Body (JSON):
{
  "text": "New stock is in",
  "targets": [{ "account_id": "6b1e…" }],
  "scheduled_at": "2026-12-01T09:00:00+07:00"
}
```

- Get account ids from `GET /api/v1/accounts`.
- An `Idempotency-Key` taken from your own data (a row id, an order number) makes a rerun of the workflow create nothing twice.
- To post a file, first copy it into the media library with `POST /api/v1/media/from-url` (a public `https://` link), wait until `GET /api/v1/media/{id}` shows `ready`, then pass its id in `media_ids`.
- If the post breaks a platform's rule, the answer is `400 validation_failed` with the problem per account.

Every endpoint is in the [API Reference](/growsocmed/docs/api-reference); start with [REST API](/growsocmed/docs/developers) and [Posts](/growsocmed/docs/developers/posts).

## Start a workflow from GrowSocmed [#start-a-workflow-from-growsocmed]

1. Add a **Webhook** node in n8n, method POST, and copy its production URL. It must be a public `https://` address.
2. In GrowSocmed, open **Developer** → **Webhooks** → **Add webhook**, paste the URL and pick the events, for example `post.failed` or `comment.created`.
3. Save the secret shown once. **Send test event** sends `webhook.test` so you can see the data in n8n.

Answer quickly: GrowSocmed waits 5 seconds for a `2xx` and tries again later otherwise, so let the Webhook node respond immediately and do the work after. To check that a request really comes from GrowSocmed, verify the `Grow-Signature` header in a Code node; see [Webhooks](/growsocmed/docs/developers/webhooks#verify-the-signature).

## Ideas for workflows [#ideas-for-workflows]

- A new row in a spreadsheet schedules a post.
- A failed post sends a message to your team chat.
- New comments go to your CRM or a support tool.
- A weekly workflow reads statistics and writes them to a report.