Add to Tana runs but doesn't add to Tana

I have added the action and obtained the API from Tana to add to the action and it seems to run quite happily BUT I am not seeing the result in Tana!

The description instructs “[In Tana] Create a node for entries to be added to. For example: I added one called Inbox on the root node.”

My Tana already has an inbox at what appears to be root level.

My test item from Drafts is not showing up in a title search in Tana - to rule out whether it is going somewhere unexpected

Is this the action you are using?

https://directory.getdrafts.com/a/2

If so did you get your token from your existing node?

The directory link didn’t work for me butthis Add to Tana action is the only one I am aware of – added by Jason a year ago.

I have copied the API on the Inbox node but when I run the action on a test para in Drafts, it appears to run but doesn’t prompt for the API key as expected. Can’t see an alternative way to add it.

The action you mention does not have any logging. It’s likely the HTTP request is failing for some reason, but you would need to explicitly log that to see what’s going on. Add the below to the end of the script and any HTTP response errors will be in the action log:

console.log(`${response.statusCode}, ${response.error}`)
console.log(response.responseText)

I tried this (with addition)

const credential = Credential.create(
“tana”,
“Tana.inc\nPress cmd+k and select ‘Get API Token’ on your inbox node”
);

credential.addPasswordField(
“token”,
“Token”,
);

if (!credential.authorize()) {
alert(“No API token provided or found.”);
context.fail(
“Tana API token not entered, or not found. Clear API token and try again if no prompt was provided.”
);
}

const content = encodeURI(draft.content);
const url = https://europe-west1-tagr-prod.cloudfunctions.net/addToNode?note=${content};

const http = HTTP.create();
const response = http.request({
“url”: url,
“method”: “GET”,
“headers”: {
“Authorization”: Bearer ${credential.getValue("token")},
“Content-Type”: “application/json”,
};

console.log(${response.statusCode}, ${response.error})
console.log(response.responseText)
}

});

And got this

Script Error: SyntaxError: Unexpected token ‘;’. Expected ‘}’ to end an object literal.
Line number: 28, Column undefined

Tried to resolve it by trial and error but I don’t know what I am doing…

You are missing back ticks in the first line you added. If you cut and paste my example you should be OK.

I think the cut-and-paste must have stripped out the backticks. Here’s the action with your addition:

const credential = Credential.create(
“tana”,
“Tana.inc\nPress cmd+k and select ‘Get API Token’ on your inbox node”
);

credential.addPasswordField(
“token”,
“Token”,
);

if (!credential.authorize()) {
alert(“No API token provided or found.”);
context.fail(
“Tana API token not entered, or not found. Clear API token and try again if no prompt was provided.”
);
}

const content = encodeURI(draft.content);
const url = https://europe-west1-tagr-prod.cloudfunctions.net/addToNode?note=${content};

const http = HTTP.create();
const response = http.request({
“url”: url,
“method”: “GET”,
“headers”: {
“Authorization”: Bearer ${credential.getValue("token")},
“Content-Type”: “application/json”,
};

console.log(${response.statusCode}, ${response.error})
console.log(response.responseText)

});

The action again with addition:

const credential = Credential.create(
“tana”,
“Tana.inc\nPress cmd+k and select ‘Get API Token’ on your inbox node”
);

credential.addPasswordField(
“token”,
“Token”,
);

if (!credential.authorize()) {
alert(“No API token provided or found.”);
context.fail(
“Tana API token not entered, or not found. Clear API token and try again if no prompt was provided.”
);
}

const content = encodeURI(draft.content);
const url = https://europe-west1-tagr-prod.cloudfunctions.net/addToNode?note=${content};

const http = HTTP.create();
const response = http.request({
“url”: url,
“method”: “GET”,
“headers”: {
“Authorization”: Bearer ${credential.getValue("token")},
“Content-Type”: “application/json”,
}
console.log(${response.statusCode}, ${response.error})
console.log(response.responseText)
});

Tis results in this message:

Script Error: SyntaxError: Unexpected identifier ‘console’. Expected ‘}’ to end an object literal.
Line number: 29, Column undefined

Please forgive my illiterate stumbling and thank you for bearing with me!

Note: If you use ``` to wrap code in the forum, it will be treated as a code block.

Here’s the complete version with the troubleshooting code where it needs to be. To be clear, I know nothing about Tana, I did also make a change to the endpoint URL (added V2) because that appears to be what they are publishing in their API docs now.

const credential = Credential.create(
  "tana", 
  "Tana.inc\nPress cmd+k and select 'Get API Token' on your inbox node"
);

credential.addPasswordField(
  "token",
  "Token",
);

if (!credential.authorize()) {
  alert("No API token provided or found.");
  context.fail(
    "Tana API token not entered, or not found. Clear API token and try again if no prompt was provided."
  );
}

const content = encodeURI(draft.content);
const url = `https://europe-west1-tagr-prod.cloudfunctions.net/addToNodeV2?note=${content}`;

const http = HTTP.create();
const response = http.request({
  "url": url,
  "method": "GET",
  "headers": {
    "Authorization": `Bearer ${credential.getValue("token")}`,
    "Content-Type": "application/json",
  }
});

console.log(`${response.statusCode}, ${response.error}`)
console.log(response.responseText)

OK, I have created an inbox on my main workspace node. ‘Agile Tortoise’ has helpfully given me an extra couple of lines to add a log trace and work out what is going on,

I got got an API for the workspace. The action appears to have saved and the log confirms this — but the instruction…

  • Create a new draft and select this action. You will be prompted for the API key
    … doesn’t tally with my experience: I have not been prompted for the API token, and nothing has appeared in the inbox.

The action uses credentials so prompts and stores on the first run.

If you clear the tana credentials you can force it to prompt you again. See guidance in the docs on doing this.

Thank you so much, Stephen. Understanding has dawned! Functionality has blossomed.

Bit of a journey but I learned some useful things about Drafts along the way — and it’s here for the benefit of others. Thanks again.

—Ian Greig

Just had a similar issue, my issue is that it creates the Tana node but it is empty. The issue is as observed by agiletortoise (hi!!), Tana has published a new version of their API (v2) and wants everyone to use it. The “v1” that this action targets still does exist, and works but has some limitations that you may be observing. One is that it can’t ingest Drafts Markdown, if the url encoded “note” query param starts with a “#” (h1), the API will return a 200/OK but create only an empty node. Removing the “#” works as you might expect for V1. Anyway, this Action does need to be updated to use V2, as we don’t know how long V1 will continue to work.

I am trying to get this figured out for my system, there are some other issues here (around exporting to a specific node) and when I get them working I’ll report back in this thread if the fix is any different than what’s already posted. So we can get the Action updated.

Not sure Tana understands Markdown (yet…!) so I just feed it plain text. It’s not a great drawback as Tana’s great strength is gathering together various strands with its power of organisation through supertags. I take my edits to Obsidian or sometimes Ulysses for finalising and that’s where Markdown scores.
But I agree that this very useful action needs updating.

I’ve created a new Drafts Action to target the Tana Input API v2, and added some functionality to export a draft to different places in a Tana Workspace and to export to one or more than one destination node in Tana.

Readme with screenshits

The code is in that repository, and I’ve created a Github issue if you want to flame me there directly :slight_smile:

@agiletortoise @greiggy @sylumer what do you think about inclusion into the Directory?

The directory is open to add to - you just add it if you think it could be of use to others and would like to share it. No need to seek any confirmation.

1 Like

Have looked in the Drafts Directory (much easier to add to Drafts from there)!