Meddysong Posted November 22, 2021 Posted November 22, 2021 I have a page on a couple of my sites which presents results of events taking place over the next year, taking that information from an api. I received a report about a month ago that one of the sites (now running 4.6.8., then running 4.5.x) is not displaying any results. I've checked on the other site (running 4.4.6), and that, too, is no longer returning any results. My trouble-shooting has led to these conclusions: It's not related to a change within IC because the 4.4.6 site hasn't been updated in a couple of years and the page was displaying correctly before. I don't believe it's related to a change in the server environment because I've copied the relevant code into a new local installation, and it's not working. It's likely, therefore, to be a change in the API, but I can't detect it. My api call has to go to https://eventaservo.org/api/v1/events.json with the following parameters: an email address a token a start date ("komenca_dato"), which I set to today: yyyy-mm-dd an end date ("fina_dato"), which I set to one year from now: yyyy-mm-dd If I enter these details into my browser long-hand, I receive some JSON, just as I should. Here's an excerpt: [ { "uuid": "b7892dcb-e3e7-4347-b49a-01185fd33dda", "kodo": "75a199", "titolo": "Baza Friis-kurso de Esperanto", "priskribo": "Baza kurso por portugallingvanoj surbaze de la Naturmeto laŭ Metodo Friis", "enhavo": null, "komenca_dato": "2021-09-14", "fina_dato": "2021-10-29", "retpaĝo": "https://forms.gle/veqaGfxtM8VkkRNG8", "retpoŝtadreso": "xxx@gmail.com", "specoj": [ "Kurso" ], "nuligita": false, "nuligkialo": null, "reta": true, "loko": null, "administranto": "Cícero Gabriel Cardoso Soares" }, { "uuid": "70897cd0-196a-44ea-8494-90cd3c9612f5", "kodo": "bb89c1", "titolo": "Ekspozicio pri Hector Hodler", "priskribo": "Tiu ekspozicio montras verkojn, fotojn, librojn, revuojn pri Hodler kaj pri la kreo de UEA.", "enhavo": null, "komenca_dato": "2021-09-30", "fina_dato": "2021-12-31", "retpaĝo": "https://biblio.chaux-de-fonds.ch/bvcf/informations-pratiques/Pages/horaires-acces.aspx", "retpoŝtadreso": "xxx@gmail.com", "specoj": [ "Loka", "Anonco" ], "nuligita": false, "nuligkialo": null, "reta": false, "loko": { "adreso": "Urba biblioteko, Strato Progrès 33, 2300 La Chaux-de-Fonds (Svislando) (Sama domo kiel CDELI)", "urbo": "La Chaux-de-Fonds", "lando": "Svislando", "landokodo": "ch", "kontinento": "Eŭropo", "latitudo": 47.11767829999999, "longitudo": 6.8405667 }, "administranto": "Mireille Grosjean" } ] Here's the code from my Page, which worked until at least one month ago: {{$apiUrl = 'https://eventaservo.org/api/v1/events.json'; $result = array(); try { $result = \IPS\Http\Url::external($apiUrl)->setQueryString(array('user_email' => 'xxx@xxx.com', 'user_token' => '123456asdf', 'komenca_dato' => \IPS\DateTime::ts(time())->format('Y-m-d'), 'fina_dato' => \IPS\DateTime::create()->add(new \DateInterval('P365D'))->format('Y-m-d')))->request()->get()->decodeJson(); } catch (\Exception $e) {} }} Although my page usually styles and operates conditions on the results, to keep things simple whilst troubleshooting, I'm just going to return results for one name: it's "titolo" (title). This is how I've tried to do it: {{foreach $result as $res}} {$res['titolo']} {{endforeach}} That's right, isn't it? And still there's nothing. Or have I done it incorrectly? What would help is if I could display my query string within the page to check that the $apiURL is still forming correctly but I don't know how to do that. I've tried {echo $result;} and even {echo $apiURL;} just to test, since I can see that's a standard variable, but nothing's getting returned. Can anybody offer any advice, please? I used to be dependent on the wonderful @newbie LAC to bail me out of these situations through his combination of skill and kindness but, sadly, we're coming up to a year since he's last been with us.
Daniel F Posted November 22, 2021 Posted November 22, 2021 Are there any exceptions? Right now you're catching them, so troubleshooting is going to be tricky;) Replace catch (\Exception $e) {} with catch (\Exception $e) {\IPS\Log::log($e); } Meddysong 1
Kirill Gromov Posted November 22, 2021 Posted November 22, 2021 You can remove the construction decodeJson() from the request and most likely get error description. Meddysong 1
Meddysong Posted November 22, 2021 Author Posted November 22, 2021 Very prompt replies, thank you! I've tried both your approaches, Daniel's first, and then Kirill's added to it. The code is now: {{$apiUrl = 'https://eventaservo.org/api/v1/events.json'; $result = array(); try { $result = \IPS\Http\Url::external($apiUrl)->setQueryString(array('user_email' => 'tim@meddysong.com', 'user_token' => 'ynxG7oP3oxo3LN-dbn-6', 'komenca_dato' => \IPS\DateTime::ts(time())->format('Y-m-d'), 'fina_dato' => \IPS\DateTime::create()->add(new \DateInterval('P365D'))->format('Y-m-d')))->request()->get(); } catch (\Exception $e) {\IPS\Log::log($e); } }} I assume that {\IPS\Log::log($e); } will cause errors to be logged in the ACP. I've tried a few times but am not seeing any entries at all in the Error Log, even after having set it to Levels 1, 3 and 5.
Meddysong Posted November 22, 2021 Author Posted November 22, 2021 I've sort of solved it, fellas. I usually look for events in the coming year. If I reduce the scope, then everything works fine. Once I go past 2022-08-19, the API call returns the following returns an error message. It seems that my token is set to expire at some point and that I can't look for dates beyond that. The person who designed the API is aware and is looking into it. Thank you for taking the time to look into this with me.
Meddysong Posted November 22, 2021 Author Posted November 22, 2021 All sorted now: it was a problem with the API request after a certain point in time, which has now been fixed. We're back to normal! Kirill Gromov 1
Recommended Posts