teamraiser stuff in typescript

To interact with TeamRaiser API using TypeScript, you will need to:

  1. Install request-promise package to make API requests and @types/request-promise to have type definitions for the package installed.
index.ts
npm install request-promise @types/request-promise
51 chars
2 lines
  1. Create a module to handle API requests. Here is an example using the request-promise package:
index.ts
import rp from 'request-promise';

interface TeamRaiserConfig {
  apiKey: string;
  apiUrl: string;
}

export default class TeamRaiserAPI {
  private apiKey: string;
  private apiUrl: string;

  constructor(config: TeamRaiserConfig) {
    this.apiKey = config.apiKey;
    this.apiUrl = config.apiUrl;
  }

  getTeam(teamId: number): Promise<any> {
    const options = {
      method: 'GET',
      uri: `${this.apiUrl}/rest/tr/${this.apiKey}/team/${teamId}`,
      json: true
    };

    return rp(options);
  }

  createTeam(teamData: any): Promise<any> {
    const options = {
      method: 'POST',
      uri: `${this.apiUrl}/rest/tr/${this.apiKey}/team`,
      body: teamData,
      json: true
    };

    return rp(options);
  }
}
734 chars
38 lines
  1. Instantiate the TeamRaiserAPI class with the required configuration data (API key and URL), and then use the methods to interact with the TeamRaiser API.
index.ts
const teamRaiserConfig = {
  apiKey: '<YOUR_API_KEY>',
  apiUrl: 'https://secure.e2rm.com/registrant/api'
};

const teamRaiserAPI = new TeamRaiserAPI(teamRaiserConfig);

teamRaiserAPI.getTeam(123)
  .then((teamData) => {
    console.log(teamData);
  })
  .catch((error) => {
    console.error(error);
  });
307 chars
15 lines

This example shows how to retrieve a team's data by ID, but you can replace getTeam() with any other TeamRaiser API endpoint and method available to interact with the API.

gistlibby LogSnag