Answers.Body: <p>I've found the answer.</p>
  
  <p>I was calling GroupContact > Create with parameter Status=Pending.  This worked to create the pending contact but as far as I can find there is no way to then trigger the double opt-in email.</p>
  
  <p>The solution is instead to call MailingEventSubscribe > Create, with parameters for email address and group id.  This adds the pending GroupContact and sends the double opt-in email.</p>
  
  <p>For my use case, I needed to create the contact at the same time, so I use separate API calls of Contact > Create, then MailingEventSubscribe > Create.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-16T11:34:26.180Z
Answers.LastActivityDate: 2018-05-16T11:34:26.180Z
Answers.UserDisplayName: Piggo
Answers.Body: <p>We’re using civicoop email api extension on 4.7 and that means it should work on 5.x as well. </p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-11T13:12:19.177Z
Answers.Text: Thanks, I've just installed it and it's working fine.
  
  I'm still having trouble though.  emailapi works to send an email using a template from **Mailings > Message Templates**, but the group confirmation email is not in this list.
Answers.UserDisplayName: Piggo
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-11T16:43:25.253Z
Answers.Text: You need to create your own Message Template
Answers.UserDisplayName: KarinG - Semper IT
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-07-13T12:26:56.037Z
Answers.Text: This is more of a comment than an answer to the question.
Answers.UserDisplayName: michaelmcandrew
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-15T10:17:50.973Z
Answers.Text: Thanks Karin.  I have tried that but I can't find a token that can be used for confirmation of group membership.  The closest I have found is {action.subscribeUrl.gid}, but this only gives a link to a page where a user can enter their email, and in fact the token does not work at all in an email sent using the emailapi.
Answers.UserDisplayName: Piggo
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-11T12:14:28.300Z
Answers.LastActivityDate: 2018-05-11T12:14:28.300Z
Answers.UserDisplayName: KarinG - Semper IT
Body: <p>I'm using the REST API to create contacts and add them to an existing mailing group.  I want to add them as <em>pending</em> and trigger the confirmation email but I can't find a way to do it via the API.</p>
  
  <p>The extension <a href="https://civicrm.org/extensions/e-mail-api" rel="nofollow noreferrer">org.civicoop.emailapi</a> seems like it does what I need but it only supports up to 4.6 and I'm running 5.0.2.</p>
  
  <p>Are there any other options?</p>
  
  <p><strong>edit</strong> - I've installed org.civicoop.emailapi and it's working under 5.0.2, but I can't make it send the group confirmation email as it's not a normal mailing template.</p>
  
  <p><strong>edit</strong> - If I create my own mailing template, I can't find a token that generates the confirmation link for a specific user and a specific group.  To be clear, I want to recreate the {subscribe.url} token from the <em>Subscription Confirmation Request</em> automated message.</p>
  
Tags: <contacts><api><email><groups><confirmation>
Title: How to send a confirmation email when adding a contact to group via API?
ThreadText: # How to send a confirmation email when adding a contact to group via API?
  
  (Asked by: username_0 on 2018-05-11)
  
  I'm using the REST API to create contacts and add them to an existing mailing group. I want to add them as *pending* and trigger the confirmation email but I can't find a way to do it via the API.
  
  The extension [org.civicoop.emailapi](https://civicrm.org/extensions/e-mail-api) seems like it does what I need but it only supports up to 4.6 and I'm running 5.0.2.
  
  Are there any other options?
  
  **edit** - I've installed org.civicoop.emailapi and it's working under 5.0.2, but I can't make it send the group confirmation email as it's not a normal mailing template.
  
  **edit** - If I create my own mailing template, I can't find a token that generates the confirmation link for a specific user and a specific group. To be clear, I want to recreate the {subscribe.url} token from the *Subscription Confirmation Request* automated message.
  
  **Tags:** contacts, api, email, groups, confirmation
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_0 on 2018-05-16. Score: 2 | Accepted answer
  
  I've found the answer.
  
  I was calling GroupContact > Create with parameter Status=Pending. This worked to create the pending contact but as far as I can find there is no way to then trigger the double opt-in email.
  
  The solution is instead to call MailingEventSubscribe > Create, with parameters for email address and group id. This adds the pending GroupContact and sends the double opt-in email.
  
  For my use case, I needed to create the contact at the same time, so I use separate API calls of Contact > Create, then MailingEventSubscribe > Create.
  
  
  ---
  
  ### Answer by username_1 on 2018-05-11. Score: 2
  
  We’re using civicoop email api extension on 4.7 and that means it should work on 5.x as well.
  
  > **Comments:**
  > **username_0**: Thanks, I've just installed it and it's working fine.  I'm still having trouble though.  emailapi works to send an email using a template from **Mailings > Message Templates**, but the group confirmation email is not in this list.  
  > **username_1**: You need to create your own Message Template  
  > **username_0**: Thanks Karin.  I have tried that but I can't find a token that can be used for confirmation of group membership.  The closest I have found is {action.subscribeUrl.gid}, but this only gives a link to a page where a user can enter their email, and in fact the token does not work at all in an email sent using the emailapi.  
  > **username_2**: This is more of a comment than an answer to the question.  
  
  ---
  
  