Building a Charity Search App in C# Using the OrgHunter Charity API
Learn how to use the OrgHunter Charity API to build a C# app that searches for charities by name, city, or state, with easy setup and integration steps.
Here’s a guide on how to use the OrgHunter Charity API to create a C# charity search application:
Step-by-Step Guide
- Get an API Key: Sign up at OrgHunter Charity API to obtain your API key, required for accessing the API.
- Set Up the Project:
- Open Visual Studio and create a new Console Application.
- Add
System.Net.Http
for HTTP requests.
- Create the Charity Search Function: Define a function to send a POST request to the API endpoint:
using System;
using System.Net.Http;
using System.Threading.Tasks;
namespace CharitySearchApp
{
class Program
{
private static async Task SearchCharities(string searchTerm)
{
string apiKey = "yourKey";
string url = $"http://data.orghunter.com/v1/charitysearch?user_key={apiKey}&searchTerm={searchTerm}";
using (HttpClient client = new HttpClient())
{
HttpResponseMessage response = await client.PostAsync(url, null);
if (response.IsSuccessStatusCode)
{
string responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseBody);
}
else
{
Console.WriteLine($"Error: {response.StatusCode}");
}
}
}
static async Task Main(string[] args)
{
await SearchCharities("humane society");
}
}
}
- Test the Application:
- Run the application and view the output.
- Modify parameters like
searchTerm
,city
, andstate
for different searches.
This basic implementation demonstrates how to call the OrgHunter Charity API in C#. For detailed parameter options, visit the Charity API Search Documentation.