HTTP Post to Webhook

Trying to send data from a web server to losant based on this info:

In order for you to receive data from the device you will have to provide us with a URL to post the
data to. The data can be posted in multiple formats (CSV, JSON and XML). JSON is the
preferred format for its brevity, but what you choose depends on what you are most familiar with.

Posts can be made over regular and SSL connections and we can post data using basic http
authentication.

The server owner has asked for a domain name and port to send HTTP posts in json format.

So i have provided them with a webhook URL and suggested using port 443…

So far this isn’t working, any help would be much appreciated.

Hi, I’m a little confused as to your use case; can you elaborate on what you’re trying to do with the Losant platform? That would help point you in the right direction.

i.e. From where did you get the paragraph you quoted? Are you trying to fire a workflow by sending a request to a webhook? Are you trying to interact with your devices using our REST API?

Please let me know. Thanks.

Use Case - Gps tracking of assets, with losant want to collate the data and provide dashboards for visualising each of the assets location.

For a start I’m just trying to get the data into losant. Currently i have created a workflow that fires from a webhook.

The tracking devices connect to a 3rd party online server via TCP/IP data connection.
Communications with the server is done using TCP Messages. Data connectors can be created in the 3rd party server that convert the TCP messages to JSON and then it does an http post to a nominated URL and port.

Some further info here: https://support.digitalmatter.com/support/solutions/articles/16000046384-choosing-an-integration-strategy

So if I understand correctly, you’ve already got the data generated by your devices on a server, and you just want to send the data from that server over to Losant, where it can be acted on using the workflow engine and/or visualized using our dashboards.

You may have done some of these steps already, but first you’ll need to create an application and then create a device within it. You’ll need to add an attribute for each data point you’d like to track; you mentioned GPS in your question, so you’ll at least need an attribute of the gps type.

At this point, I would abandon the webhook / workflow strategy and would instead use the Losant REST API.

  1. In the Losant interface, create an API token, which you will need to authenticate your request. You can either grant the token all permissions, or if you wish to set custom permissions, at least grant the token “Device -> Send State” permission.
  2. From your server, make a POST request to the “Device -> Send State” endpoint. The URL (with parameters) and request body format are available at the documentation link.

There is also an example curl request in the documentation, which shows you how to use the combination of your application ID, device ID, API token and state data to form your request.

Please let me know if this resolves your issue!

Thanks Dylan, the server is third party as such the data connector / Json cannot be individually structured to meet the losant schema for the different API calls. ( As far as I’m aware)

  • The POST call is used to send data from multiple devices within the third party server as such my intention was to first process it through a workflow and then write device state to individual devices with corresponding serial number tags.

  • The third party has asked for a domain name and port to send the data to.

  • Can you suggest the best place to make a POST request from this server. I have this additional information from the third party server:

Posts can be made over regular and SSL connections and we can post data using basic http
authentication. Additionally the following dynamic fields can be included in the URL of the post:
• Serial Number [SERIAL]
• IMEI [IMEI]
• ICCID [ICCID]
e.g. http://www.thirdparty.com/records/save/100199
or http://www.thirdparty.com/SaveRecords?Serial=[SERIAL]
Note: When responding to the HTTP post a 200 OK response will cause the posted data to be
deleted from the tracking device. Any other response will fail the data commit and cause the device
to re-post the data.

An example of JSON data that will be sent here:

{
“SerNo”: 100482,
“IMEI”: “351579050616323”,
“ICCID”: “89610164556427000029”,
“ProdId”: 17,
“FW”: “17.1.1.23”,
“Records”: [
{
“SeqNo”: 24866,
“Reason”: 11,
“DateUTC”: “2014-05-12 12:57:14”,
“Fields”: [
{
“GpsUTC”: “2014-05-12 09:26:39”,
“Lat”: -31.9535124,
“Long”: 115.8241971,
“Alt”: 18,
“Spd”: 4,
“SpdAcc”: 2,
“Head”: 0,
“PDOP”: 28,
“PosAcc”: 12,
“GpsStat”: 3,
“FType”: 0
},

Understood. In that case, yes, I would use a webhook like your originally suggested. You can then use the Webhook Trigger to kick off a cloud workflow. Then, using a Device State Node, you can pull values off of the payload and report them as state for any attribute on your device(s).

Finally, if you’d like, you can use a Webhook Reply Node to issue a 200 response code to the webhook request, which will delete the data from the tracking device.

You should be able to give him the URL of the webhook after you generate it, and since the request will be made over https, the port will be 443.

1 Like

How did you set up your connector on OEMserver? I can’t figure it out according to these instructions: https://docs.losant.com/mqtt/overview/


20240130_134434

Much appreciated,
Warren

It looks like you’re attempting to use Losant’s MQTT broker, but OEMServer does not support MQTT as a connector.

You’ll instead want to use a Webhook. When you create a Webhook, you’ll receive a unique URL that you can provide in OEMServer’s Url field. When OEMServer invokes the Webhook with a message, that will trigger a Losant Workflow through the use of the Webhook Trigger Node. You will then add whatever additional nodes are required to process the specific message.