# HTTP Integration - Custom Body

**URL:** <https://www.thethingsnetwork.org/forum/t/http-integration-custom-body/23465>\
**Category:** Application Development\
**Created:** [March 3, 2019, 10:54pm UTC](https://www.thethingsnetwork.org/forum/t/http-integration-custom-body/23465 "2019-03-03T22:54:30Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![DCH\_Project](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/dch_project/32/40350_2.png) [@DCH\_Project](https://www.thethingsnetwork.org/forum/u/DCH_Project)\
**Post date:** [March 3, 2019, 10:54pm UTC](https://www.thethingsnetwork.org/forum/t/http-integration-custom-body/23465/1 "2019-03-03T22:54:30Z")

</div>

Hi Everyone,

I have a Web API for an IoT Platform that I’d like to push data to using the TTN HTTP Integration

I can use postman to push data - successfully

I am stuck for some example HTTP integrations to see how things are done…

**Issue 1:** exact format for multiple header params (does it use a ‘;’ seperator or comman ? or something else JSON?

**Issue 2:**  
The Web API I must use has a very specific custom JSON format and wont accept the TTN JSON as it stands.

I have a LoRaWAN device that monitors Temperature / Humidity but the Web API requires a seperate POST for temperature and second POST for humidity. So I will need two HTTP integrations attached to the device.

I haven’t been able to find an example anywhere on how I would separate out the temperature from the TTN JSON payload in order to add to my HTTP Body

I have my **Postman** setup below:

**URL:** [https://xxx.io/api/sensor/v2/observations](https://xxx.io/api/sensor/v2/observations)  
**Params:** streamid=xxx\_test\_ttn\_lansitec-temp  
**Authorizations:** Basic Auth [username] [password]  
**Headers:** Content-Type = application/json  
Accept = application/json  
**Body:**  
{  
“results” : [  
{  
“t” : “2016-11-12T00:00:00.000Z”,  
“v” : {  
“v” : 1.0  
}  
}  
]  
}

What I can’t work out is how to substitute t and v into the HTTP Body:

- Time as t
- Temperature Value as v

PS: I noticed the documentation and video for HTTP Integration don’t reflect the current page which now has separated out the authorization, custom header name, custom header value. I don’t see an option for custom body. I can imagine at some point there would be a need to add a javascript to convert payload\_fields =\> custom http body -

Should I modify my decoder to be like the HTTP body I need?  
As currently send data to another integration that uses all the JSON data.

Your Thoughts?

PS: Apologies for miss categorizing i couldn’t find a category for integration

PS requestb.in isn’t working for me but [https://requestbin.fullcontact.com/](https://requestbin.fullcontact.com/) does work (unsure of firewall related)

---

<div class="post-metadata">

**Author:** ![UdLoRa](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/udlora/32/45330_2.png) [@UdLoRa](https://www.thethingsnetwork.org/forum/u/UdLoRa)\
**Post date:** [March 4, 2019, 7:00am UTC](https://www.thethingsnetwork.org/forum/t/http-integration-custom-body/23465/2 "2019-03-04T07:00:55Z")

</div>

I did not fully understood the post, however I do not think there is a way to transform a single packet to two different posts - its a strange need.  
You may either program a “splitter” on a web server, that receives one POST from TTN and sends two POST to your platform, or program your device in order to send packets that alternate temperature and humidity, with waste of airtime (or also change platform to a more flexible one 😉 ).

---

<div class="post-metadata">

**Author:** ![kersing](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/kersing/32/44777_2.png) [@kersing](https://www.thethingsnetwork.org/forum/u/kersing)\
**Post date:** [March 4, 2019, 11:06pm UTC](https://www.thethingsnetwork.org/forum/t/http-integration-custom-body/23465/4 "2019-03-04T23:06:25Z")

</div>

You will need to use an intermediate system that splits the data and posts it. The payload decoder does not provide the option to perform two separate posts.  
I would look into using either node or node-red with an mqtt subscription to get the data and to perform the post data to the IoT platform.

---

<div class="post-metadata">

**Author:** ![UdLoRa](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/udlora/32/45330_2.png) [@UdLoRa](https://www.thethingsnetwork.org/forum/u/UdLoRa)\
**Post date:** [March 5, 2019, 8:51am UTC](https://www.thethingsnetwork.org/forum/t/http-integration-custom-body/23465/5 "2019-03-05T08:51:53Z")

</div>

> [@DCH\_Project](#):
>
> It dos not have an API that can split in this way.

What me and @kersing suggested is that **you** create a splitter in some place. In addition to the method proposed by @kersing, you can use http integration towards a simple script in a language of your choice on some hosting, that receives the JSON, iterates through the payload\_fields property, and for each variable you post towards the IoT platform (using cURL like libraries). Maybe 20 lines of code.

---

<div class="post-metadata">

**Author:** ![arjanvanb](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/arjanvanb/32/46626_2.png) [@arjanvanb](https://www.thethingsnetwork.org/forum/u/arjanvanb)\
**Post date:** [March 5, 2019, 9:01am UTC](https://www.thethingsnetwork.org/forum/t/http-integration-custom-body/23465/6 "2019-03-05T09:01:31Z")

</div>

…and if you don’t want some hosting to be running _continuously_, see also [HTTP integration with Azure Functions (testing)](https://www.thethingsnetwork.org/forum/t/http-integration-with-azure-functions-testing/10811) and [TTN to Azure Functions - Downlink and Uplink](https://www.thethingsnetwork.org/forum/t/ttn-to-azure-functions-downlink-and-uplink/11184).

---

<div class="post-metadata">

**Author:** ![mrpackethead](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/mrpackethead/32/20484_2.png) [@mrpackethead](https://www.thethingsnetwork.org/forum/u/mrpackethead)\
**Post date:** [March 5, 2019, 10:29am UTC](https://www.thethingsnetwork.org/forum/t/http-integration-custom-body/23465/7 "2019-03-05T10:29:20Z")

</div>

> [@arjanvanb](#):
>
> …and if you don’t want some hosting to be running _continuously_ , see also [HTTP integration with Azure Functions (testing)](https://www.thethingsnetwork.org/forum/t/http-integration-with-azure-functions-testing/10811) and [TTN to Azure Functions - Downlink and Uplink](https://www.thethingsnetwork.org/forum/t/ttn-to-azure-functions-downlink-and-uplink/11184).

or if you like an amazon flavour, you could use some Amazon Lambdas

---

<div class="post-metadata">

**Author:** ![UdLoRa](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/udlora/32/45330_2.png) [@UdLoRa](https://www.thethingsnetwork.org/forum/u/UdLoRa)\
**Post date:** [March 6, 2019, 5:47am UTC](https://www.thethingsnetwork.org/forum/t/http-integration-custom-body/23465/9 "2019-03-06T05:47:49Z")

</div>

This could be a way to do it (check the XMLHttpRequest class in Javascript), but I do not expect all libraries being available for a decoder function. Regarding elegance, side effects in functions are not particularly elegant 🙂  
If you already have programmed a splitter, it’s one step more for data, but at the end there shouldn’t be much traffic.

---

<div class="post-metadata">

**Author:** ![arjanvanb](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/arjanvanb/32/46626_2.png) [@arjanvanb](https://www.thethingsnetwork.org/forum/u/arjanvanb)\
**Post date:** [March 6, 2019, 8:18am UTC](https://www.thethingsnetwork.org/forum/t/http-integration-custom-body/23465/10 "2019-03-06T08:18:40Z")

</div>

Like already noted:

> [@kersing](#):
>
> The payload decoder does not provide the option to perform two separate posts.

@kersing is right: it’s just bare JavaScript ([ECMAScript5 to be precise](https://github.com/robertkrimen/otto)). It [does not add anything to support HTTP](https://github.com/TheThingsNetwork/ttn/blob/v2.10.0/core/handler/functions/functions.go) (even more: it does not even include any library to make parsing the number array `bytes` easier).

(Also, it can run for [at most 100 ms](https://github.com/TheThingsNetwork/ttn/blob/v2.10.0/core/handler/convert_fields_custom.go#L32-L33), mainly to limit resources, but as an application might want to respond with a downlink processing should be fast too.)

---

<div class="post-metadata">

**Author:** ![system](https://www.thethingsnetwork.org/forum/uploads/default/original/3X/6/2/6250ea44fd2b0d6259489e1a92748df681e1f970.png) [@system](https://www.thethingsnetwork.org/forum/u/system)\
**Post date:** [May 9, 2019, 10:33pm UTC](https://www.thethingsnetwork.org/forum/t/http-integration-custom-body/23465/12 "2019-05-09T22:33:27Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
