Webhooks - Custom Webhook

What was problem/solution so others may learn?

It’s not mandatory - the default is to use the base path for any message.

And my WebHooks are running beautifully too!

So you don’t enable anything? The text on the page suggests (to me) you need to enable a certain message type to receive it. It also allows specifying a custom path but that is optional. Might well be the wording is confusing me…

Shoot**, turns out I’ve got some with them all turned on and some with them all turned off.

My v3 config is work in progress so it’s not easy to quickly check - will do that later on this evening.

**Originally other words starting with B were here …

My V3 webhook is working, in that it triggers the code in my endpoint to log a visit, but it seems to arrive without any payload data. I’ve tried both specifying the message type and letting it send all message types. It is configured to send in JSON format which I attempt to recover using PHP like this:

header(‘Content-Type: application/json’);
$json = file_get_contents(‘php://input’);

But $json is empty.

It worked OK with V2 HTML integrations!

I don’t know what the effect of setting the header is at that stage, as it’s an outgoing response element.

The input is raw text, this works for me:

$data = file_get_contents("php://input");

// Save a raw copy of the message in a debug directory
// this will fill up quickly so don't leave it turned on
//$pathNFile = "debug/".date('YmdHis')."-".uniqid().".txt"; 
//file_put_contents($pathNFile, $data);

$json = json_decode($data, true);


Thanks for your help. I already do exactly as you suggest but even removing the header setting has no effect. Do you think that the problem could be related to my devices and applications being on V3 but the traffic is going via my TTN Indoor hub which is still on V2 because I have been unable to register it on V3?

Absolutely nothing to do with it at all.

If the traffic is appearing on the Application Live Data view it should then be forwarded.

You could turn on the save to file on the code snippet above so you can see data arriving (as files on the server).

What happens if you access your WebHook in your browser?

Hi Guys,
ME Too. Data arriving from devices on V2 to my end point URL no problem,

Devices on V3 with Webhook, The device is sending data to the V3 server and i can see the data on the V3 server, It is triggering the uplink and my end point URL is receiving the connection, but no body data i.e no json.

My apologies, I see that my WebHooks haven’t picked up any data since 10:18 today.

As per Heisenberg’s Uncertainty Principle, having poked at a few settings and copied them over on to another application, data is now appearing.

I’ll alert Head Office that there may be an issue.

Problem solved! It was nothing to do with TTN but I’ll detail the fix for anyone else who may have this problem.

The domain where my endpoint lives can either be found at https://mydomain.com or https://www.mydomain.com. Using the former involves a hidden redirection to the latter. In the process of redirection the payload is shed and the web hook arrives at its destination empty. Adding the full url to my webhooks solved the problem and I am now swimming in data.

I used the following code to test the endpoint:

// Not Heisenberg compliant
$url = '{your endpoint url}';
$ch = curl_init($url);
$data = array(
    'temperature' => '27.693',
    'humidity' => '40.773'
$payload = json_encode(array("user" => $data));

curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);

curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$result = curl_exec($ch);




(Sorry I tried to put cr/lfs in the code - but simple things baffle me.)


Thanks for sharing the solution… just the kind of apparently minor thing that can lead to a big snafu for many…

Hi Guys,
I am still rather confused here.
I am still not sure as to the setting for the http integration. they seem pretty basic as on v2.
my devices still on v2 are sending data to my end point no problem. the devices i have change to v3 are sending data to the v3 server, visible in the live data, which says its sending the data by my url, but i am not receiving any body data i,e the json data. So i must have something wrong with my v3 settings if you are saying it does work. Again if i set the device back to v2 i get my data as expected.
so what am i missing.

It may be a bugette in the v3 stack - I went back in to my v3 WebHooks, ensured all the check boxes were checked and clicked Save. It wasn’t very scientific but it suddenly resulted in incoming payloads. Worth a try. Let us know how you get on and I can try & setup some testing if no joy.

Hi Nick, I have made a slight modification to the debug code that you posted, to provide a prettier output and a useful crib sheet for further coding.

$json = file_get_contents("php://input");
$data = json_decode($json, true);
ob_start(); //Start buffering
print_r($data); //print the result
$output = ob_get_contents(); //get the result from buffer
ob_end_clean(); //close buffer

// Save a raw copy of the message in a debug directory
// this will fill up quickly so don't leave it turned on
// Save a raw copy of the message in a debug directory
// this will fill up quickly so don't leave it turned on
$pathNFile = "debug/".date('Y-m-d H:i:s') .".txt"; 
file_put_contents($pathNFile, $output);
fwrite($fp,date('Y-m-d H:i:s'));
1 Like

Nice one!

For those coming along at a later date, this will return a response to a browser or any HTTP client type utility or command line curl request as @dhmitchell provided above.

It will not provide any benefit for deployment to be accessed by a WebHook as you never get to see the response. The stack doesn’t and can’t really do anything with a response.

Hi there,

OK ticked all my boxes in the enabled messages section, as yet no data is arriving.

but have noticed i have NO ‘downlink API key’ set i.e box is just blank.
On V2 i have it set to just default, could this have an effect?

Thanks for the help.

Arriving where? Does the ‘where’ have logs you can see? Is there activity for the application in the console?

You only need a downlink API key if you want to trigger downlinks using a link embedded in the message.


Right, so the Download API key does not need anything in it.

OK - I have a single application - configured on the v2 server running perfectly and has been for last 18 months. Using the http to send the device data to my server.

having ‘moved’ a number of the devices to the new v3 server, we can see the data arriving on the v3 server via the live data.

my server has logs and i can see data coming in from the v2 server now problem, i can also see the connection arriving from the v3 server but the body empty. i.e no JSON data.

Now i am sure it is probably a configuration issue, missing header or something, but the setting look the same to me on v3 as on v2 and if i move the device back to v2, it all works fine.

There was a period last week when WebHooks weren’t working. But I can see incoming data on two different web hosts.

As you can put in as many as you want, can you try the snippet above: Webhooks - Custom Webhook - #9 by descartes