I’m trying to update submitted data via google sheets. I’m doing some initial testing with the follow code but it does not work.
function apiPatch() {
var payload = {‘_id’:‘235834200’,‘data’:{‘teacher’:‘teacher2’}};
Logger.log(JSON.stringify(payload))
// API Endpoint options, including header options.
var apiOptions = {
“muteHttpExceptions”: true,
“method” : “PATCH”,
“headers” : {
“Authorization” : “Token MY UNIQUE TOKEN”,
“Content-Type”: “application/json”
},
“payload”: JSON.stringify(payload)
};
Logger.log(apiOptions)
// Fetch contents from API endpoint.
var apiResponse = UrlFetchApp.fetch(‘https://kf.kobotoolbox.org/api/v2/assets/**MYUNIQUEFORMID**/data/bulk/’, apiOptions);
Logger.log(apiResponse.getContentText())
}
The log enties from this are as follows
- {“_id”:“235834200”,“data”:{“teacher”:“teacher2”}}
- {method=PATCH, payload={“_id”:“235834200”,“data”:{“teacher”:“teacher2”}}, headers={Authorization=Token MY UNIQUE TOKEN, Content-Type=application/json}, muteHttpExceptions=true}
- {“payload”:[“This field is required.”]}
I’m new to API calls and JSON and my hunt for info on why this response is given is proving to be fruitless. Does anyone know what I’m missing?