Skip to content

Instantly share code, notes, and snippets.

View reganstarr's full-sized avatar

Regan Starr reganstarr

View GitHub Profile
<?php
if($_SERVER['REQUEST_METHOD'] != 'POST'){
exit;
}
/*
EXAMPLE:
input.messy_data_from_previous_trigger_or_action = 'This is a single string of text that contains lots of different data. {"name": "John"} Sometimes when you are building a Zap, you will need to pull out one piece of data from a long, messy string of text. {"email": "[email protected]"} Thankfully, you can use the "Formatter by Zapier" app or the "Code by Zapier" app to extract the information you need.'
*/
function extract_piece_of_data(entire_string_of_text, characters_before_desired_data, characters_after_desired_data) {
var desired_data_with_stuff_after_it = entire_string_of_text.substr(entire_string_of_text.indexOf(characters_before_desired_data) + characters_before_desired_data.length);
var username = '';
var password = '';
var encoded_credentials = new Buffer(username + ':' + password).toString('base64');
fetch('https://example.com', { method: 'POST', headers: {'Authorization': 'Basic ' + encoded_credentials} })
.then(function(res) {
return res.json();
})
.then(function(body) {
/*
EXAMPLE:
input.tweetContent = This is a tweet about Zapier that mentions @zapier twice as well as reganstarr.
*/
var commaSeperatedTwitterUsernames = "Zapier,ReganStarr";
// You'll need to change input.tweetContent to match whatever input mapping you defined in the "Input" section of Zapier. (https://zapier.com/help/code/#how-does-it-work)
var tweetContent = input.tweetContent;
/*To get the Trello checklist ID...
1. Open the card that contains the checklist
2. In the right sidebar of the card, click on "Share and more"
3. Click "Export JSON"
4. Select all of that JSON and Copy it to your clipboard
5. Go to http://www.jsoneditoronline.org/
6. Paste in the JSON in the box on the left
7. Click the right arrow [>] button
8. On the right side, scroll down until you see the "checklists" key, then click the arrows to expand that section
9. Use the "name" key find the correct checklist, then copy the "id" value of that checklist
var termsNameArray = input.termsName.split(",");
var termsTaxonomyArray = input.termsTaxonomy.split(",");
for (var i = 0; i < termsNameArray.length; i++) {
if(termsTaxonomyArray[i] !== 'post_tag'){
termsNameArray.splice(i, 1);
}
}
var output = {};
// You can find all three of these in the "Account Details" section of your Cloudinary Dashboard.
var cloudinaryCloudName = "";
var cloudinaryApiKey = "";
var cloudinaryApiSecret = "";
// Upload a semi-transparent PNG file to your Cloudinary account. This semi-transparent image will be used as the watermark. Then, enter the name (Public ID) of that image below. Learn more at http://cloudinary.com/blog/adding_watermarks_credits_badges_and_text_overlays_to_images
var watermarkImageName = "";
var apiUrl = 'ENTER_THE_API_URL_HERE';
var data = JSON.stringify({
"key1": "value1",
"key2": "value2"
});
fetch(apiUrl, {
method: 'POST',
body: data,
var twitterHandle = "";
var bestAvailableImage = "";
if(input.user_twitter_link){
var indexOfLastSlash = input.user_twitter_link.lastIndexOf('/');
twitterHandle = input.user_twitter_link.substring(indexOfLastSlash + 1);
twitterHandle = '(@' + twitterHandle + ')';
}
if(input.hidpi_image){
var string = "This is a string";
var encodedString = new Buffer(string).toString('base64');