Skip to content

C# SDK Configuration

Pawel Sawicz edited this page Oct 28, 2015 · 9 revisions

Using NuGet, install the JustGiving SDK package into your project either from the NuGet GUI or using the PowerShell console:

PM> Install-Package justgiving-sdk

Next, create an instance of the JustGivingClient class passing in your API key obtained from the API Management portal.

var client = new JustGiving.Api.Sdk.JustGivingClient("APIKEY");

By default, this client will make anonymous requests against the JustGiving Production API instance. Initially, you probably want to make requests against the Sandbox instance. This can be configured by passing a ClientConfiguration object to the constructor as follows:

Sandbox
var clientConfig = new Api.Sdk.ClientConfiguration("https://api.sandbox.justgiving.com/", "api-key", 1);
Production
var clientConfig = new Api.Sdk.ClientConfiguration("https://api.justgiving.com/", "api-key", 1);

Replace the api-key string with the API key you obtained earlier. Leave the version number at 1.

Pass this into the JustGivingClient constructor.

var client = new JustGiving.Api.Sdk.JustGivingClient(clientConfig);
Authenticated requests

To make authenticated requests, simply add your username and password to the client instance:

clientConfig.Username = "username";
clientConfig.Password = "password";

Data API

If you want to use the C# SDK against the Data API (not applicable to the standard API above), you can set up a connection configuration in two ways either by entering details into your web.config/app.config or by setting up values directly on the configuration object.

app.config configuration

<configSections>
  <section name="justGivingDataSdk" type="JustGiving.Api.Data.Sdk.Configuration.JustGivingDataSdkConfiguration, JustGiving.Api.Data.Sdk"/>
</configSections>
<justGivingDataSdk CharityId="yourCharityId" RootDomain="environmentAPIUrl" ApiVersion="1" ApiKey="yourAppKey" Username="justgivingUserName" Password="password" />

RootDomain is just the endpoint of the chosen environment (production or sandbox). For example, http://dataapi.justgiving.com/ or http://dataapi.sandbox.justgiving.com/.

Configuration instance

In this case, the RootDomain is passed in as an argument to the constructor.

var dataConfig = new DataClientConfiguration("https://dataapi.sandbox.justgiving.com/", "apiKey", 1);
dataConfig.CharityId = 2050;
dataConfig.Username = "userName";
dataConfig.Password = "password";
var client = new JustGivingDataClient(dataConfig);

This is required to make any request against the Data API.