Supernotes Drafts Action?

Has anyone seen or might be up to create an integration with Supernotes?

Adding the 1st line of text as the title then everything after as the body of a new card seems like a perfect fit for Drafts.

https://supernotes.app/ Is the app

And they have a pretty nice looking API https://api.supernotes.app/docs/

I chatted with one of the Supernotes founders and was able to get some help along with a tip from @FlohGro to get me started.

Here’s what I have so far using the documentation here:

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

var response = http.request({
  "url": "https://api.supernotes.app/v1/cards/simple",
  "method": "POST",
  "data": {
	  
   "headers": {
    "HeaderName": "HeaderValue"
    "Api-key": "XXXX",
    "Content-Type": "application/json",
  }

   "body": {
     icon: "",
     name: "[[title]]",
     markup: "[[body]]",
     tags: "",
	},

  },

  

});

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

I’m getting this error:

Not sure if the script would be working otherwise. Anyone have any thoughts about how it looks and if there’s an obvious issue?

You are close, but your Javascript is not quite valid. Try:

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

var response = http.request({
  "url": "https://api.supernotes.app/v1/cards/simple",
  "method": "POST",
  "headers": {
       "Api-key": "XXXX",
       "Content-Type": "application/json",
  },
  "data": {   
       "body": {
             "icon": "",
             "name": "[[title]]",
             "markup": "[[body]]",
             "tags": ""
        }
    }
});

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

No comment on whether this is correct, I didn’t look at the API, but this should be valid script to make the HTTP request. You would at least still need to put in your valid API key value.

@agiletortoise thanks so much!

It seems close. It’s running now but getting a console error that says

422
undefined
Script step completed.

Does that 422 error mean anything specific?

The 422 is an HTTP error code being returned from the API. You might log the response.responseText value in addition to the statusCode in your else block. Some APIs return more detailed error messages as a body of the response.

I expect this means that the data value is not constructed properly.

Quick look at the api docs suggest they do not want the body part, more like the below.

Note I updated your title/body value as well. You were literally passing “[[title]]” and “[[body]]”. Those would not automatically be converted to anything.

let title = draft.processTemplate("[[title]]");
let body = draft.processTemplate("[[body]]");

var response = http.request({
  "url": "https://api.supernotes.app/v1/cards/simple",
  "method": "POST",
  "headers": {
       "Api-key": "XXXX",
       "Content-Type": "application/json",
  },
  "data": {   
         "icon": "",
         "name": title,
         "markup": body,
         "tags": ""
    }
});

@agiletortoise ok thanks so much!

That makes sense. I added a missing closing quotation mark to line 2 but am still getting this error:

Do you know what that might mean?

Ah looks like I just mistakenly deleted the line

var http = HTTP.create();

when pasting in your code.

Looks like it’s running successfully now. It’s not yet being picked up by Supernotes but I’ll see if there’s something with the data being sent over that still needs to be tweaked.

Thanks so much for your help!

Actually maybe I spoke too soon. I am still getting that 422 error I just had also removed the logging / error handling section from the sample code I started with initially. So I’m still getting this

Try this at the end of your script, changing the error output to responseText and see what their API is saying is wrong. It may have an informative message.

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

@agiletortoise ah thanks! That gave me enough info to fix it myself.

It was expecting a list for tags but I just had a blank string. I was able to remove that line entirely and it’s working now!

So excited, thank you!

1 Like

Here’s the code I used in case anyone else finds this useful

var http = HTTP.create();

let title = draft.processTemplate("[[title]]");
let body = draft.processTemplate("[[body]]");

var response = http.request({
  "url": "https://api.supernotes.app/v1/cards/simple",
  "method": "POST",
  "headers": {
       "Api-key": "XXX",
       "Content-Type": "application/json",
  },
  "data": {   
         "icon": "",
         "name": title,
         "markup": body
    }
});

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

Yeah! That’s great. Glad you stuck with it.