IT Nerd Space

How to authenticate to TP Link cloud API with Tasker

How to authenticate to TP Link cloud API with Tasker

We’ve seen in a previous post what is the protocol to authenticate to TP Link cloud API. Now, what about doing that from Tasker you can ask me? Well, that’s very simple actually!

To implement that in Tasker I have used RESTask for Tasker (because I had troubles having the native HTTP Post action work for me):

RESTask for Tasker
RESTask for Tasker
Developer: Freehaha
Price: Free

Next create 3 global variables in Tasker (self-explanatory I guess):

  • TPLUSER
  • TPLPASS
  • TPLTERM (use the UUIDv4 you got above)

Then create a new Task with the following 4 actions:

The first action will be a Variable Set %payload:

Name:%payload
To: { "method" :"login",
"params" : {
  "appType" :"Kasa_Android",
  "cloudPassword" :"%TPLPASS",
  "cloudUserName" :"%TPLUSER",
  "terminalUUID" :"%TPLTERM" } }

The second action will be the RESTask call:

Further down we need to set the custom body to %payload:

Then we set the Headers:

The third action will be a Javascriptlet with the following code, to extract the token (from the rtres, passed from  RESTask) to the %mtoken variable:

var mtoken = JSON.parse(rtres).result.token;

Finally, here the fourth action will just be a Flash action, that will show the token:

Flash [ Text:%mtoken Long:On ]

The whole task should end up looking like this:

You can run the Task and it should flash the token on the screen!! Yay