Search code examples
javascriptgoogle-calendar-apifetch-api

How to fetch a URL containing a # with Fetch API?


I'm using the Google Calendar API and to fetch the events of a calendar, you must send a GET request to the https://www.googleapis.com/calendar/v3/calendars/calendarId/events endpoint.

Problem is calendarId may contain a # like in addressbook#contacts@group.v.calendar.google.com and when when I fetch https://www.googleapis.com/calendar/v3/calendars/addressbook#contacts@group.v.calendar.google.com/events, it's only actually fetching https://www.googleapis.com/calendar/v3/calendars/addressbook, i.e. the part of the URL before the # (I see it in the Chrome Network tab and I just get GET https://www.googleapis.com/calendar/v3/calendars/addressbook 404 in the console)

So how can I force the fetch() method to use the entire URL ?


Solution

  • You probably need to percent-encode the calendarId:

    > encodeURIComponent("addressbook#contacts@group.v.calendar.google.com")
    "addressbook%23contacts%40group.v.calendar.google.com"