I want the flow to be easy for the user so they can simply input any sort of Coda date and have it translate on the pack side to an ISO format. Any idea how to do that?
Hi @Scott_Collier-Weir - Great question! Date parameters in Coda are passed to the Pack’s execute function as JavaScript Date objects. These objects have a built in method toISOString() that you can use to convert it to thee ISO 8601 format.
toISOString() is a method, so you’d add it to the end with a dot:
execute: async function ([mydate], context) {
let dateAsString = mydate.toISOString();
// ...
},
I don’t think an ISO date can include any characters that aren’t URL-safe, but it’s usually always a good idea to encode values just to be safe. If you use the helper function coda.withQueryParms() it will both encode the parameters and add them to the URL in one shot.
let url = coda.withQueryParams(baseUrl, {
startDate: mydate.toISOString(),
});
Yes, although if your key (part on the left of the colon) has special characters in it (like those square brackets) you need to wrap the key in quotes.
Can you say a bit more about why you’re using the square brackets in that context? I’m just worried they may not work quite the way you’re expecting (but maybe they will)
The assignment[integration_id] is just denoting that is part of the assignment but that is all. I maybe wrong and the devs that designed the Canva API really hate standards.
Also it’s just… weird to have square brackets in query parameters like that.
Personally I would pass the parameters in an object in body if it’ll let you do it that way (it should work that way too). But I guess… if it ain’t broke… ?