How to obtain xero_tenant_id ?
zkid18 opened this issue · 5 comments
I'm not interested in creating the complex Xero app but simply need to
app = Flask(__name__)
if app.config["ENV"] != "production":
# allow oauth2 loop to run over http (used for local testing only)
os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "1"
# configure persistent session cache
Session(app)
# configure flask-oauthlib application
oauth = OAuth(app)
xero = oauth.remote_app(
name="xero",
version="2",
client_id="CLIENT_ID",
client_secret="CLIENT_SECRET",
endpoint_url="https://api.xero.com/",
authorization_url="https://login.xero.com/identity/connect/authorize",
access_token_url="https://identity.xero.com/connect/token",
refresh_token_url="https://identity.xero.com/connect/token",
scope="offline_access openid profile email accounting.transactions "
"accounting.transactions.read accounting.reports.read "
"accounting.journals.read accounting.settings accounting.settings.read "
"accounting.contacts accounting.contacts.read accounting.attachments "
"accounting.attachments.read assets projects "
"files "
"payroll.employees payroll.payruns payroll.payslip payroll.timesheets payroll.settings",
api_client = ApiClient(
Configuration(
oauth2_token=OAuth2Token(
client_id="CLIENT_ID", client_secret="CLIENT_SECRET"
),
),
pool_threads=1,
)
)
accounting_api = AccountingApi(api_client)
So in that setup how can I obtain the xero_tenant_id
so I can pass it over to the following request?
accounting_api.get_online_invoice("xero_tenant_id", "invoice_id")
Hi @zkid18 can you clarify your use case so I can best assist you? It sounds like maybe you want to build an integration without a UI?
@RettBehrens yes, that's correct. I don't need UI, just to get Online Invoice based on Invoice id
Ah, ok. You'll need to use custom connections to circumvent UI-based user auth/consent with the client_credentials grant.
Here's the python sample app for custom connections.
More details on custom connections from our docs.
@RettBehrens ok, but it seems that it works only with apps created via Custome connections.
Unfortunately, we're neither UK, Australian nor New Zealand Company.
All Xero APIs require apps to operate on behalf of a user. Connecting your app to a Xero account requires a user to grant consent in a web browser. This can be challenging if you’re building a back-end integration that doesn’t have a user interface. Custom Connections solved this by moving the auth/consent to an email to the user.
It's true, Custom Connections is currently only available for AU, NZ, and UK regions. The other option is to use XOAuth to obtain tokenset, store tokenset in your application db and run scheduled job to refresh tokens with your application.
Our CLI tool XOAuth allows you to establish an offline connection with a Xero user’s account directly from the command line. No web development required.