Easiest Way to Shorten URLs?

But the method for recovering the token is freaking ridiculous :rofl:

So now, in relation to the Bit.ly macro, we're going to replace the script with:

And the %JSONValue% by:

And… voilà!

Droplr Link.kmmacros (26.0 KB)

1 Like

I totally agree. :sweat_smile:

I can confirm on my end that it works! Thank you so much, @carycrusiau. :pray:t3:

1 Like

I've got an update, @carycrusiau!

The macro has been working well, except that every week or so it would suddenly stop working. I figured out it was because my token had changed. Once I grabbed the new token and inserted it into the script, the macro started working again, at least until the token would change once more.

I reached out to Droplr and asked why this was happening, and they responded:

"Just to clarify, our tokens typically have a one-week expiration period as part of our standard procedure. When you make a request, a new token is returned in the headers. The header you're looking for is 'x-droplr-authorization.' This header is sent with each request, providing a new token automatically. Utilizing this header will allow you to refresh your token as needed."

Based on what he wrote, do you have any ideas on how the script and/or macro can be updated to accommodate for this?

Hi @alexcr,

I took a look at it and, yes, it's possible. You send a request with a valid token and you receive a new token which is valid for one week. So, if you use the macro every day or at least once during the week (before the token expired), you receive a new token and the macro works again for at least a week. We therefore need to use a variable to store and use this new token for the next request. However, if you exceed this period of time, you'll have to go back and get a valid token by connecting to the site and looking for it in the cookies to encode it in the variable. I need a bit of time to check the error messages we get when the 7-day period has expired so that I can build a macro that's as clear and clean as possible so that everyone can understand and use it. And to see how I can deal with the fact that the 'token' variable exists the first time it's used.

Give me a few days and I'll come back with a new macro ready to use.

1 Like

Thanks, @carycrusiau. You're awesome.

Maybe one approach would be to create an additional separate macro that, once a day, pings Droplr to retrieve an updated token, which it then saves to the variable you mention? That way, you'd just about always have a fresh token, even if you haven't used the original macro in awhile.

The only scenario where you'd then have an invalid token would be if, say, your computer has been off or disconnected from the internet for seven days. (And in the uncommon scenario that this happens, there can be an error message that explains to the user how to retrieve a new token from the Droplr website, and that also then provides a method for manually updating the variable to this manually retrieved token.)

An even better solution, if at all possible, would be to have the "daily token refresh" script run on the web. That way you'd always have a fresh token available, even if your computer has been shut down and disconnected from the internet for an extended period. Though that might involve using services beyond Keyboard Maestro.

Very nice idea! We could use a Periodic Trigger to ping Droplr to retrieve a new token every day. I'll look into it!

1 Like

Yep! Then, the only scenario that wouldn't be covered would be if your computer is shut down or disconnected from the internet for over seven days. (Though maybe there's a way to run the script from the web, and not the computer, so that this wouldn't be an issue.)

Happy New Year, @carycrusiau. Any luck yet on updating the macro? No worries if you've been busy with the holidays.

Happy New Year!

I was on holiday for the festive season. Back to work tomorrow. I'll no doubt have the chance to get back to it. Stay tuned!

1 Like

I have been following this thread since the Droplr app has changed significantly, breaking some of my workflows.
I have found this resource: GitHub - Droplr/droplr-js: Official Droplr API Client for Javascript, but I do not know if it can help with this issue. I am not very knowledgeable in node.js, so I am unsure how this could be implemented with KM.

1 Like

Thanks, @carycrusiau. Hope you had a great holidays.

I'm not really an expert in Node.js but I've already used some packages. I installed 'droplr-api' but the Terminal told me about a serious vulnerability linked to Axios, a dependency of 'droplr-api'. The last update of the package was more than 6 years ago. So, for something I don't really need (I'm just trying to help @alexcr with a macro for Droplr), I prefer not to use it.

2 Likes

Hey, @carycrusiau! No rush, of course, but just curious if you had a chance to get back to this? I appreciate your help.

I've got back into it a bit but I have to admit that I'm very busy at the moment. Sorry about that!

No worries, @carycrusiau. Keep me posted and let me know how I can be helpful. :pray:t3:

Thank you very much for these macro's. It has been a few years that I have not been able to use my API in TextExpander and I tried to fix them a few times but with no luck. I love that the TinyURL macro allows you to give a unique name to it like you can do directly in bitly.com but without having to go to the website.

Great to be able to shorten URL's again thanks @carycrusiau for all your help in this forum on this.

1 Like

Hello Cary (@carycrusiau):wave:

I am new to working with API’s and just curious - how do you handle the API Keys/ Tokens ?!

I‘m asking because of the fact that you can create a Keyboard Maestro Password Variable which is then accessible through other actions using AppleScript or JXA - but it is not possible getting access to a Keyboard Maestro Password Variable via AppleScript or JXA.

Another thing - what’s about the Link Aliases - are there chances to delete them for example during a request for a newer version of the token ??! Something like this would be very useful - especially if you are then eventually able to reuse the Alias.

This then maybe could result in keeping a posted link up to date without changing it every time … :thinking:

Greetings from Germany

Tobias