Intergration with capacities

since recently, Capacities have an API. (Capacities API | Capacities Docs). could such API be used to share draft notes to an object (a space to store content) in Capacities, and ideally have a backlink created to that note in the DailyNote?

From a Quick look it seems like you could use the /save-to-daily-note endpoint documented here:
https://api.capacities.io/docs/#/

From Drafts perspective you can use the HTTP object to create such a request with the required parameters and necessary token for capacities

1 Like

Thanks, unfortunately, not fully aware of the scripting language.

I have an API server and a token, but how to authorise me with the token, and how to put the API content in the Drafts script

If you are partially aware, then why not take a look at the documentation linked above and some of the existing integrations for other services that have been created (see the directory for a wide variety of actions)? Chances are you you can piece it together and become even more familiar with scripting in Drafts.

telle me, based on the Drafts template,

  • where to PUT, the API details?
  • where to put the API token?

the only part I understand is the server

let http = HTTP.create(); // create HTTP object

let response = http.request({
“url”: “http://api.capacities.io/”,
“method”: “POST”,
“data”: {
“key”:“value”
},
“headers”: {
“HeaderName”: “HeaderValue”
}
});

if (response.success) {
var text = response.responseText;
var data = response.responseData;
}
else {
console.log(response.statusCode);
console.log(response.error);
}
Copy

Have you looked at any existing actions as an example like I suggested? Above looks like the example code from the HTTP documentation page and nothing else.

Each API will have its own endpoints, parameters, headers, etc. but there is commonality you can draw upon. This, along with the Drafts and API documentation are what give you the details to build the integration.

A good example to take a look at first could be this one.

Take a look at that and maybe a few others (just search for “API” in the directory and have a browse) and see how much further that gets you.

If you have never written scripts to make HTTP requests against a REST API, you may need to sort out a few more details to understand how to get this up and running. The URL you would need should be to a specific endpoint in the API.

Authentication is covered in their docs and is in the form of a Authorization header included in the request.

It looks like they have a format for blocks that would need to be understood to build and send the right type of block to add.

I don’t have time to parse all that out right now, but it looks totally possible, just maybe more complex than you are imagining.

1 Like