# Webhook, JSON problem

**URL:** <https://forums.losant.com/t/webhook-json-problem/4536>\
**Category:** Help\
**Tags:** workflow\
**Created:** [May 16, 2022, 11:46am UTC](https://forums.losant.com/t/webhook-json-problem/4536 "2022-05-16T11:46:53Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joe\_Ka](https://avatars.discourse-cdn.com/v4/letter/j/7993a0/32.png) [@Joe\_Ka](https://forums.losant.com/u/Joe_Ka)\
**Post date:** [May 16, 2022, 11:46am UTC](https://forums.losant.com/t/webhook-json-problem/4536/1 "2022-05-16T11:46:53Z")

</div>

I want to display the data of an IoT sensor on the Losant control panel. The motherboard communicates with the Hologram through a cellular connection. From there, it sends the data to Losant via a Webhook.  
The problem starts there because the device is already using a JSON template to identify and send data to the Hologram server. The data cannot be a newer JSON string, as it disrupts the original encoding on the Hologram server. Useful data can only be something like this:

Temp:27.34; Battery:3.6; Loc:47.45623, 19.67234

It contains data from several sensors that Loszant no longer interprets in this form because it is not JSON encoding.

Of course, I can put it in a suitable format in the Hologram message, but the data still looks like this:

{Temp:27.34; Battery:3.6; Loc:47.45623, 19.67234}

How can I set up the webhook on Losant so that it continues to transfer the data properly in JSON:

{“Temp”:27.34, “Battery”:3.6, “Loc”:“47.45623, 19.67234”}

Or how to convert the data on the device so that it is well understood by the Losant Webbhook and can be configured in the (device: status) template.

I can program the format and characters on the device side, but I can’t use a JSON (“something”) character.

Could someone help me?  
I am at a beginner level in Losant programming.

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![Brandon\_Cannaday](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/brandon_cannaday/32/14_2.png) [@Brandon\_Cannaday](https://forums.losant.com/u/Brandon_Cannaday)\
**Post date:** [May 16, 2022, 12:25pm UTC](https://forums.losant.com/t/webhook-json-problem/4536/2 "2022-05-16T12:25:45Z")

</div>

One option would be to have your device (or the Hologram platform, if possible) encode the JSON string as Base64. The Base64 string can then be added to the outer JSON object.

In Losant, you’d use the Base64 Decode Node followed by the JSON Decode Node to turn it into an object on the payload.

---

<div class="post-metadata">

**Author:** ![Joe\_Ka](https://avatars.discourse-cdn.com/v4/letter/j/7993a0/32.png) [@Joe\_Ka](https://forums.losant.com/u/Joe_Ka)\
**Post date:** [May 16, 2022, 1:09pm UTC](https://forums.losant.com/t/webhook-json-problem/4536/3 "2022-05-16T13:09:15Z")

</div>

Hi Brandon,

oh yeah, the screw in it is that the device already handles sending data in BASE64, so it translates everything into BASE64. I can’t even change this part from a program because it’s included in the base API. Then the entire BASE64 data set is converted back by Hologram so that the useful data is already displayed in decdata if I want. Or you can transmit in BASE64, but I can’t add useful data in BASE64 ☹

“data”: “eyJUZW0iOjI2LjcsICJCYXR0ZXJ5IjozLjY1LCAiTG9jIjoiNDcuNDUzNTYsIDE5LjM0NTIzNH0=”, “received”: “2022-05-16T12:28:20+00:00”, “record\_id”:

I just can’t write a character in the payload ("").  
I would have to send the useful data in some other form that Losant can also interpret and manage.  
I’ve been thinking about CSV, but I don’t know how to handle it.  
What would be the right string.  
I’m a little confused where to go.

Thk.  
Br.  
Joe

---

<div class="post-metadata">

**Author:** ![Brandon\_Cannaday](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/brandon_cannaday/32/14_2.png) [@Brandon\_Cannaday](https://forums.losant.com/u/Brandon_Cannaday)\
**Post date:** [May 16, 2022, 1:20pm UTC](https://forums.losant.com/t/webhook-json-problem/4536/4 "2022-05-16T13:20:38Z")

</div>

CSV would also work - there’s a CSV Decode Node. It doesn’t really matter how the data is reported, as long as you can get the values on the payload. The Device: State Node, which would ultimately be used to save the data to device attributes, can pull values from anywhere on the payload.

---

<div class="post-metadata">

**Author:** ![Joe\_Ka](https://avatars.discourse-cdn.com/v4/letter/j/7993a0/32.png) [@Joe\_Ka](https://forums.losant.com/u/Joe_Ka)\
**Post date:** [May 16, 2022, 1:40pm UTC](https://forums.losant.com/t/webhook-json-problem/4536/5 "2022-05-16T13:40:59Z")

</div>

Can you give me a simple example code for this?  
I would now test these 3 sensors.  
Currently I can handle an example JSON message:  
{“Tem”: 26.7, “Battery”: 3.67, “Loc”: “49.25567, 18.09893”}

What CSV data set should I send to the Webhook?  
How do I set the CSV node to receive it (Device: status)?

Could you help with this?

 ![Gmail, Hologram_3](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/1/1a2972df7b3959bb5405cab661819ec718190938.png)

---

<div class="post-metadata">

**Author:** ![Erin\_Thompson](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/erin_thompson/32/501_2.png) [@Erin\_Thompson](https://forums.losant.com/u/Erin_Thompson)\
**Post date:** [May 16, 2022, 2:13pm UTC](https://forums.losant.com/t/webhook-json-problem/4536/6 "2022-05-16T14:13:03Z")

</div>

What CSV data set should I send to the Webhook? That is really up to you and what you want to record as the device state data.

How do I set the CSV node to receive it (Device: status)?  
In order to accomplish this you would send the webhook a string of CSV data and then you would use the [CSV: Decode Node](https://docs.losant.com/workflows/logic/csv-decode/) to turn your data from CSV into JSON objects which can then be sent to the [Device: State Node](https://docs.losant.com/workflows/outputs/device-state/). The way you are using the device state node currently is by mapping the [individual fields](https://docs.losant.com/workflows/outputs/device-state/#defining-state-properties) on a payload to your device state fields, if you’re CSV has multiple device states consider using a payload path to pass in your device states. The catch with using payload path is that your attributes will need to be named correctly on the objects given.

---

<div class="post-metadata">

**Author:** ![Joe\_Ka](https://avatars.discourse-cdn.com/v4/letter/j/7993a0/32.png) [@Joe\_Ka](https://forums.losant.com/u/Joe_Ka)\
**Post date:** [May 16, 2022, 3:31pm UTC](https://forums.losant.com/t/webhook-json-problem/4536/7 "2022-05-16T15:31:14Z")

</div>

Dear Erin,

> [@Erin\_Thompson](#):
>
> What CSV data set should I send to the Webhook? That is really up to you and what you want to record as the device state data

yes that’s why i asked what order i should put the sensor data in place.

So:

“data”: {  
“body”: {  
“Battery”: 3.67  
“Loc”: “47.28519, 19.06179”,  
“Tem”: 26.7

If I send this in CSV, what would be appropriate?  
This is currently being sent by the device:

Tem: 26.7, Loc: 47.28519, 19.06179, Battery: 3.67

Can be varied:  
For example, Tem = 26.7, or Tem, 26.7; it would only be nice to know what is easiest to set up in Losant.

> [@Erin\_Thompson](#):
>
> In order to accomplish this you would send the webhook a string of CSV data and then you would use the [CSV: Decode Node](https://docs.losant.com/workflows/logic/csv-decode/) to turn your data from CSV into JSON objects which can then be sent to the [Device: State Node](https://docs.losant.com/workflows/outputs/device-state/).

Currently, if I send a non-JSON format to the Webhook, it will return an error.

Server sent HTTP status code 400 with body: {“statusCode”: 400, “error”: “Bad Request”, “message”: “Invalid request payload JSON format”}

So I asked how to set up the Webhook trigger to receive CSV.

> [@Erin\_Thompson](#):
>
> CSV has multiple device states consider using a payload path to pass in your device states. The catch with using payload path is that your attributes will need to be named correctly on the objects given.

Could you give an example of this (useful route) just how it works?  
It has multiple device states at once, which can be separated by (,) (;). I would just like an example setting so I have little idea how to proceed. 🙂

Thank you in advance for your help.

Br.

Joe

---

<div class="post-metadata">

**Author:** ![Erin\_Thompson](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/erin_thompson/32/501_2.png) [@Erin\_Thompson](https://forums.losant.com/u/Erin_Thompson)\
**Post date:** [May 16, 2022, 4:18pm UTC](https://forums.losant.com/t/webhook-json-problem/4536/8 "2022-05-16T16:18:54Z")

</div>

Dear Joe,

If you want to send a CSV, you can send it in many different formats and specify the configuration via the [CSV: Decode Node](https://docs.losant.com/workflows/logic/csv-decode/) like the record delimiter (by default is a newline character (\n)), delimiter, quote and escape. We try to keep most of our nodes allow different configurations to fit different users needs. The only requirement for a CSV is that the first line is the header line and the following lines are the records. I.E.

```auto
Tem,Loc,Battery
26.7,'47.28519,19.06179',3.67

```

So if I wanted to send this as a body on a webhook I would do something like the following…

 ![Screen Shot 2022-05-16 at 12.01.51 PM](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/c/ce58b8311366e96b7d355fc06505f1e41d37ef6d.png)

This is how I test webhook workflows, and you can set the body to a valid JSON object like

```auto
{
    "csv": "Tem,Loc,Battery\n26.7,'47.28519,19.06179',3.67"
}

```

If you want to want to send this data in the body then yes it must be in the valid JSON format. If you want to send this as a simple string you could put it on a query param, however you may end up reaching the query param length limit depending on the length of your CSV string.

After that I would set up a workflow like the following,

 ![Screen Shot 2022-05-16 at 12.10.07 PM](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/4/47ef47c2bac2edde7deb87c4ded034bb7edfa935.png)

 ![Screen Shot 2022-05-16 at 12.10.18 PM](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/5/57442de60cba4526d2305d9d252529b48592cb78.png)

I would use the webhook tester as seen above to actually trigger my workflow down here and view the payload path to make sure the data is being parsed correctly. You can use the [debug node](https://docs.losant.com/workflows/outputs/debug/) at any point to view the payload.

Let me know if you have any more questions,  
Erin

---

<div class="post-metadata">

**Author:** ![Joe\_Ka](https://avatars.discourse-cdn.com/v4/letter/j/7993a0/32.png) [@Joe\_Ka](https://forums.losant.com/u/Joe_Ka)\
**Post date:** [May 18, 2022, 3:05pm UTC](https://forums.losant.com/t/webhook-json-problem/4536/9 "2022-05-18T15:05:39Z")

</div>

Hi Erin,

thanks for the help, i was able to set the CSV codes. The example code also helped a lot.  
I had trouble with it because the Hologram was less supportive, but I ended up resolving it.

I have another question, maybe there is a solution at Losant.

GPS coordinates are sent by the device in one (DMM) format by default. (format: ddmm.mmmmmm N / S, dddmm.mmmmmm E / W)  
Losant handles the (DD) format for location data that can be displayed on the control panel (format: (-) dd.ddddd, (-) ddd.ddddd)  
Is it possible to convert location data from DMM to DD and send it to (device: status)?

thanks if you can help.

Br.  
Joe

---

<div class="post-metadata">

**Author:** ![Erin\_Thompson](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/erin_thompson/32/501_2.png) [@Erin\_Thompson](https://forums.losant.com/u/Erin_Thompson)\
**Post date:** [May 18, 2022, 3:30pm UTC](https://forums.losant.com/t/webhook-json-problem/4536/10 "2022-05-18T15:30:17Z")

</div>

Hi Joe,

You should try using our formatGps template helper that can be found in our [format helpers](https://docs.losant.com/workflows/accessing-payload-data/#format-helpers). You can use the [template tester](https://docs.losant.com/workflows/platform-template-tester/) on the workflow to play around with any of the format helpers you may need to use and you can utilize your debug messages or example payload from triggers.

Hope this helps get you a step closer to your solution,  
Erin

---

<div class="post-metadata">

**Author:** ![Joe\_Ka](https://avatars.discourse-cdn.com/v4/letter/j/7993a0/32.png) [@Joe\_Ka](https://forums.losant.com/u/Joe_Ka)\
**Post date:** [May 19, 2022, 7:42am UTC](https://forums.losant.com/t/webhook-json-problem/4536/11 "2022-05-19T07:42:44Z")

</div>

Hi Erin,

I looked at the formatGps format helper.  
It looks good although I may not recognize this particular format but I can try it.  
My question is, where can I use this helper?  
In Device: state, I use custom fields, such as  
for temperature {{stateData.0.Tem}}  
and {{stateData.0.Loc}} for location data  
No useful route is specified at the end, the values are displayed directly in the dashboard.  
I’d like a few more nodes for that later, but only if the data is already displayed correctly, at least in the control panel.

I also looked at the fact that formatGps returns the decimal value by default, so you don’t have to specify another format.  
It basically looks like this:  
{{formatGps gpsStr formatStr precision}}

Do you know a sample for this, where to put the template, and how to format it to use location data on {{stateData.0.Loc}} output?  
Where would you do it? Need a new node? 🙂

Thank you in advance for your help.

---

<div class="post-metadata">

**Author:** ![Erin\_Thompson](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/erin_thompson/32/501_2.png) [@Erin\_Thompson](https://forums.losant.com/u/Erin_Thompson)\
**Post date:** [May 19, 2022, 1:53pm UTC](https://forums.losant.com/t/webhook-json-problem/4536/12 "2022-05-19T13:53:53Z")

</div>

Hi Joe,

These handlebar format helpers can be used in any field that takes a template, so you should be able to use it directly in the device: state node if you are using individual fields or a json template to set the device state. If the device state is being saved properly are you sure you need to convert the data?

I would also suggest that you run through some of these [Losant University courses](https://docs.losant.com/university/overview/). It will go over a lot of these basic concepts and help you understand how each area of Losant works and then fits together as a whole.

Let me know if you have anymore questions.

Hope this helps,  
Erin

---

<div class="post-metadata">

**Author:** ![Joe\_Ka](https://avatars.discourse-cdn.com/v4/letter/j/7993a0/32.png) [@Joe\_Ka](https://forums.losant.com/u/Joe_Ka)\
**Post date:** [May 19, 2022, 2:42pm UTC](https://forums.losant.com/t/webhook-json-problem/4536/13 "2022-05-19T14:42:14Z")

</div>

Hi Erin,

ok i am trying to use it in the status node.  
I need the conversion because what I sent earlier is just test data, not device data.

Yes, I am constantly learning Losant. I try to adjust to it and come up with knowledge. 🙂  
Thanks for the help, they always take me forward.  
When I use a specific case that needs a lot more attention anyway, it arouses interest!

---

<div class="post-metadata">

**Author:** ![Joe\_Ka](https://avatars.discourse-cdn.com/v4/letter/j/7993a0/32.png) [@Joe\_Ka](https://forums.losant.com/u/Joe_Ka)\
**Post date:** [May 19, 2022, 4:05pm UTC](https://forums.losant.com/t/webhook-json-problem/4536/14 "2022-05-19T16:05:50Z")

</div>

Hi Erin,

Well, I didn’t make it.  
To be a little more specific:  
So the data coming in through the webhook goes through the CSV decoder.  
 ![Szeretné kérni az oldal lefordítását](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/e/e4aadac502632f9b65706ffc575234ab93d89974.png)

then device: state reads and displays it in the control panel.  
 ![Gmail, Hologram_4](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/1/1f882493e03cd20e7d7d562742289d3dbc113c19.png)

Where should I put the handlebars helper here? 🙂

Must be the default. (decimal value, 6 decimal places)

---

<div class="post-metadata">

**Author:** ![Erin\_Thompson](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/erin_thompson/32/501_2.png) [@Erin\_Thompson](https://forums.losant.com/u/Erin_Thompson)\
**Post date:** [May 19, 2022, 5:02pm UTC](https://forums.losant.com/t/webhook-json-problem/4536/15 "2022-05-19T17:02:42Z")

</div>

HI Joe,

Based on your screenshots you should be accessing your Loc attribute like this `{{ stateData.[0].Loc }}` without the brackets around the index you are trying to access this wont work. In order to use the handle bars helper you would simply write `{{ formatGps stateData.[0].Loc }}`. Any of these handlebars helpers can be used in fields where templates are allowed.

However, looking at what you have for your given data, the format GPS data will not help as your data is no longer a valid [GPS format](https://docs.losant.com/devices/attributes/#gps). You will probably have to use either a combination of the [math node](https://docs.losant.com/workflows/logic/math/), the [mutate node](https://docs.losant.com/workflows/logic/mutate/) and the [string nodes](https://docs.losant.com/workflows/logic/string/) to transform the latitude and longitude into a decimal format. I found the conversion example online from this format into decimal and built a small workflow to show you how this can be done. And you should be able to apply the same logic to your workflow.

[format-dddmmmmmm-to-decimal-gps-develop.flow](https://forums.losant.com/uploads/short-url/4j6v9CxE0RWGKxSf9Ollbep7uUN.flow) (5.2 KB)

Hope this helps,  
Erin

---

<div class="post-metadata">

**Author:** ![Joe\_Ka](https://avatars.discourse-cdn.com/v4/letter/j/7993a0/32.png) [@Joe\_Ka](https://forums.losant.com/u/Joe_Ka)\
**Post date:** [May 19, 2022, 5:21pm UTC](https://forums.losant.com/t/webhook-json-problem/4536/16 "2022-05-19T17:21:02Z")

</div>

Hi Erin,

> [@Erin\_Thompson](#):
>
> Based on your screenshots you should be accessing your Loc attribute like this `{{ stateData.[0].Loc }}` without the brackets around the index you are trying to access this wont work. In order to use the handle bars helper you would simply write `{{ formatGps stateData.[0].Loc }}` . Any of these handlebars helpers can be used in fields where templates are allowed

oh yeah i tried this solution too, albeit a little differently. Did not work. ☹

(0) works because it is a path  
not a key, but I’ll fix it.

yes i was also thinking of needing a node here for this conversion.  
I’m also trying to convert the DD format from a program on the device side. One just works. 🙂

> [@Erin\_Thompson](#):
>
> Ha azonban megnézzük, mi áll rendelkezésére a megadott adatokhoz, akkor a GPS-adatok formátuma nem segít, mivel az adatok már nem érvényes [GPS-formátumok](https://docs.losant.com/devices/attributes/#gps) . [Valószínűleg a matematikai csomópont](https://docs.losant.com/workflows/logic/math/) , a [mutációs csomópont](https://docs.losant.com/workflows/logic/mutate/) és a [karakterlánc csomópontok](https://docs.losant.com/workflows/logic/string/) kombinációját kell használnia a szélességi és hosszúsági fok decimális formátummá alakításához. Megtaláltam az interneten az ebből a formátumból decimálissá konvertáló példát, és létrehoztam egy kis munkafolyamatot, amely megmutatja, hogyan lehet ezt megtenni. És képesnek kell lennie arra, hogy ugyanazt a logikát alkalmazza a munkafolyamatára.

thank you for your help, i will review the document and then indicate what has been achieved.

Br.  
Joe

---

<div class="post-metadata">

**Author:** ![Joe\_Ka](https://avatars.discourse-cdn.com/v4/letter/j/7993a0/32.png) [@Joe\_Ka](https://forums.losant.com/u/Joe_Ka)\
**Post date:** [May 19, 2022, 5:38pm UTC](https://forums.losant.com/t/webhook-json-problem/4536/17 "2022-05-19T17:38:30Z")

</div>

there was a little difficulty, we managed to import 🙂

---

<div class="post-metadata">

**Author:** ![Dylan\_Schuster](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/dylan_schuster/32/2850_2.png) [@Dylan\_Schuster](https://forums.losant.com/u/Dylan_Schuster)\
**Post date:** [May 19, 2022, 5:50pm UTC](https://forums.losant.com/t/webhook-json-problem/4536/18 "2022-05-19T17:50:10Z")

</div>

You’re trying to import that file as an Edge Workflow, but it is actually an Application Workflow, hence your error. Instead, try importing it into the “Application Workflows” list at the top of the page.

---

<div class="post-metadata">

**Author:** ![Joe\_Ka](https://avatars.discourse-cdn.com/v4/letter/j/7993a0/32.png) [@Joe\_Ka](https://forums.losant.com/u/Joe_Ka)\
**Post date:** [May 19, 2022, 5:51pm UTC](https://forums.losant.com/t/webhook-json-problem/4536/19 "2022-05-19T17:51:08Z")

</div>

there was a little difficulty, we managed to import 🙂

---

<div class="post-metadata">

**Author:** ![Joe\_Ka](https://avatars.discourse-cdn.com/v4/letter/j/7993a0/32.png) [@Joe\_Ka](https://forums.losant.com/u/Joe_Ka)\
**Post date:** [May 20, 2022, 9:20am UTC](https://forums.losant.com/t/webhook-json-problem/4536/20 "2022-05-20T09:20:16Z")

</div>

Hi Erin,

it looks like the sample workflow works for me too, but if I paste it into my own workflow I don’t have the newLocDecimal data anymore.

 ![Szeretné kérni az oldal lefordítását](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/0/00bb5a2eb52d91fc59217c3c65200230cf30f5c9.png)

Sensor data is displayed on the main path, but the converted data is missing from the stateData keys. (data.stateData. [0] .newLocDecimal)

 ![p3](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/5/516140a02a7829a04fe949b745aa6aa249bccbec.png)

What is obvious is that there is no conversion, the value is empty or 0 everywhere.  
It seems to me that the string does not pick up the Loc data from the csv, even though it is in (stateData. [0] .Loc).

I did something wrong, even though the process is copied 🙂  
do you have any idea what’s wrong?

Br.  
Joe

[Next page](https://forums.losant.com/t/webhook-json-problem/4536.md?page=2)
