Copy Email Subject and URL from Mailmate to Dynalist

I use Dynalist and am looking for a way to get my emails from Mailmate to Dynalist.

I've set up a macro that copies the subject of the email and email url to variables.

I have a Curl command


curl --header "Content-Type: application/json"
--request POST
--data "{"token":"${TOKEN}","content":"${CONTENT}","note":"${NOTE}"}"

The results in Dynalist are that the content is "%Variable%SubVar%" and the note being "%Variable%EmlVar%"

I've tried everything under the sun that I can think of to get those variables to expand, but it doesn't work.

I tried setting the whole command as a variable (endResult) and using $KMVAR_EndResult and it didn't work.

What am I doing wrong and how can I get this to work?

Dynalists API doc on the subject:

This one's probably too deep for me for me to assist with. But I'll ask a question. I don't understand where you are invoking the KM engine here to replace the KM variables and tokens. It doesn't seem that you are implying that this script is placed inside a script action in KM. If not, how where are you expecting the KM Engine to kick in? You make no mention of executing any KM action, so I'm not sure why you think that KM could respond by replacing these variables and tokens.

Remember, I'm just an average guy here. There are much smarter people here than me, so if you want to wait for them, I understand.

I think that is my issue.

I’ve set up KM to copy the subject of the email and email url into two variables; SubVar and EmlVar.

What I’m failing to achieve is getting the expanded variables into the Curl command and executing the Curl command. The command runs correctly in the execute script command, but I’m having a hard time getting the variables to expand.

I can get them to expand if I save both variables as another variable. But I then cannot get that variable to run in the execute script command. I can get it to save as text, just not into the execute variable.

Okay, now that you stated that you are running the script in an Execute Shell Script action, maybe I can help.

Because the way you are writing the command is not how variables are expanded in that action. To expand a variable in an action the syntax is: $KMVAR_varname

Perhaps if you show your action in an image then I can be sure that I'm giving you the right advice. I'm still scared that I might be giving bad advice because I'm not sure where you are executing that script.

Upon further reflection I think there's a chance you might fix this if you replace the above with this:

However I'm only 70% sure this will fix your issue because I'm only 70% sure that you are using this code in an Execute Shell Script action. And also because I don't usually use variables the way you do in unix scripts.

Output is:

So something is wrong as nothing appears in Dynalist.

Whenever I have a problem like this, what I do is find a way to see what's being passed to the command. The command you are using is curl. You are passing a string with some variables. We can't see what that string is. So I think the first easy step is to replace the word curl with echo and see what is displayed then. After the curl command you have four lines of text separated by backslashes to break the command into multiple lines. Since I'm not sure if echo works with backslashes (I think it does), you may want to combine them into a single line. Do that if you wish.

Once you see what the result is, I would then open a Terminal window and manually enter curl then place the output from the window that appeared after the word curl. Do you see my reason for doing this? It's to validate what's being passed too curl.

P.S. I had never heard of Dynalist until now, and I haven't use curl too often, so my advice is just coming from the perspective of an average KM user. But I think the odds are good that we can figure this out. I just came back from lunch so I'm around now.

This is the echo output instead of curl:

It looks like the problem could be that when the clipboard copies the Subject of the email and the url of the email that a line break is added at the end of the text copied.

My Shell script is as follows:

CONTENT="Last chance to catch the early bird rate for iKids Conference 2020"

curl --header "Content-Type: application/json" \
  --request POST \
  --data "{\"token\":\"${TOKEN}\",\"content\":\"${CONTENT}\",\"note\":\"${NOTE}\"}" \

As you can see I have pasted in an email subject and email url.

Running this in terminal works.
Running this script in KM also works.

I then introduced a line break at the end of the CONTENT and NOTE and received the same error I have been getting.

I then copied both variables I use for subject and email onto the clipboard and displayed the text. Sure enough there is a line break at the end of each variable.

So, Any idea on how to remove line breaks at the end of a variable?

Anything above very simple shell scripts is still above my head, but this much I can answer. Just use the Trim Whitespace filter action on each variable before executing the script:


Thanks for that! The macro is now working.

For anyone needing the same solution here's the macro:

MM>DL Subject and Email URL with popup confirmation.kmmacros (6.2 KB)

1 Like

Thanks gglick. I didn't think of that either. It was just yesterday that I had to write a bit of code because I didn't know how to remove a trailing CR from a variable. I never thought of CRs as white space.

1 Like