iAuditor users often want to receive an email if an inspection (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 inspection (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.

Part 1: Setup trigger from iAuditor

  1. Log in and select “Make A Zap!”
  2. You’ll be taken to a blank Zap template to select a trigger app.
  3.  Type in “iAuditor” in the search box.
  4. We want to set this Zap to trigger only on a specific template, so we select “Audit Completion” as the trigger.
  5. If we wanted this Zap to trigger any time an audit is conducted, we would select “Any Audit Completion” instead.
  6. Click “Save+Continue.”
  7. Now associate your iAuditor account with Zapier by clicking “Connect a New Account.”
  8. A separate window will pop up prompting you to enter in the API token.
  9. Input your API Access Token into Zapier.  If you do not have an API Token, you can follow this guide to generate an API token.
  10. Click “Yes, Continue.”
  11. “Test” your account to ensure connectivity.
  12. “Save + Continue” takes us to the “Set Up Options” step, where we select our target template.
  13. Select the template you want to work with and hit “Continue.”
  14. “Fetch and Continue” will complete the trigger setup. Note: This only works if you have recently conducted an inspection (audit) from this template
  15. For this workflow, the first Action required is “Code by Zapier”
  16. Select “Run Python”, then “Save + Continue.”
  17. 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)
  18. Select the Audit ID value from the drop-down on the right column, as shown
  19. We have provided a simple example script to help you get started here and encourage you to modify it for your own needs.
  20. Delete the code that is pre-filled in the “Code” section of the Zap, and copy and paste the following script in its place:
import requests

auth_header = {'Authorization': 'Bearer YOUR_SAFETYCULTURE_API_TOKEN'} 
api_url = 'https://api.safetyculture.io/audits/' 
audit_id = input['audit_id'] 
audit_doc = requests.get(api_url + audit_id, headers=auth_header).json()

for item in audit_doc['items']:     
    if item.get('responses') and item['responses'].get('failed') == True:        return{'proceed': True}

return{'proceed': False}

Part 2: Setup action to send email

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.

  1. Replace“YOUR_SAFETYCULTURE_API_TOKEN” with your account’s API token, which we obtained in a previous step.
  2. Make sure you leave a space between the word “Bearer” and your API token.
  3. For the next action, choose the “Filter”
  4. Select the “Only continue if” option
  5. Take the output from the “Code by Zapier” step, to decide whether the Zap will proceed or not.
  6. If the “Code by Zapier” step returned the value True (this indicates there was at least 1 failed response) the Zap should proceed and email an inspection report, otherwise, it can stop now without further action.
  7. Fill out the option as shown below, then test this step and continue.
  8. Now we need to configure the resulting Action if we are to proceed. Search for ‘iAuditor’ and select the “Prepare Audit Report” Action.
  9. 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.
  10. Configure the Audit Export details and click “Continue”
  11. Audit ID: The unique ID of the Audit – Select the Audit ID from the recently completed Audit.
  12. Document Type: The type of report to generate, either a PDF or Word document.
  13. Export Profile (optional): Leave blank
  14. Timezone (optional): Choose an 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.
  15. Click “Create + Continue” to complete the Action.
  16. If the test is successful you will be notified and you can continue onto the next step by clicking “Add a step.”
  17. Next, search for the Action “Delay by Zapier.”
  18. 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 inspection report.
  19. This is a critical requirement for the Zap to work correctly. If omitted, all exports will fail.
  20. Select the “Delay For” option
  21. Save + Continue
  22. Add “10’” to the ‘Time Delayed For (value)” field and “Minutes” to the ‘Time Delayed For (unit)”
  23. Click Continue
  24. Click “Create + Continue” to complete the Delay Action in your workflow.
  25. If the test is successful you will be notified and you can continue onto the next step by clicking “Add a step”
  26. Search for iAuditor and select the “Get Audit Report” which retrieves an inspection report that has already been prepared.
  27. Save + Continue
  28. To validate the account, pick your iAuditor account from the next page, and “Save+Continue”
  29. Configure the inspection (audit) Export details and click continue.
  30. Audit ID: The unique ID of the inspection (audit) – Select the Audit ID from the recently completed inspection (audit)
  31. Export Task ID: The unique export task ID which is created during the “Prepare Audit Report” Action
  32. Click ‘Create + Continue’ to complete the “Get Audit Report” Action in your workflow.
  33. If the test is successful you will be notified and you can continue onto the final step by clicking “Add a step”
  34. 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.
  35. In the attachment field of the email, select the inspection (audit) report from the ‘Get Audit Report’ Action
Was this article helpful?

We love your feedback. Please tell us what you think.

Yes No
Care to share a bit more so we can continue to make improvements for you? Care to share a bit more so we can make this article even better for you? Thanks for your feedback!