Host Engineering Forum

General Category => Do-more CPUs and Do-more Designer Software => Topic started by: Kristjan on June 14, 2023, 06:37:59 AM

Title: Training on miscellaneous BRX REST API
Post by: Kristjan on June 14, 2023, 06:37:59 AM
I have a BRX and training on different external API services. Not all services are relevant for industrial automation but I would like to get more confident with integrating towards different REST API services.

I have been reading and parsing successfully from e.g. OpenWeatherMap (with token) and Sunrise-Sunset (without token). Now I am trying out some APIs I found on publicapis.dev and in some cases I get an HTML response "301 Moved Permanently". This was the case with Strava (yes we will have beacons notifying about lack of our training   :D). Is there a way around this 301 response?

Strava tells me the CURL request should be as follows:

Code: [Select]
curl -X GET \
https://www.strava.com/api/v3/athlete \
-H 'Authorization: Bearer YOURACCESSTOKEN'

This works in Postman but not in my PLC. Am I setting up the additional header correctly in the attached image?
Title: Re: Training on miscellaneous BRX REST API
Post by: Bolt on June 14, 2023, 11:42:27 AM
I'm not a ton of help here, and since you've done a few other API's I may be wrong, but the Request does not need "https://www.strava.com" in it, only "/api/v3/athlete". Then no "https://" in the Server Name, but not sure about the "www". Also, port 80 is not HTTPS, more typically 443. But I'll be watching along to see what other tips are, as I routinely bang my head against the wall on these setups when I do them.

Additionally, perhaps the ' in combination with the " in your Additional User Request Header isn't helping either.
Title: Re: Training on miscellaneous BRX REST API
Post by: Kristjan on June 21, 2023, 10:16:22 AM
You are right, there was a problem in HTTPCMD parameters. Attached request works fine and reads my profile into BRX  8)

The token needs to be refreshed every now and then, this will be a separate HTTPCMD and subsequently parsing out the token string (luckily a short one) and passing it into new requests.

I haven't found a decent value proposition for this integration yet so I'll put further Strava work on hold  ;D But the HTTPCMD and JSON instructions are really opening up the PLC to a whole new world of information!