A friend of mine helped me with the Clickup integration to Dratfs. Here it is:
// Token from API
const authorizationToken = "pk_XXXXXX_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
function createTask(categoryID) {
let url = "https://api.clickup.com/api/v2/list/" + categoryID + "/task";
let title = draft.processTemplate("[[line|1]]")
let description = draft.processTemplate("[[line|2..]]")
let body = {
'name': title,
'description': description,
// Person assignees ID
'assignees': [XXXXXX],
// Status name
'status': "TODO"
};
let http = HTTP.create();
let response = http.request({
"url": url,
"method": "POST",
"data": body,
"headers": {
"Content-Type": "application/json",
"Authorization": authorizationToken
}
});
}
// List name ID (last digits from url
createTask("XXXXXXX");
3 Likes
It is probably worth taking a look at credentials in Drafts for holding the API key.
Credential objects can be used in actions which require the user to provide a username, password and optionally a host name, to connect to a service. By using credentials objects, actions can be written to connect to arbitrary web services without hard coding credentials into the action.
It should only be a relatively small change to your existing code.
It may be that you want to do something similar with the assignee, or make that a parameter like the category ID.
As a general rule, you want to avoid hard coding anything that might vary. Hardcoding the URL, that’s fair enough as it is unlikely to change without a bigger change to the API for the service, which probably then needs a code review for the action. But things like keys and IDs, specifically the API key and the assignee ID, may be worth a bit of extra tinkering.
It might also be useful to see what an example of setting up a draft might be like? I can tell from the code what the structure of the draft would be and how it would get added to Click Up, but not everyone will.
3 Likes