Most popular Applets

Filter code cheat sheet

By The IFTTT Team

March 21, 2022

Filter code cheat sheet
  • Filter code is one of the most powerful features on IFTTT because it gives you the ability to add conditional logic that determines the result of your Applet’s action. You have the ability to skip or modify the resulting event based on the code that you add. You can write your own filter code, use our generators, or look at online resources to find code that suits your needs. We have created a helpful guide to make it easy to copy and paste the filter code that you want.

    Remember to include the elements from the services you are using. Many of these examples have filter code for actions or services as examples. Within the filter code editor, you will be able to see the options for the services you have already included in the Applet itself. Simply scroll and you will see the available Trigger data, actions, and other. You can also use your current time and days of the week as an element of your filder code.

    If you haven’t already, you can also check out our filter code generators here.

    Skip during certain hours

    Use this code when you only want your Applet to run during certain hours of the day. This is very popular when you want to skip an action at night or when you are asleep.

    let currentHour = Meta.currentUserTime.hour();
    
    if (currentHour < 9 || currentHour >= 23) {
      Email.sendMeEmail.skip(`It's ${currentHour}, only running between 9am and 11pm`);
       // You can pass a message to skip() and it will be recorded in the Applet's
       // activity feed when an action is skipped. This is useful for debugging.
    }
    

    Run every second week

    Use this code for Applets that should only run every second week.

    // Filter code to check the week number and if the week number is odd,
    // the actions will be skipped.
    // This code makes use of the moment.js function moment().week()
    // which returns the current week number in the number format.
    
    let thisWeek = Meta.currentUserTime.week();
    
    //Change 0 to 1 to make it run on odd weeks instead
    if (thisWeek % 2 != 0) {
    IfNotifications.sendNotification.skip(`Only running on even weeks. Week number ${thisWeek}`);
    }
    

    Run based on temperature

    This filter code can skip an action if the data from your trigger is different from a certain number. In this example, the filter code uses the local temperature to determine if the Applet will run.

    let currentTemp = Number(Weather.currentTemperatureRisesAbove.TempFahrenheit);
    
    if (currentTemp < 90 && currentTemp > 75) {
    Sms.sendMeText.skip(`Temperature is ${currentTemp}`);
    }
    
    else if (currentTemp <= 75) {
    IfNotifications.sendNotification.skip(`Temperature is ${currentTemp}`);
    Sms.sendMeText.skip(`Temperature is ${currentTemp}`);
    }
    

    Skip based on keyword

    This filter code can skip an action if the data from your trigger does not match a specific keyword based on a search.

    let str = GoogleCalendar.anyEventStarts.Description;
    let searchTerm = 'IFTTT';
    let indexOfFirst = str.indexOf(searchTerm);
    
    if (indexOfFirst === -1) {
    IfNotifications.sendNotification.skip("Not found!")
    }
    

    Only after sunset

    The sunrise or sunset option is one of the most popular filter code use cases, because it makes it possible to control your Applets based on the light in your area. Use this code with the Sunrise/Sunset survive as a query element.

    let sunrise = moment(Weather.currentWeather[0].SunriseAt);
    let sunset = moment(Weather.currentWeather[0].SunsetAt);
    let currentTime = Meta.currentUserTime;
    
    let afterSunrise = currentTime.isAfter(sunrise);
    let beforeSunset = currentTime.isBefore(sunset);
    
    if (afterSunrise && beforeSunset) {
    IfNotifications.sendNotification.skip
    (`ISS appears overhead for ${Space.spaceStationOverheadSoonNasa.DurationSeconds}
    seconds, but you won't see it while the sun is up`)
    }
    

    Only on some days of the week

    Only want to run your Applets on certain days of the week? No problem, just use this code. let day = Meta.currentUserTime.day()

    if (day === 0 || day === 6) {
    // Add the action you want to skip inside these curly braces
    }
    

    Skip image

    If you are using IFTTT to cross-post your content across platforms, use this filter code to skip the image URL if there is no picture associated with the content. This will ensure that you do not get the image not found error that can accompany tweets that are missing an image.

    let imageURL = Tumblr.newAnyPost.PostImageUrl;
    let noImage = 'no_image_card.png';
    
    if ( imageURL.indexOf(noImage) !== -1 ) { 
    Twitter.postNewTweetWithImage.skip();
    }
    

    Feeling inspired?

    If you’re ready to dive in, create your own Applet using filter code!

    Create Applets Button