iAuditor users often want to receive an email if an audit contains one or more responses designated by the template author to be a “failed response.” This page will show you how to set up this workflow using Zapier.
We’ll assume we want to send a PDF report for any audit with a failed response that is conducted from a specific template. The first step is to register for a free or paid Zapier account. For help on getting started with Zapier, please see our Zapier Integrations article. Once you have a Zapier account, log in and select “Make A Zap!” You’ll be taken to a blank Zap template to select a trigger app. Type in “iAuditor” in the search box.
We want to set this Zap to trigger only on a specific template, so we select “Audit Completion” as the trigger. If we wanted this Zap to trigger any time any audit is conducted, we would select “Any Audit Completion” instead. Click “Save+Continue.”
Now associate your SafetyCulture account with Zapier by clicking “Connect a New Account.”
A separate window will pop up prompting you to enter in the API token. If you have already generated a token, input it in the text field and click “Yes, Continue”. If you do not have an API Token, you can follow this guide to generate an API token. Input your API Access Token into Zapier and click “Yes, Continue.”
“Test” your account to ensure connectivity.
“Save + Continue” takes us to the “Set Up Options” step, where we select our target template. Select the template you want to work with and hit “Continue.” Provided you have recently conducted an audit from this template, “Fetch and Continue” will complete the trigger setup.
For this workflow, the first Action required is Code by Zapier
Select “Run Python”, then “Save + Continue.” To configure the input data, type ‘audit_id’ in the first Input Data field (exactly as shown, any deviation from this will cause an error), and select the Audit ID value from the drop-down on the right column, as shown.
We have provided a simple example script to help you get started here and encourage you to modify it for your own needs. Delete the code that is pre-filled in the “Code” section of the Zap, and copy and paste the following script in its place:
Next, we’ll create an action to send an email. In this example, we’ll use Gmail to send an email, however, there are a number of email platforms that can be used within Zapier.You’ll notice the field “YOUR_SAFETYCULTURE_API_TOKEN” is not filled out. Replace this with your actual token, which we obtained in a previous step. Make sure you leave a space between the word Bearer and your API token.
For the next action, choose the ‘Filter’
Select the ‘Only continue if…’ option
Next, we’ll take the output from the ‘Code by Zapier’ step, to decide whether the Zap will proceed or not. If the ‘Code by Zapier’ step returned the value True (this indicates there was at least 1 failed response) the Zap should proceed with emailing an audit report, otherwise, it can stop now without further action. Fill out the option as shown below, then test this step and continue.
Now we need to configure the resulting Action if we are to proceed. Search for ‘iAuditor’ and select the ‘Prepare Audit Report’ Action. This will allow you to create a PDF or Word Document from the Audit that contains failed responses. In this example, we’ll create a PDF report.
Configure the Audit Export details and click ‘Continue’:
- Audit ID: The unique ID of the Audit – Select the Audit ID from the recently completed Audit.
- Document Type: The type of report to generate, either a PDF or Word document.
- Export Profile (optional): Apply a previously created Export Profile to the Audit to make sure the report appearance remains consistent.
- Timezone (optional): Choose the Olson timezone or use a custom value to convert dates and times to within the report. This option defaults to GMT/UTC when left unselected.
Click ‘Create + Continue’ to complete the Action. If the test is successful you will be notified and you can continue onto the next step by clicking ‘Add a step’.
Next, search for the Action ‘Delay by Zapier’. This allows you to set a timed delay in your workflow. In this case, the delay needs to be put in place to ensure iAuditor has enough time to fully generate the Audit Report. This is a critical requirement for the Zap to work correctly. If omitted, all exports will fail. Select the ‘Delay For’ option followed by ‘Save + Continue’.
Add ‘10’ to the ‘Time Delayed For (value)’ field and ‘Minutes’ to the ‘Time Delayed For (unit)’. Click ‘Continue’.
Click ‘Create + Continue’ to complete the Delay Action in your workflow. If the test is successful you will be notified and you can continue onto the next step by clicking ‘Add a step’.
Search for iAuditor and select the ‘Get Audit Report’ which retrieves an Audit report that has already been prepared. Click ‘Save + Continue’.
To validate the account, pick your iAuditor account from the next page. Click ‘Save + Continue’
Configure the Audit Export details and click ‘Continue’:
- Audit ID: The unique ID of the Audit – Select the Audit ID from the recently completed Audit
- Export Task ID: The unique export task ID which is created during the ‘Prepare Audit Report’ Action
Click ‘Create + Continue’ to complete the ‘Get Audit Report’ Action in your workflow. If the test is successful you will be notified and you can continue onto the final step by clicking ‘Add a step’.
Select a recipient, email subject, and fill in the body. You can use audit properties from the initial trigger in the subject and body of the email.
In the attachment field of the email, select the audit report from the ‘Get Audit Report’ Action
Lastly, name the Zap and make sure it is turned on.
If everything is set up correctly, you will start receiving emails with an attached audit report anytime an audit is completed with at least one failed response.