Home > Net >  How to fetch a URL containing a # with Fetch API?
How to fetch a URL containing a # with Fetch API?

Time:05-25

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#[email protected] and when when I fetch https://www.googleapis.com/calendar/v3/calendars/addressbook#[email protected]/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 ?

CodePudding user response:

You probably need to percent-encode the calendarId:

> encodeURIComponent("addressbook#[email protected]")
"addressbook#[email protected]" 
  • Related