First thing first:
Unless you are using jQuery under node.js, you won't be able to use client side javascript to access Marketo REST API, as these requests will be blocked due to CORS.
Also, your Client Secret needed to generate an Access Token would not remain secret any more at the client side. So, you have to do this from your server.
The payload:
The payload in question is better documented under the REST API / Lead Database / Custom Objects section of the API documentation.
In your case it would look something like this:
{
'action' : 'createOrUpdate',// optional
'dedupeBy' : 'dedupeFields',// optional
// input is an array of objects containing the custom object fields
'input' : [
{
'personID' : 'personID',
'emailAddress' : 'emailAddress',
'question01' : 'question01 value',
'question02' : 'question02 value'
},
// …Other items…
]
}
which should be in the body of the request. The sample code below is an illustration how you would do it with jQuery, but again, it won't work from the client side.
var instanceId = '123-ABC-456',
accessToken = 'ACCESS_TOKEN',
customObjectName = 'customObjectName_c',
payload = payloadFromAbove;
$.ajax({
// Constructing url with ES6 String Interpolation
url: `https://${instanceId}.mktorest.com/rest/v1/customobjects/${customObjectName}.json?access_token=${accessToken}`,
method: 'POST',
data: JSON.stringify(payload),
dataType: 'json',
})
.done(function(response) {
console.log(response);
});