Skip to content

Instantly share code, notes, and snippets.

@mariovalney
Created October 20, 2020 12:11
Show Gist options
  • Save mariovalney/7dc48fefa8bed30e102657f509a006ac to your computer and use it in GitHub Desktop.
Save mariovalney/7dc48fefa8bed30e102657f509a006ac to your computer and use it in GitHub Desktop.
Send webhook to Airtable API
<?php
/**
*
* Plugin Name: CF7 to Webhook - Airtable
* Description: Send webhook to Airtable API
* Version: 1.0.0
* Author: Mário Valney
* Author URI: https://mariovalney.com
* Text Domain: cf7-to-webhook-air-table
*/
add_filter( 'ctz_post_request_args', 'ctwat_post_request_args' );
/**
* Change the post request to send data to Airtable API
*
* @see https://youtu.be/snl_OQbm3UI?t=631
* @see https://developer.wordpress.org/reference/functions/wp_remote_post/
*
* @param $args array
* @return $args
*/
function ctwat_post_request_args( $args ) {
$args['headers']['Authorization'] = 'Bearer YOUR_TOKEN_HERE';
$body = json_decode( $args['body'] );
$body = array(
'records' => array(
array(
'fields' => $body,
),
),
);
$args['body'] = json_encode( $body );
return $args;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment