Making API calls

Hi! How can I make an API call ?
As an example, I want to do a GET request to this API: http://worldtimeapi.org/

Welcome to the community, In python try this…

import json
import requests
url = "http://worldtimeapi.org/api/timezone/America/Toronto"
headers = {'content-type': 'application/json'}
r = requests.get(url, headers=headers)
details = json.loads(r.text)
print(details)
print(details['timezone'])
print(details['abbreviation'])
print(details['utc_datetime'])
print(details['utc_offset'])

1 Like

Did you try requests python library yet?

Here are three examples of skills from the Mycroft market place that use requests:



2 Likes

Thanks! I get it!
However, I will show you what I was doing:
url = “http://worldtimeapi.org/api/timezone/America/Toronto
response = requests.get(url)
self.speak_dialog(response) – Here I had an error → response is not JSON serializable

I try with a lot of things. The reasonable solution was doing: jsonify(response)
But, nothing. Always the same error.

Thank you! I will take a look!

self.speak(details[‘timezone’])
self.speak_dialog would imply your are using a .dialog file to get the response from.