Action

Zapier: Catch Hook with Hard Coded URL

Posted by agiletortoise, Last update over 5 years ago

Example script demonstrates how to trigger a Zap at Zapier.com which has a “Catch Hook” trigger. Change the “hookURL” variable and “data” passed as needed.

This example will not work unless the hookURL variable at the top of the script is changed to a valid Catch Hook URL. The data variable can also be changed to pass other values to the Catch Hook if desired. By default it will send “title”, “body”, and “content” value which can be used in the Zap action.

Steps

  • script

    // Set to Webhook URL for a Zap
    // With a "Catch Hook" trigger type
    // This can be copied from Zapier.com dashboard
    var hookURL = "https://hooks.zapier.com/SET-TO-YOUR-ZAP-URL";
    
    // Setup data you want passed to the Zap
    // Default pass title, body and full content of draft
    // Other values could be passed
    var data = {
    	"title": draft.title,
    	"body": draft.processTemplate("[[body]]"),
    	"content": draft.content
    }
    
    // create HTTP and make POST request to Catch Hook
    var http = HTTP.create();
    var response = http.request({
      "url": hookURL,
      "method": "POST",
      "data": data,
      "headers": {
        "Accept": "application/json"
      }
    });
    
    // log result
    console.log(response.statusCode);
    console.log(response.responseText);
    
    // if not 200 OK, fail the action
    // Otherwise Zapier successfully received post
    if (response.statusCode != 200) {
    	context.fail();
    }

Options

  • After Success Default
    Notification Info
    Log Level Info
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.