Help! How to POST or use Webhook


#1

I am new to HTTP REST and webhooks so forgive me for my ignorance…

I found a tutorial online that will allow me to use Postman to send data to a table on SAP HANA Cloud Platform (similar concept to the Microsoft Azure platform). The tutorial works just fine with static, fictitious data. I would like to use data from my Particle Core instead.

Can I send data to the SAP Platform with a web hook or a HTTP POST? If so, where does that logic live? Do I put this “POST” logic into the Web IDE and then flash my device and it will communicate to the SAP Platform directly? Or will this logic be created in a web hook that lives on the Particle Cloud, meaning the core will send data to Particle Cloud, then to SAP?

I read the webhook tutorial but I ended up more confused…

https://docs.particle.io/guide/tools-and-features/webhooks/#particle-webhook-create

^didn’t help me much. I would appreciate some guidance so i can focus on the correct approach. i.e. using HTTP post or webhooks.

Thank you,
Anthony


#2

Webhooks are the way to go, basically its the particle cloud doing the HTTP POST. The core/photon will publish an event, this event triggers the webhook which does the http post. Its all built in and reduces the amount of code significantly and adds security.

logic will live on the core/photon, in that the sensor data will require some logic to format the event data.

the webhook needs to have some logic too, to know how to process the data in the event so it matches whats required for HANA

have you got a link to the first tutorial you mentioned?


#3

You will need:

1.) CLI installed
2.) A .json file with all the information for your webhook
3.) For POST, you will need something like requestType: 'POST' in the .json file as shown in the example.


#4

Thanks for the help.

The link for the tutorial is: http://www.slideshare.net/saphcp/sap-hcp-iot
It was part of a larger blog post on the SAP collaboration network: http://scn.sap.com/community/internet-of-things/blog/2016/01/29/how-iot-and-hcp-can-keep-thanksgiving-dinner-fresh


#5

Thank you for the help. I have the CLI installed from the node.js installation and the .json file can be created in notepad (I assume?). I saw an example listed for librato on the Webhook guide webpage. The example uses a username and password. However, the tutorial I found for Postman uses “bearer” for authorization. Would I replace the username and password with “bearer”? I saw a small example of “bearer” used in the header section but it did not provide an example within an entire POST template. Additionally, the tutorial specifies a “Content-Type”. Where would this fit in?

Thank you,
Anthony


#6

Can you share the docs for the website that you are trying to send a webhook too?


#7

Here is a link to the HANA Cloud Platform. I have setup my own trial account here:
https://hcp.sap.com/index.html

As for the documentation, I tried to upload the pdf tutorial but I am limited to jpeg, png, gif. I downloaded the guide from here: http://www.slideshare.net/saphcp/sap-hcp-iot

Is this what you were asking for?
Thank you,
Anthony


#8

Hmm the docs are really tough to read.

Can you share the link for the Postman to SAP Hana example? That should provide me with all the required information. :wink:


#9

Here is the share link for the Postman example. I am new to Postman so hopefully this is what you have asked for :smile:

Thank you,
Anthony


#10

@Anth,

  1. I removed the postman link you shared since it contains all the credentials needed to access your account :stuck_out_tongue: (that said i was able to test and get it working with the credentials :see_no_evil:)

2.) Here’s the .json file you will need: https://gist.github.com/kennethlimcp/84ebac8ad4c8e9ed6084

3.) Be sure to replace the 2 values in xxxxxxx

  • the url will be something like: https://iotmmsi8403.....
  • bearer will be Bearer 1029013910231........

4.) Use the CLI and do a particle webhook create sap-hana.json

5.) open a new command line and type particle subscribe mine or use Dashboard to see the webhook response

6.) Do a particle publish "hana_test" example

This is hardcoded with the temperature and humidity value at this point in time though.

Also, the timestamp is hardcoded as well since it requires type of long but the webhook is only able to provide a string timestamp…

Seems like you need to handle this using firmware over webhooks…


#11

Thank you so much for your help! :smile:
This is great! I will address the timestamp challenge shortly. First, I will continue to play with the webhook to better understand how this all works. Much appreciated!!

Anthony


#12

@kennethlimcp
I am having some trouble putting in a variable from the core. In the webIDE I used Spark.publish(“hana_”) and it successfully called the webhook. Now I would like to include data in the Spark.publish function. I looked at some other posts and the data is sent as a string. Example is from another post:

I am assuming the sprintf is creating a string called publishString with the hour, min, sec variables replacing the 3 %u’s. The string is then sent to the “Uptime” webhook. I do not understand what the JSON file looks like to receive the string with 3 variables. In the JSON file you shared with me, the values were hard coded. If i wanted to send the temperature value of 75 from the core, I assume the IDE code would be as follows:

Spark.publish(“hana_”, “{“Temperature”:75}”;

What would the JSON file look like for receiving the temperature value with the webhook call? Currently the JSON file has a numeric value and not a placeholder for a variable. i.e. “Temperature”: “80.2”

Thank you,
Anthony


#13

this is exactly what I am looking for, can you share your solution on this?
did that link ( Using Spark.publish() with Simple JSON Data ) worked for you.

I also have the webhook with the material ready to talk to another cloud “Artik.Cloud”, the webhook works. As of now, I have fixed values as place holders in my webhook, but is time to move to variables published by particle core, and I have the same questions you have above.

In contrast with what you had, I am publishing an array of integers so my string can extend

here is my post: