Event problem :(

Hi :slight_smile:

I have a problem: I want to publish an event from an external source to the particle cloud. When I try it with the following website, all works great: http://onlinecurl.com/

Code:

curl --data name=myevent --data data=Hello World --data
access_token=xxxx
https://api.particle.io/v1/devices/events

But I need now the URL to make a POST request. I tried this URL but it always caused an error:

https://api.particle.io/v1/devices/events/name=myevent?access_token=xxxx
(https://www.hurl.it/)

I replaced my token with xxxx!

Could you say me what I made wrong?

best regards

1 Like

@electronweather, did you review the docs?

https://docs.particle.io/reference/api/

yes @peekay123

https://docs.particle.io/reference/api/#events

any solution?

I am not sure I understand your problem fully but I will try to add some information.

POST HTTP calls do not typically have URL parameters (the name=myevent?access_token=XXX part in your second URL). That is why the doc says to do this:

$ curl https://api.particle.io/v1/devices/events \
       -d "name=myevent" \
       -d "data=Hello World" \
       -d "private=true" \
       -d "ttl=60" \
       -d "access_token=1234"

This uses a URL with just the events path but adds parameters using -d for all the other required elements. These parameters are passed in the body of the POST request and not in the URL. This is one of the primary differences between POST and GET requests over HTTP.

1 Like

Ok :frowning: , my problem is that a website should send something to my electron but the electron doesn’t have a static ip so my idea was that I use the cloud so that the electron can receive the data. Any other ideas?

@bko

OK so using publish to send stuff to your device works well–you just can’t use a GET URL to publish, you have to POST. Not only does your electron have a non-static IP address, it is on a cellular network that is not routed the same way as an ethernet or WiFi network so outbound TCP connections are fine, but inbound is a no-no.

What code on the website are you using to send the publish? NodeJS? PHP? Python? Curl? Something else? That is the part you are missing.

I am assuming you control and code the website but if not, then is this something a webhook could be used for? Having the Particle Cloud act as the intermediary works well too.

1 Like

I don’t control the website, it’s paypal.com :sweat_smile:
Paypal transmits the IPN message to a website. At the end the Electron should get this message

@bko

OK you need a host on the Internet to translate the paypal IPN messages to Particle messages.

You might be able to get that host on the Internet to be the Particle Cloud using a webhook.

Or you could have your own host on the Internet doing the translation by running a simple web service.

https://picload.org/view/ddoogrgl/paypal.jpg.html

So how can I use a webhook to receive the data and send it to my Electron?
I thought a webhook can only send data to another website?

@bko

Now I get a success message from the PayPal IPN simulator but I cannot see the date in the webhook:

https://picload.org/view/ddoorgil/paypal1.jpg.html

I use this URL:

https://api.particle.io/v1/integrations/5a4f7b97d67baa4522044dc9/test?access_token=xxxxx

I have to use “test” because otherwise I get an error. Any ideas how I can see the data?

@bko

This is an example of the data which PayPal sends to me:

payment_type=echeck&payment_date=Fri%20Jan%2005%202018%2019%3A56%3A14%20GMT%2B0100&payment_status=Completed&address_status=confirmed&payer_status=verified&first_name=John&last_name=Smith&payer_email=buyer@paypalsandbox.com&payer_id=TESTBUYERID01&address_name=John%20Smith&address_country=United%20States&address_country_code=US&address_zip=95131&address_state=CA&address_city=San%20Jose&address_street=123%20any%20street&business=seller@paypalsandbox.com&receiver_email=seller@paypalsandbox.com&receiver_id=seller@paypalsandbox.com&residence_country=US&item_name=something&item_number=AK-1234&quantity=1&shipping=3.04&tax=2.02&mc_currency=USD&mc_fee=0.44&mc_gross=12.34&mc_gross_1=12.34&txn_type=web_accept&txn_id=448789463&notify_version=2.1&custom=xyz123&invoice=abc1234&test_ipn=1&verify_sign=AzFmRN2alSXsVcRQ-bkJDjsW0iFTAzylZCsnqZ.VFNwA6TyQlnbux0ho

@peekay123, a webhook response is limited to 512 bytes per response message. A longer website response will create two or more subscription responses so you may need to accommodate for that. Have you looked at the total response payload size from paypas?

I tried with less data (with https://www.hurl.it/) but no success :frowning:

@peekay123

@electronweather, again, what is the total size the data returned? What format are you expecting - XML, JSON, other?

Idk exactly, i only get this information: application/x-www-form-urlencoded
content-lenght: around 900

@peekay123

The problem is that the data doesnt show up (because I had to use “test” which creates a “test-event” but I wasn’t able to add some custom data :frowning:

@peekay123

@electronweather, if the “test” payload is 900 bytes then when you do get the data in there, you can expect at least two subscribe messages back to your device. As for getting the right message/data together, I will need to defer to @bko.

Ok, thank you for your help :slight_smile:

The test message is from particle:

/5a4f7b97d67baa4522044dc9/test?access_token=xxxxx

I think it’s only a few bytes

@bko @peekay123

I guess I have come around to think that you do in fact want to have your own server talking to paypal on the one side and the particle cloud on the other.

As I understand the API, you can view the payment data and basically say “yes” or “no” to the transaction. I think you should set up your own server that abstracts the data (do you really need all that data on the Electron?) and then lets you say “yes” or “no” from the Electron back to your server, which would then give the final answer to paypal.

That is the direction I would recommend.

Isn’t it possible to send the data directly to the Electron?
If it’s possible, I would like to use only the Particle Cloud and the electron

@bko