I created a POST function to Harvest using postman and it was successful, I exported the code in as javascript but then when I go to run it in the google apps script I get, ‘ReferenceError: “FormData” is not defined.’
Any idea what this is referring too?
function myFunction() {
var data = new FormData();
data.append(“name”, “TEST_CLIENT”);
data.append(“is_active”, “true”);
data.append(“address”, “”);
data.append(“currency”, “USD”);
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener(“readystatechange”, function () {
if (this.readyState === 4) {
console.log(this.responseText);
}
});
xhr.open(“POST”, “https://api.harvestapp.com/v2/clients?name=TEST_CLIENT&is_active=true&address=1%20Main%20st.%20¤cy=USD”);
xhr.setRequestHeader(“Authorization”, “Bearer {{$ACCESS_TOKEN}}”);
xhr.setRequestHeader(“Harvest-Account-Id”, “{{$ACCOUNT_ID}}”);
xhr.setRequestHeader(“User-Agent”, “(hidden)”);
xhr.setRequestHeader(“Content-Type”, “application/x-www-form-urlencoded”);
xhr.setRequestHeader(“Cache-Control”, “no-cache”);
xhr.setRequestHeader(“Postman-Token”, “HIDDEN”);
xhr.send(data);
}
I hid some parts of my code