Finally, the trigger needs to be tested. Upload an image to the previously selected folder and check if it can be found during the testing step.
After setting up the trigger, we will add an action that compresses the image. Select the TinyPNG app and choose the Compress Image action. Next, connect your API account by filling in your key found on the API dashboard. If you can't find the TinyPNG app, make sure to join the beta first.
When your account was succesfully connected, we need to specify the image that will be compressed. Select the File from step 1, by clicking the Insert button on the right side of the field. Continue to the next step and see if the test is successful.
Finally, we need to add another action that saves the compressed image back to Dropbox. Choose Dropbox as the action app and pick Upload File. Choose the Dropbox account from step 1 and setup the options as follows:
If you correctly filled all the fields you can test the last step and check the file size of the updated image in your Dropbox folder. If everything is working as it should, you can name your Zap and enabled it.
The Zap created in the previous steps will try to compress all your files in the specified folder. As only PNG and JPG files are supported by the API, other file types will generate errors in the execution of the Zap.
To prevent these errors, we can insert a filter step between the trigger and the first action. This filter will make sure the Zap will only try to compress supported files. Configure it to only continue if the File Ext text exactly matches .png
. Click the OR button to create a similar rule for .jpg
and for .jpeg
. After the filter is succesfully tested, don't forget to re-enable the Zap.
Using Zapier we can automate tasks between different web apps and services. Zapier consists of triggers, filters and actions that can be use to build a Zap. For the TinyPNG API, we created an action that allows to compress your images with no programming knowledge required.
In this blog post, we created Zap with this action that monitors a Dropbox folder and compresses newly uploaded images. A very similar approach can be used to integrate the API with other cloud services supported by Zapier, such as Google Drive, OneDrive or Box.