Monzo & IFTTT - Share your creations here!

There was a request by @Serialswitcher on the creations wiki to create a new applet for withdrawing from a pot for the “Shopping” category.

Since there’s now an ability to create custom categories with Monzo Plus I said I would do a small write up for anyone wanting to add IFTTT automation to their own categories. I already did a write up for transactions under an amount but the request is for “any transaction” so I’ve created the below as “As any card purchase above an amount” so that anyone who wants to use this can exclude small purchases if they wish.

Applet Creation Instructions
  1. First register on https://platform.ifttt.com
  2. Once registered navigate to: Applets > New Applet.
  3. Within the “Trigger” section in the field “Search services” type and select “Monzo”
  4. In the “Please select” drop-down select “Any card purchase above an amount"
  5. Under “What Amount” select visibility “Customizable by the user” this allows you to use the applet more than once for varying values
  6. Under “Default value” put your 0 (You can then set the > value when you connect the applet)
  7. Leave everything in “Which merchant?” as default again this means that you can use the applet multiple times if you need to
  8. Within the “Action” section in the field “Search services” type and select “Monzo”
  9. In the “Please select” drop-down select “Move money out of a pot”
  10. Under “Amount” leave visibility as “Set by you” and enter a value of 0 this allows the filter code to set the value to save
  11. Scroll back up to “Filter” and click “Add filter code” as per below
Filter Code with explanation
// Get the category for the transaction
var category = Monzo.cardPurchaseAboveAmount.Category

// Check "If"" the purchase category matches our withdrawal category
if ( category == "Shopping" )
{
  // The cateogry matched so we need to format the transaction value
  var transVal = parseFloat(Monzo.cardPurchaseAboveAmount.AmountInAccountCurrency).toFixed(2)
  // Then we tell the "potWithdraw" action to use the formatted value we created
  Monzo.potWithdraw.setAmount(transVal)
} else {
  // The category doesn't match so let's skip the action
  Monzo.potWithdraw.skip()
}

image
This block isn’t strictly necessary but shows how to set a variable and makes the code look a little cleaner. The line starting // is a comment. The variable is set with the command var and here is called “category” but could be called whatever you wish. The Monzo.* string is data from the “Trigger” and the available values can be seen on IFTTT platform below the filter code input window:

Note that for this applet the value used is “Monzo.cardPurchaseAboveAmount.Category” and for transactions under an amount was “Monzo.cardPurchaseBelowAmount.Category” keep this in mind when using filter code that other people have shared but IFTTT does highlight syntax errors:

image

image

This section displays the if block for TypeScript:

if ( 1 = 1 )
  {
   do something(s)
  } else { 
  do something(s) else
  }

In our example the evaluation uses our variable “category” and “==” to do a string comparison ("=" would be used for a numeric comparison). This is the section you would change to set this code up for another category e.g.:

if ( category == "myCategory" )

Once we’ve established that the category does match our desired category then within the {} we specify the value we want to withdraw from a pot and we set it using the values given under the filter code editor (a.k.a. methods).

In our case we saw under the editor that the methods for the withdraw from pot action are:

image

A method is just an instruction to do something and may expect some sort of value to do something with. The editor is very helpful in that you can hover over something to find out whether it needs an input value and what type of value it is or what the syntax is expected to be. So when we hover over setAmount() we see that it expects 1 text (a.ka. string) input within the brackets:

image

If we take our trigger information we can also hover over the relevant input data to see what type of data that is:

So we could just put:

Monzo.potWithdraw.setAmount( Monzo.cardPurchaseAboveAmount.AmountInAccountCurrency )

But there are other situations where you may need to manipulate the value given by the trigger (let’s say you wanted 50% of the spend) and then the value may be a “number” not a “string” and might have mroe than 2 decimal places so for illustration purposes and for consistency I always put the saving value/variable within parseFloat( value ).toFixed(2) to make sure I have “string” value with 2 decimal places.

This variable goes into our setAmount() method so the action knows how much to withdraw.
At the end of the if block we have and else {} so we can tell the withdrawal to skip of the category is not “Shopping”. Again hovering over the method shows no input value is required (the ? shows the input is optional):

image

So knowing all that we could have just made the filter code:

if ( Monzo.cardPurchaseAboveAmount.Category == "Shopping" )
{
  Monzo.potWithdraw.setAmount( Monzo.cardPurchaseAboveAmount.AmountInAccountCurrency )
} else {
  Monzo.potWithdraw.skip()
}

But using the longer form with comments allows easier code reuse and makes it easier for others to use.

4 Likes