PHP code example of smadeira / ministry-platform-api
1. Go to this page and download the library: Download smadeira/ministry-platform-api library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
smadeira / ministry-platform-api example snippets
use MinistryPlatformAPI\MinistryPlatformTableAPI as MP;
use MinistryPlatformAPI\MinistryPlatformProcAPI as PROC;
// Get environment variables
$dotenv = Dotenv\Dotenv::createUnsafeImmutable(__DIR__);
$dotenv->load();
// For the Table API enpoints
$mp = new MP();
$mp->authenticate();
// For the Procedures API endpoint
$proc = new PROC();
$mp->authenticate();
// Get all Approved events happening in the next 30 days that are not cancelled and order by the Event Start Date
$events = $mp->table('Events')
->select("Event_ID, Event_Title, Event_Start_Date, Meeting_Instructions, Event_End_Date, Location_ID_Table.[Location_Name], dp_fileUniqueId AS Image_ID")
->filter('Events.Event_Start_Date between getdate() and dateadd(day, 30, getdate()) AND Featured_On_Calendar = 1 AND Events.[_Approved] = 1 AND ISNULL(Events.[Cancelled], 0) = 0')
->orderBy('Event_Start_Date')
->get();
print_r($events);
inistryPlatformAPI\MinistryPlatformTableAPI as MP;
// Get environment variables
$dotenv = Dotenv\Dotenv::createUnsafeImmutable(__DIR__);
$dotenv->load();
// Attempt to authenticate to the MP API
$mp = new MP();
$mp->authenticate();
$events = $mp->table('Events')
->select("Event_ID, Event_Title, Event_Start_Date, Meeting_Instructions, Event_End_Date, Location_ID_Table.[Location_Name], dp_fileUniqueId AS Image_ID")
->filter('Events.Event_Start_Date between getdate() and dateadd(day, 30, getdate()) AND Featured_On_Calendar = 1 AND Events.[_Approved] = 1 AND ISNULL(Events.[Cancelled], 0) = 0')
->orderBy('Event_Start_Date')
->get();
print_r($events);
inistryPlatformAPI\MinistryPlatformProcAPI as PROC;
// Get environment variables
$dotenv = Dotenv\Dotenv::createUnsafeImmutable(__DIR__);
$dotenv->load();
// Attempt to authenticate to the MP API
$mp = new PROC();
$mp->authenticate();
$input = ['@SelectionID' => 26918];
$contacts = $mp->proc('api_MYGCC_PCOGetSelectedContacts')
->procInput($input)
->exec();
print_r($contacts);
use MinistryPlatformAPI\MinistryPlatformFileAPI as MP;
// Get environment variables
$dotenv = Dotenv\Dotenv::createUnsafeImmutable(__DIR__);
$dotenv->load();
// Get metadata for the file(s) based on table and record id
$fm = $mp->table('Contacts')->recordID(55309)->get();
$metadata = json_decode($fm, true);
print_r($metadata);
// Get metadata for the file(s) based on table and record id
$fm = $mp->table('Contacts')->recordID(55309)->get();
$metadata = json_decode($fm, true);
// Loop through the metadata and retrieve each file
foreach ($metadata as $fileData) {
echo 'Saving file: ' . $fileData['FileName'] . "\n";
$fileID = $fileData['FileId'];
$file = $mp->fileID($fileID)->get();
$outfile = 'D:/Temp/' . $fileData['FileName'];
file_put_contents($outfile, $file);
}