Double opt-in
Setting up double opt-in is a process that allows you to verify the email address of a new subscriber.
Creating an unsubscribed contact
When you trigger an event for a contact, they will automatically be subscribed unless you pass subscribed: false
along with the event.
When you trigger the event, Plunk's API will return you a JSON object with the contact's ID. You can use this ID to send them a confirmation email with the transactional email API
await fetch('https://api.useplunk.com/v1/track', {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer API_KEY", // Put your API key here
},
body: JSON.stringify({
"event": "new-project",
"email": "hello@useplunk.com",
"subscribed": false,
}),
});
import requests
requests.post(
"https://api.useplunk.com/v1/track",
headers={
"Content-Type": "application/json",
"Authorization": "Bearer API_KEY" # Put your API key here
},
json={
"event": "new-project",
"email": "hello@useplunk.com",
"subscribed": False
},
)
curl --location --request POST 'https://api.useplunk.com/v1/track' \
--header 'Authorization: Bearer API_KEY' \
--header 'Content-Type: application/json' \
--data-raw '{"email": "hello@useplunk.com", "event": "new-project", "subscribed": false}'
```php
<?php
$client = new Client();
$request = new Request('POST', 'https://api.useplunk.com/v1/track', ['Authorization' => 'Bearer API_KEY', 'Content-Type' => 'application/json'], '{
"event": "new-project",
"email": "hello@useplunk.com",
"subscribed": false
}');
$res = $client->sendAsync($request)->wait();
require "uri"
require "json"
require "net/http"
url = URI("https://api.useplunk.com/v1/track")
https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = "Bearer API_KEY" # Put your API key here
request["Content-Type"] = "application/json"
request.body = JSON.dump({
"event": "new-project",
"email": "hello@useplunk.com",
"subscribed": false
})
response = https.request(request)
Confirming opt-in
With an action
You can leverage Plunk's action to confirm the opt-in. For this you will need to create an transactional template that contains a link to Plunk's hosted subscribe page or a custom-built page that will call the Plunk API to subscribe the contact.
Plunk's hosted pages can be found at the following URLs:
app.useplunk.com/subscribe/contactID
app.useplunk.com/unsubscribe/contactID
When creating a template, you can use the built-in Plunk variables in the editor to automatically fill in the contact's ID.

With a transactional email
Using the contact ID returned from the previous step, you can send a transactional email to the contact. This email will contain a link to the subscription page hosted by Plunk. All contacts have a subscribe and unsubscribe page that can be found at the following URLs:
app.useplunk.com/subscribe/contactID
app.useplunk.com/unsubscribe/contactID
Once the contact confirms their subscription by clicking the button on the page, they will be toggled to a subscribed contact.
await fetch('https://api.useplunk.com/v1/send', {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer SECRET_KEY", // Put your API key here
},
body: JSON.stringify({
"to": "hello@useplunk.com",
"subject": "Please confirm your email",
"body": "<h1>Confirm your email</h1><p>Click <a href='https://app.useplunk.com/subscribe/ID'>here</a> to confirm your email.</p>",
}),
});
import requests
requests.post(
"https://api.useplunk.com/v1/send",
headers={
"Content-Type": "application/json",
"Authorization": "Bearer SECRET_KEY" # Put your API key here
},
json={
"to": "hello@useplunk.com",
"subject": "Please confirm your email",
"body": "<h1>Confirm your email</h1><p>Click <a href='https://app.useplunk.com/subscribe/ID'>here</a> to confirm your email.</p>",
},
)
curl --location --request POST 'https://api.useplunk.com/v1/send' \\
--header 'Authorization: Bearer SECRET_KEY' \\
--header 'Content-Type: application/json' \\
--data-raw '{"to": "hello@useplunk.com", "subject": "Please confirm your email", "body": "<h1>Confirm your email</h1><p>Click <a href='https://app.useplunk.com/subscribe/ID'>here</a> to confirm your email.</p>"}'
<?php
$client = new Client();
$request = new Request('POST', 'https://api.useplunk.com/v1/send', ['Authorization' => 'Bearer SECRET_KEY', 'Content-Type' => 'application/json'], '{
"to": "hello@useplunk.com",
"subject": "Please confirm your email",
"body": "<h1>Confirm your email</h1><p>Click <a href='https://app.useplunk.com/subscribe/ID'>here</a> to confirm your email.</p>",
}');
$res = $client->sendAsync($request)->wait();
require "uri"
require "json"
require "net/http"
url = URI("https://api.useplunk.com/v1/send")
https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = "Bearer SECRET_KEY" # Put your API key here
request["Content-Type"] = "application/json"
request.body = JSON.dump({
"to": "hello@useplunk.com",
"subject": "Please confirm your email",
"body": "<h1>Confirm your email</h1><p>Click <a href='https://app.useplunk.com/subscribe/ID'>here</a> to confirm your email.</p>",
})
response = https.request(request)