diff --git a/gc-airtable/gca-create-relation.php b/gc-airtable/gca-create-relation.php new file mode 100644 index 000000000..26f52dcfc --- /dev/null +++ b/gc-airtable/gca-create-relation.php @@ -0,0 +1,66 @@ +get_base_id(); + + $phone_number = rgar( $entry, $gf_phone_number_field_id ); + + if ( empty( $phone_number ) ) { + return; + } + + /** + * TIP: you can easily find the following by creating a new GC Airtable feed, connecting + * it to the "Phone Numbers" table and saving. If you open the developer console in your + * browser and refresh the page, a table of all the fields in the table will be logged. + */ + $phone_field_id = 'TODO'; // The ID of the phone number field in the Phone Numbers table. + $link_field_id = 'TODO'; // The ID of the link field in the Phone Numbers table. + + $records = array( + array( + 'fields' => array( + $phone_field_id => $phone_number, + $link_field_id => array( $create_record_resp['id'] ), + ), + ), + ); + + try { + $airtable_api = $gca_connection_instance->get_airtable_api(); + $create_record_resp = $airtable_api->create_records( $base_id, $table_id, $records ); + } catch ( Exception $e ) { + $msg = gca_get_exception_message( $e ); + gc_airtable()->log_error( $msg ); + } +}, 10, 3 );