Created
October 20, 2020 12:11
-
-
Save mariovalney/7dc48fefa8bed30e102657f509a006ac to your computer and use it in GitHub Desktop.
Send webhook to Airtable API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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