Drafts to Kinopio

I wish to write a Drafts action to send text to Knopio.

There is a script available at github.

#!/usr/bin/env bash
source .kinopio
http POST https://api.kinopio.club/card "Authorization: $KINOPIO_API_KEY" spaceId=$KINOPIO_SPACE_ID name="$*"

How do I convert this to a Drafts action? The API docs are here.

HTTP requests are scripted with the HTTP object in Drafts. That would translate to something like the below, I think. The docs don’t seem real clear about what data types they accept, so may need some tweaking.

let apiKey = "YOUR-API-KEY"
let spaceId = "YOUR-SPACE-ID"
let name = "YOUR-NAME-VALUE"

let url = "https://api.kinopio.club/card"
let http = HTTP.create(); // create HTTP object

let response = http.request({
  "url": url,
  "method": "POST",
  "data": {
    "spaceId": spaceId,
    "name": name
  },
  "headers": {
    "Authorization": apiKey
  }
});

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

2 Likes

Thank you, Greg!
Appreciate it :slight_smile:

1 Like

@agiletortoise when the API returns a 201, the response.success flag is false.

That seems like a bug. That flag should be true since 201 is a successful create, right?

Thanks!
Ben