Automatic Discourse Invite JSON Problem

Hey n8n folks,

i am switching from make.com to N8N in the community version on my own hetzner server.

I build an automatic Account Creation incl. invite for new users Workflow.

Workflow Explanation:

  • New Ghost Member
  • Filter: Paid or free Member
  • Paid member: Invite to discourse

This is my working JSON:

{
  "email": "{{ $json.body.member.current.email }}",
  "name": "{{ $json.body.member.current.name }}",
  "username": "ToolGuide{{ Math.floor(10000 + Math.random() * 90000) }}",
  "password": "{{ $json.body.member.current.uuid }}",
  "active": "false",
  "approved": "true"
}

On Username you see that i take: ToolGuide with a Random Number to create usernames.

Conclusion

The new member can change it later. I dont like it much, it was a workaround to start.

New Code Problems

Normally i would like to use the first characters on en email ex.

Therefore is this slightly different code:

{
  "email": "{{ $json.body.member.current.email }}",
  "name": "{{ $substring($replace($replace($substring($json.body.member.current.email, 0, $indexOf($json.body.member.current.email, '@')), '+', '_'), '-', '_'), 0, 20) }}",
  "username": "{{ $substring($replace($replace($substring($json.body.member.current.email, 0, $indexOf($json.body.member.current.email, '@')), '+', '_'), '-', '_'), 0, 20) }}",
  "password": "{{ $json.body.member.current.uuid }}",
  "active": "true",
  "approved": "true"
}

Question

How can i tell the N8N System that $json.body.member.current.email is a dynamic vairbale without the {{ }} at the end ?

thx for assist

You’re using the variable correctly, but you need to remove the $ sign from the substring and replace functions (they’re regular Javascript functions).

1 Like

I changed it but i get still the Undefined error ?

thxj for assist!

I recommend starting with the inner expression, ensure it returns the expected value and then adding more layers. As it is right now, it’s kinda hard to read :slight_smile:

Another approach is to add some Edit Fields nodes to add the intermediary values. Remember: unlike Make.com, we don’t charge per node execution, only per workflow execution :slight_smile: So you can expand your workflow a bit for readability.

1 Like