Facebook Pixel
Fit'DistanceDocumentation
Open the app
On this page

An Instagram DM → an activation code, with ManyChat

When someone sends you a keyword in an Instagram direct message, ManyChat replies with an activation code created by Fit'Distance, with n8n or Make.

When someone sends you a keyword in an Instagram direct message, ManyChat replies with a fresh activation code. This use case writes in your name, without sending anything else: it needs a key with Students › Write (students:write) and an offer that includes writes. Create the key in the app, terms of use accepted. It also needs the ManyChat Pro plan, the only plan with the External Request action.

What this use case does

  1. In ManyChat: a "keyword" trigger on Instagram DMs, for example PROGRAM, or a "comment on a post" trigger. An External Request action sends a POST to the address of the n8n webhook, with the X-Webhook-Secret header and the body below. Its Response mapping stores $.code in the custom field fd_code, which you empty before the request: if it fails (wrong secret, timeout), ManyChat does not fill it. A message follows, only if fd_code is filled: "Here is your code:", the fd_code field inserted with the variable picker, then "Install Fit'Distance and enter it when you sign up."
  2. In n8n: the webhook checks the secret, then a POST /operations/students.create_open_code creates the code. It answers { "code": … } to ManyChat. A wrong secret gets a 401, and writes nothing.
{ "subscriber_id": "<Contact ID>", "first_name": "<First name>" }

Replace each value in angle brackets with the ManyChat field of the same name, inserted with the variable picker. Create the fd_code field first, as text. ManyChat expects a JSON answer within 10 seconds, from an https address.

curl -X POST https://api.fitdistance.io/api/partner/v1/operations/students.create_open_code \
  -H "Authorization: Bearer fd_live_xxxxxxxx" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: code-1234567890-2026-10-26" \
  -d '{}'

The code is in data.token (and in message): { "data": { "token": "AB2C", … }, "message": "…", "dry_run": false }. The Idempotency-Key is code-<subscriber>-<YYYY-MM-DD>: the same subscriber asking again the same day gets the same code, and the replay is refunded. See Writes and idempotency.

What the code opens

The code gives access to your coaching: whoever enters it at sign-up becomes your student, and anyone can write the keyword. Keep it for an offer you really want to hand out. To remove a student who got in by mistake, use the app.

What it costs

A code costs one credit, debited before the call. An argument the operation's schema refuses is refunded; a 401, a 403 or a 429 costs nothing; a replay is refunded. students.create_open_code has no preview: only test it with your own Instagram account, it creates a real code and sends nothing.

In n8n

  1. Choose Import from URL… and paste https://fitdistance.io/documentation/api/cas-pratiques/instagram-dm-code.n8n.json, or download the workflow and choose Import from File…. Pick the Fit'Distance API credential from Connect n8n in the HTTP Request node.
  2. In Secret matches?, replace change-this-secret with a long random text, the same as the X-Webhook-Secret header in ManyChat. Also replace the fitdistance-code path of the Webhook with a name only you know.
  3. Activate the workflow: ManyChat calls https://<your-n8n>/webhook/<path>, not the test address.
  4. Send the keyword from your account. ManyChat does not fill fd_code when you test the request in the editor: trigger the automation as a contact, or in preview.

Today keeps the subscriber id and the date. If ManyChat sends an empty or unresolved variable, it stops the workflow before writing: every subscriber would share one key. To limit the duration of the code, add contractEndAt to the body of Create the code, with a date that does not change during the day: otherwise the second call of the day gets a 409 IDEMPOTENCY_MISMATCH.

In Make

  1. Webhooks › Custom webhook: in the webhook's Advanced settings, choose Yes for Get request headers, then add a filter: the x-webhook-secret header equal to your secret, and subscriber_id not empty, like Today in n8n.
  2. HTTP › Make a request: POST on https://api.fitdistance.io/api/partner/v1/operations/students.create_open_code, Idempotency-Key = code-{{subscriber_id}}-{{formatDate(now; YYYY-MM-DD)}}, Body content type application/JSON, Body input method JSON string, body {}, Parse response set to Yes.
  3. Webhooks › Webhook Response: Status 200, Body { "code": "{{data.token}}" }, header Content-Type = application/json.

Reference: creating a code.

Next pageA form submission → a note on the student's fileEvery answer to a Tally form becomes a private note on the student's file, with n8n or Make.