Up-to-date Particle Webhooks Email tutorial

I’ve been trying to follow this tutorial, but it seems out of date.

The current webhooks interface has mandatory fields for URL and HTTP basic authorization, so the JSON code in the tutorial has duplicate fields. I’ve tried deleting the duplicates from the JSON but that didn’t work either.

It’s strange that the integration page has some fields defined in the form, while others need to be in the JSON code. Being new to this kind of thing it’s hard to guess how the new integration form works. There appears to be no documentation or working tutorials available?

Is there anyone who knows how to send an email with the current webhooks creation page?

Here’s my JSON code…


          
{
  "event": "G",
  "url": "https://api.mailgun.net/v3/sandboxf3xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.mailgun.org/messages",
  "requestType": "POST",
  "mydevices": true,
  "auth": {
    "username": "api",
    "password": "xxxxxxxxxxxxxxxxxxxxxxx-xxxxxxxx-xxxxxxxx"
  },
  "noDefaults": true,
  "form": {
    "to": "thresholdengineering@comcast.net",
    "from": "ANY_NAME <ANY_EMAIL_ADDRESS@sandboxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.mailgun.org>",
    "subject": "ANY_SUBJECT",
    "text": "ANY_BODY"
  }
}

        
1 Like

I should have mentioned I have tested my mailgun account with their C# example code and that works just fine

Ok, I’ve finally succeded with sending an email from the webhooks integration

!

2 Likes

Thanks for the feedback, @thresholdengineering. I’ll throw this on the issues list for our docs and request that an engineer audit and update the example if necessary.

Thanks for helping to make us aware!

Thanks for posting this. Why does everyone refer to this as a JSON setup when the screen shot (and the only working examples I’ve seen) use Web Form??

thresholdengineering,

I am having trouble getting webhook to work with mailgun, are you still using particle/mailgun?

Each time I test I get an error 400 or 401. I am wondering if I need to do anything else at the mailgun end than had been done in the older posts here.

Thanks
Paul

I have managed to find my way through this and have mailgun integration working (the Web Form was the key).

I will put together what I did so the info is there for anyone as confused as i was to use.

I can also get the webform version to work but cannot get a JSON version to work. Any one know of a way to send a parsable string to a webhook via webform to mailgun? The below was taken from the only partial example I can find. It says to use double brackets to get the sub parts of the PARTICLE_EVENT_VALUE broken out. I have tried 2 and 3 brackets {{subject}} and {{text}}. Mail gun is complaining there is no text field

Output from particle cloud:

// Publish an event to the Particle Cloud, which triggers your Mailgun webhookvoid sendMailgunEmail(String subject, String body) {
// Use a string to concatenate the subject and body for the publish event.
// The webhook was configured to extract 'subject' and 'data' from this.String 

eventData = "subject=" + subject + "&data=" + body;
// The first argument is the event name defined in your webhook.
// The second argument is the payload (our combined subject and body).
// PRIVATE ensures the event is not public.

Particle.publish("sendEmail", eventData, PRIVATE);

}

Event

The source event that triggered the webhook

{
  "name": "sendEmail",
  "data": "subject=\"TestP1\"$data=\"this is data\"",
  "ttl": 60,
  "published_at": "2025-09-19T13:40:11.617Z",
  "coreid": "0a10aced202194944a05a22c"
}	    

Request

The HTTP request sent to the webhook url

POST /v3/sandboxxxxxxxxxxxxxxxxxxxxxbdd12.mailgun.org/messages HTTP/1.1
User-Agent: ParticleBot/1.1 (https://docs.particle.io/webhooks)
host: api.mailgun.net
content-type: application/x-www-form-urlencoded
authorization: Basic YXBpOmZkN2M2NmFmOTE5ZjI2NDkyMmI0YjMxY2I3NjQxNTZmLTNjMTM0MDI5LTg3NzZkZDAw
content-length: 63
Connection: keep-alive	      

Response

The HTTP response received from the webhook url

HTTP/1.1 400 Bad Request
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: *
Account-Id: 548e13xxxxxxxxxxxxx8819
Cache-Control: no-store
Content-Length: 97
Content-Type: application/json; charset=utf-8
Date: Fri, 19 Sep 2025 13:41:11 GMT
Strict-Transport-Security: max-age=63072000; includeSubDomains
X-Mailgun-Key-Id: 3c134029-8776dd00
X-Server: influx
X-Xss-Protection: 1; mode=block

{"message":"Need at least one of 'text', 'html', 'amp-html' or 'template' parameters specified"}	

Replace subject with “This is the subject” and text with {{{PARTICLE_EVENT_VALUE}}} and it work, the text is the event value. I want to pass both subject and body.

Any ideas?

In order for things like {{{subject}}} and {{{body}}} to work, the event data must be JSON formatted.

This is not the best way to format JSON, but is worth a try:

eventData = "{\"subject\":\"" + subject + "\",\"body:\"" + body + "\"}";

Bettery ways to format the JSON can be found in the JSON reference.

The rub on that is JSON does not seem to work, if you look up in the post and back to the post this references…I will give a bit more time and try your suggestions.