We are looking for the same thing. Imagine you have a form on your landing page and make it optional to add contact details (for us also information without contact is useful to stock statistics). Now, whenever someone sends in a form we want the conversation to be closed automatically to avoid unnecessary work.
Here's a custom code action I built out and tested.
const http = require('https');
exports.main = async (event, callback) => {
/*****
How to use secrets
Secrets are a way for you to save API keys and set them as a variable to use anywhere in your code
Each secret needs to be defined like the example below
*****/
const HAPIKEY = process.env.Hapi;
const hs_thread_id = event.inputFields['hs_thread_id'];
//close the conversation/thread
var options = {
"method": "PATCH",
"hostname": "api.hubapi.com",
"port": null,
"path": "/conversations/v3/conversations/threads/"+hs_thread_id,
"headers": {
"accept": "application/json",
"content-type": "application/json"
}
};
var closeThread;
var req = http.request(options, function (res) {
var chunks = [];
res.on("data", function (chunk) {
chunks.push(chunk);
});
res.on("end", function () {
var body = Buffer.concat(chunks);
console.log(body.toString());
closeThread = body.toString();
});
});
req.write(JSON.stringify({status: 'CLOSED', archived: true}));
req.end();
callback({
outputFields: {
closeThread: closeThread
}
});
}
Here's what the inputs look like:
The auth token is for one of your private app tokens (NOT HAPIKEY).