1. Learn
  2. /
  3. Courses
  4. /
  5. Working with the OpenAI Responses API

Connected

Exercise

Defining a Function for Converting Timezones

You're building a scheduling assistant that helps coordinate meetings across different timezones. The OpenTimezone API provides timezone conversion services—you just need to send it a datetime, source timezone, and target timezone, and it returns the converted time. Your task is to create a function that makes this API call and returns a formatted result.

The requests and json modules have already been imported for you.

Instructions

100 XP
  • Set the url variable to "https://api.opentimezone.com/convert".
  • Create a payload dictionary with keys "dateTime", "fromTimezone", and "toTimezone" mapped to the function's arguments.
  • Make a POST request to the url assigning the payload as JSON.
  • Test the function works with the values provided.