NewPath-Consulting / warm

Pro Reports for Wild Apricot is a Google Data Studio connector that helps Wild Apricot administrators understand your organization’s membership engagement, renewal rates, and demographics. Trend your revenue and get expense analyses. Whatever your question, enjoy all the organized data you need at your fingertips to make the business decisions want.
https://newpathconsulting.com/warm
GNU General Public License v3.0
5 stars 4 forks source link

Integrate a User-Agent into the fetchAPI call #78

Closed asirota closed 4 years ago

asirota commented 4 years ago

In order for Wild Apricot's infrastructure team to know when our connector is using their resources they asked us to integrate a custom User-Agent into our fetchAPI call. I suggest adding a header called User-Agent with the value WARM / 2.1 (DEV) Wild Apricot Reports Manager to be sent for all our API calls to Wild Apricot

function fetchAPI(url, token) {
  // HTTP request
  try {
    var responseJSON = UrlFetchApp.fetch(url, {
      method: "GET",
      headers: { Authorization: "Bearer " + token, "User-Agent": "WARM / 2.1 (DEV) Wild Apricot Reports Manager" },
      accept: "application/json"
    });
    return JSON.parse(responseJSON);
  } catch (e) {
    DataStudioApp.createCommunityConnector()
      .newUserError()
      .setDebugText("DBG: Failed to fetch data from API: " + e)
      .setText("Wild Apricot API returned an error: " + e)
      .throwException();
  }
}
asirota commented 4 years ago

this has been added in v2.1