Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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 ?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You probably need to percent-encode the calendarId:

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

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading