Hi David, and welcome to the community!
Pretty sure you can - https://www.w3schools.com/jsref/jsref_encodeuri.asp
If sending the JSON payload encoded in the URL, you may run into issues if the JSON content is large. Typically, APIs also support POSTing the JSON data in the body of the request in which case you needn’t URL encode it but it must be passed as a serialized string using JSON.stringify()
.
so let’s say I have a JSON object:
{“event”: “Airtable Task Created”,
“properties”: {
“distinct_id”: “123”,
“token”: “145353”,
“prop”: “value1”
}
}
and I need to send that event to https://api.mixpanel.com/track
it accepts a data parameter which is the JSON either url encoded or base64 encoded per the docs here: https://developer.mixpanel.com/docs/http
If I POST this with the JSON data in the body of the request, it seems I’d need to do more than just JSON.stringify()
so let’s say I have a JSON object:
{“event”: “Airtable Task Created”,
“properties”: {
“distinct_id”: “123”,
“token”: “145353”,
“prop”: “value1”
}
}
and I need to send that event to https://api.mixpanel.com/track
it accepts a data parameter which is the JSON either url encoded or base64 encoded per the docs here: https://developer.mixpanel.com/docs/http
If I POST this with the JSON data in the body of the request, it seems I’d need to do more than just JSON.stringify()
Yes - you’d need to use fetch() to POST the JSON paylod to that endpoint. However, this assumes the mixpanel API supports this method and I cannot imagine why they wouldn’t. However, it’s always good to read the API docs - and sure’nough - it does.

It might look something like this…
let myJSONObject = {
{
"event": "Airtable Task Created",
"properties": {
"distinct_id": "123",
"token": "145353",
"prop": "value1"
}
}
let thisURL = "https://api.mixpanel.com/track";
let postOptions = {
method: "POST",
headers: {
'Accept' : 'application/json',
},
body: JSON.stringify(myJSONObject)
}
const postResults = await fetch(thisURL, postOptions);