Are you sure you tried with JSON.stringify correctly? This example here correctly creates a project for me in Basecamp with the specifified project name/description in the POST payload.
Note, I wrote this quickly to not include the UserAgent - you'll want to put that back in.
function createProject() {
var user = 'USERNAME';
var password = 'PASSWORD'
var accoundId = 'ACCOUNTID#';
var url = 'https://basecamp.com/'+accoundId+'/api/v1/projects.json';
var payload = {name : 'new project', description : 'my project description'};
var opt = {
contentType : 'application/json',
method : 'post',
headers:{Authorization :"Basic " + Utilities.base64Encode(user + ':' + password)},
validateHttpsCertificates :false,
muteHttpExceptions : true,
payload : JSON.stringify(payload)
};
var response = UrlFetchApp.fetch(url, opt);
var text = response.getContentText();
Logger.log(text);
}
In order to update a project, you have to use the put
verb instead of post
as documented here
Here is a working sample -
function updateProject() {
var projectId = '2413370';
var url = 'https://basecamp.com/'+accoundId+'/api/v1/projects/'+projectId+'.json';
var payload = {name : 'new project', description : 'my new new project description'};
var opt = {
contentType : 'application/json',
method : 'put',
headers:{Authorization :"Basic " + Utilities.base64Encode(user + ':' + password)},
validateHttpsCertificates :false,
muteHttpExceptions : true,
payload : JSON.stringify(payload)
};
var response = UrlFetchApp.fetch(url, opt);
var text = response.getContentText();
Logger.log(text);
}