Welcome back to MSPTutorials, my tech and non-tech friends!
So you’re on a mission to delete a volunteer record via the MSP REST API. Don’t worry, I’ve got your back!
But before we start coding, be sure you have reviewed and adhered to the requirements on the “Getting Started” page.
Let’s kick things off with PHP first and then sail smoothly or slither into the Python waters (see what I did there!). 😎
Ready? Let’s set sail and delete those records!
Overview of the Volunteers Collection
We all know that volunteers are the very heartbeat of every organization. One of the most accessed collections of the MSP REST API is the volunteers. To access its data, the Volunteers collection consists of the following endpoints:
- CREATE uses this endpoint, /volunteers, which allows API requests to create a single volunteer record.
- GET uses this endpoint, /volunteers/{volunteerId}, which allows API requests to retrieve and access a single volunteer record based on the unique volunteer’s MSP ID.
- PUT uses this endpoint, /volunteers/{volunteerId}, which allows API requests to access and update a single volunteer record based on the unique volunteer’s MSP ID.
- DELETE uses this endpoint, /volunteers/{volunteerId}, which allows API requests to access and delete a single volunteer record based on the unique volunteer’s MSP ID.
- POST uses this endpoint, /volunteers/list, which allows API requests to retrieve and access a list of volunteer records.
There are nearly 30+ Volunteer properties to consider (see codebase below or MSP REST API documentation) when accessing the Volunteers collection.
In this tutorial, we’ll focus our efforts on mastering the DELETE endpoint of the Volunteers collection.
In addition, I’ll provide in their entirety the code base for both PHP and Python without much explanation. Review the CREATE and GET endpoints if you would like a detailed breakdown and explanation of each codebase.
I know you’re eager to get started, so let’s dive in and explore the world of deleting a volunteer record using MSP REST API without further ado.
How to delete a volunteer record using PHP.
Using the volunteers’ DELETE endpoint, deleting a volunteer record via MSP REST API using PHP resembles the API call that uses the volunteers GET endpoint.
The only change in the codebase is cURL’s curl_setopt option of CURLOPT_CUSTOMREQUEST. Instead of ‘GET,’ the CURLOPT_CUSTOMREQUEST should be set to ‘DELETE.’ That’s it!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
<?php /*********************************** **** **** delete_volunteer.php **** **** This file allows for authentication using your MSP API Key and deleting a volunteer record by volunteer id. **** ***********************************/ // define MSP API variables $mspApiKey = 'Enter key area'; // Your MSP API Key $apiBaseUrl = "https://api.ministryschedulerpro.com/2/"; // MSP API base URL $volunteerID = 31; // MSP Volunteer Unique Record ID for the person you want to delete $endPoint = 'volunteers/'.$volunteerID; // MSP API Endpoint // If the endpoint is not defined and still equals the default of `Enter API Endpoint`, then create an empty $endpoint variable. if ($endPoint == "Enter API Endpoint") { $endPoint = ''; } $url = $apiBaseUrl.$endPoint; // Set your MSP API Key. Also uncomment the content type if you are attempting to instantiate a request using an MSP API endpoint. $header = array( "Authorization: Bearer $mspApiKey", "Content-Type: application/json" ); // Time to initiate cURL request using MSP API variables $ch = curl_init(); $timeout = 60; // Set the URL and other options for curl curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); // Values: GET, POST, PUT, DELETE, PATCH, UPDATE //curl_setopt($ch, CURLOPT_POSTFIELDS, $postData); // Uncomment if you are using MSP API endpoint query parameters -- see lines 24-30 // curl_setopt($ch, CURLOPT_POST, true); // Uncomment if the previous line is uncommented. ;) curl_setopt($ch, CURLOPT_HTTPHEADER, $header); // Execute call and return response data. $result = curl_exec($ch); // Close the cURL connection curl_close($ch); // Decode the JSON response $rez = json_decode($result, true); var_dump($rez); ?> |
How to delete a volunteer record using Python.
Now, let’s dive into the Python version. Python is just as powerful, so let’s see how to achieve the same result.
Using the volunteers’ DELETE endpoint, deleting a volunteer record via MSP REST API using Python resembles the API call that uses the volunteers GET endpoint.
Here’s the code for how to delete a volunteer record via MSP REST API using Python:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
import requests # Define MSP API variables mspApiKey = 'Enter key area' # Your MSP API Key apiBaseUrl = "https://api.ministryschedulerpro.com/2/" # MSP API base URL volunteerID = 31 # MSP Volunteer Unique Record ID for the person you want to delete endPoint = f'volunteers/{volunteerID}' # MSP API Endpoint # Set your MSP API Key header = { "Authorization": "Bearer {mspApiKey}", "Content-Type": "application/json" } # Construct the URL url = apiBaseUrl + endPoint # Send the DELETE request response = requests.delete(url, headers=header) # Print the response print(response.json()) |
Tutorial Summary
Congratulations! You now have the power to delete volunteer records like a pro using either PHP or Python.
Choose your preferred language, follow the instructions, and let the records vanish into thin air—in the best sentiment! Remember, no matter which language you choose, the end result matters most.
In addition, refer to the MSP API documentation for more advanced functionalities and options. Feel free to reach out if you have any questions or encounter technical roadblocks along the way.
Oh, and one last thing: don’t forget to add error handling to your code, especially since this is a delete operation.
Well, that’s all for today. Happy coding, and may your volunteer records be deleted swiftly and securely!