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
- In ManyChat: a "keyword" trigger on Instagram DMs, for example
PROGRAM, or a "comment on a post" trigger. An External Request action sends aPOSTto the address of the n8n webhook, with theX-Webhook-Secretheader and the body below. Its Response mapping stores$.codein the custom fieldfd_code, which you empty before the request: if it fails (wrong secret, timeout), ManyChat does not fill it. A message follows, only iffd_codeis filled: "Here is your code:", thefd_codefield inserted with the variable picker, then "Install Fit'Distance and enter it when you sign up." - In n8n: the webhook checks the secret, then a
POST /operations/students.create_open_codecreates 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
- 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 theFit'Distance APIcredential from Connect n8n in the HTTP Request node. - In Secret matches?, replace
change-this-secretwith a long random text, the same as theX-Webhook-Secretheader in ManyChat. Also replace thefitdistance-codepath of the Webhook with a name only you know. - Activate the workflow: ManyChat calls
https://<your-n8n>/webhook/<path>, not the test address. - Send the keyword from your account. ManyChat does not fill
fd_codewhen 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
- Webhooks › Custom webhook: in the webhook's Advanced settings, choose
Yesfor Get request headers, then add a filter: thex-webhook-secretheader equal to your secret, andsubscriber_idnot empty, like Today in n8n. - HTTP › Make a request:
POSTonhttps://api.fitdistance.io/api/partner/v1/operations/students.create_open_code,Idempotency-Key=code-{{subscriber_id}}-{{formatDate(now; YYYY-MM-DD)}}, Body content typeapplication/JSON, Body input methodJSON string, body{}, Parse response set toYes. - Webhooks › Webhook Response: Status
200, Body{ "code": "{{data.token}}" }, headerContent-Type=application/json.
Reference: creating a code.