Changing the API URL that the photon grabs data from

I am not sure if any of you have experience with the httpsclient for the photon. So far my experience has been fairly negative. When I do http get from an api url that doesn’t need authorization I get it about 80% of the time. Obviously, I wish it was closer to 100%. Here is my predicament:

I am creating an android app that allows a user to select a professional sports game (NHL, NBA, MLB, NFL), once the user selects this game, I need the app to send the games API URL over to the particle photon and I was going to have the photon grab the scores from this URL using HTTPS GET. However, my experience with using HTTPS GET with the httpsclient has been horrible. I know that webhooks is the preferred method. However, the API URL that I need is going to change every time the user selects a certain matchup. There are literally millions of sports games being played. So it isn’t possible to make a webhook for every one. I just want to know some of your guy’s thoughts on other solutions. Here is what I have come up with. Let me know if these are even possible:

1: use https get from a different wi-fi module (like esp8266/sparkfun thing)
a: user selects game with app
b: app sends URL to photon
c: photon uses https get to grab game data

2: Use webhook and Find a way to update webhook API URL with app
a: user selects game with app
b: app updates webhook to connect to that url
c: photon is always hooked up to that webhook

3: use webhook and find a way to use an external system to update webhook API URL. Have app send it to that external system
a: user selects game with app
b: app sends game’s URL to raspberry pi
c: PI edits webhook to have new URL

4: Make external API URL that will mirror the URL selected by app
a: user selects game with app
b: app sends API URL to something that updates the API URL we were using to mirror the game’s API URL
c: we have a webhook that is always connected to our API URL
d: The photon is always connected to this webhook

5: use a raspberry Pi instead of photon
a: user selects game with app
b: app sends API URL to raspberry pi
c: raspberry pi does http get to grab data from that URL

Posting " Https get with photon sucks!" and then asking for help is not the way to get things done.
Just because “you” are getting “about 80% of the time” does not mean its the devices fault.
Odds are its yours. We have many devices on a few products deployed in the field for 2 years now. Each one on their own customer networks, and we have not had one complaint of issues.

Spend more time learning and reading the docs before you say something sucks, and for sure dont say something sucks and then ask for help.

2 Likes

Sorry. I’m not saying it’s the device’s fault. I was starting to think it would be the same whether I used an Arduino or even the spark fun thing. I guess I didn’t realize how offensive that was. The photon is a great device and I wouldn’t be using it if it wasn’t. I will change the title.

1 Like

Also, just to clarify what you said. You have many devices using the https clent library? Is that true? And no complaints?

We are using http, and works perfect.

I think https is a different story though.

It might very well be, I’ll let another comment on that who has tried it. My beef (which you changed) was your tag title and when you said that 80% of the time it worked. Whereas 100% of time for me with http. So sounded to me you might not be doing something right if your only getting 80%. Might want to look into getting that 100% before trying https.

Is it actually the URL changing or rather the path?
Have you got some sample URLs you may be looking at?

Maybe @rickkas7 can chime in about the question how dynamic a webhook’s target URL can be made

1 Like

It’s a continuation of this topic, or so it seems…

1 Like

Yes, you can use a mustache template in the url field of webhook. It’s mentioned in passing in my intermediate webhook tutorial but it should work.

2 Likes

I think it might just be the URL. here are some samples:

https://api.mysportsfeeds.com/v1.2/pull/nhl/current/scoreboard.json?fordate=20180130&&team=CHI
https://api.mysportsfeeds.com/v1.2/pull/nba/current/scoreboard.json?fordate=20180129&&team=BOS
https://api.mysportsfeeds.com/v1.2/pull/nfl/current/scoreboard.json?fordate=20170129&&team=BOS

And yeah. I think the mustache might be a good idea. I think the only problem might be the fordate. Unfortunately, the API doesn’t have a way of setting the fordate to today’s current date. If I could do “fordate=today”. I think we would be set with using the mustache template. Let me know if there is a way though.

And thanks a lot for all the help guys! I am about to head to work but when I get done I will start working on the solutions you guys are giving me. Thanks!

So the host name is constant and only parts of the path change.
The foredate can be passed from your device too, after all the device knows what today’s date is.

And yes, mustache templates would be the way to go for all of the dynamic fields.

2 Likes

I am assuming you are talking about the query parameters?

Not only. Also about the path portion of the URL

You could look at this part in his FireBase tutorial
https://github.com/rickkas7/firebase_tutorial#storing-data-in-a-per-device-table

note the {{n}} in the URL

3 Likes