0

I am creating a new event in google calendar by the following URL structure.

   https://calendar.google.com/calendar/r/eventedit?
   text=discount for Asgardian&
   dates=20200327T032400Z/20200327T032400Z&
   details=Thor will be there to receive you&
   location=Asgard&
   trp=false&sprop=&sprop=name:

here is a URL variable text, which represents the title of an event.

if I pass a plain string, it works well. but if I pass special character like '%' (e.g. 20% off for Asgardian), then google calendar gave me -

  Bad Request 
  Error 400

how can I pass '%'?

(same error for details vaiable also)

  • 2
    You will need to encode your entire payload so that it can be passed safely in the URL. For example, `%` should be encoded as `%25`. Which language are you using? – Terry Mar 03 '20 at 08:18
  • it works for **%25**. thanks. – Muntaha Ibn Ahmed Mar 03 '20 at 08:20
  • @Terry I am using javascript – Muntaha Ibn Ahmed Mar 03 '20 at 08:20
  • 1
    If that's the case, try looking into [`encodeURI()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURI) and [`encodeURIComponent()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent) – Terry Mar 03 '20 at 08:22
  • 1
    Event update (POST) and event patch (PATCH) methods for the google calendar api take the parameter values as part of the body why are you stringing them like query parameters? on top of the fact that r/eventedit isnt even a Google calendar api endpoint that i know of. – Linda Lawton - DaImTo Mar 03 '20 at 08:47
  • @DaImTo it's not exactly part of google calendar API. I took the URL format idea from here - https://stackoverflow.com/a/19867654/7873583 – Muntaha Ibn Ahmed Mar 03 '20 at 10:27
  • 1
    @IbnAhmed if you are not using the [Google calendar api](https://developers.google.com/calendar/) then please remove that tag and place the correct tag. to avoid confusion. **Calendar API lets you display, create and modify calendar events as well as work with many other calendar-related objects, such as calendars or access controls.** – Linda Lawton - DaImTo Mar 03 '20 at 10:37
  • @DaImTo I removed the tag. thank you. – Muntaha Ibn Ahmed Mar 04 '20 at 11:20

1 Answers1

1

in the comment, @terry gave me answer for how to pass % through URL. I need to encode it as %25.

he also share that - Javascript has a built-in function for this URL encoding. encodeURIComponent()

if we wrap our string by encodeURIComponent(), it'll give us URL encoded string.

thanks.