3

After successfully establishing OAuth2 connection to Xero, call to https://api.xero.com/connections is giving only the id, tenant id and type.

How to get the name (display name) of the connections?

Tried calling Organizations API. It does not work in OAuth2

var url = "https://api.xero.com/connections";

  //var response = service.fetch(url, {
  var response = UrlFetchApp.fetch(url, {
    headers: {
      'Content-Type': 'application/json',
      'Authorization': 'Bearer ' + service.getAccessToken(),
    },
    muteHttpExceptions : true
  });

There is no way of getting connection names and showing it to end-user to choose. (It makes no sense to ask the user to choose from the list of cryptic ids).

Michaes
  • 73
  • 6

1 Answers1

3

You should retrieve each organisation from the /organisation endpoint, with the appropriate tenantId as the value in the xero-tenant-id header:

https://api.xero.com/api.xro/2.0/organisation

This works with both OAuth1.0a and OAuth2 (note the 's' rather than the 'z' in the endpoint).

rustyskates
  • 856
  • 4
  • 10
  • 3
    Also, be sure to ask for the 'accounting.settings.read' scope to be able to access the GET /Organisation endpoint – MJMortimer Aug 21 '19 at 08:24
  • Thanks @rustyskates for this information. Call to /organisation works for single tenant id. So if there are 20 connections returned from https://api.xero.com/connections, just to get the name of the org, do we need to make 20 API calls? – Michaes Aug 27 '19 at 09:34