I'm implementing an internal procedure to generate invoices from my database. In using .NET Core
. I installed the Xero.Api.SDK.Core v. 1.1.4
I find the Xero documentation quite difficult to understand and a bit up to date. I took a look to the Github repository and they refer only to OAuth 2.0
. In my case I don't want any user interaction because I want a background process.
I created an account as developer and a demo company for test.
I googled a bit and I found in a site an example how to connect to the api (I couldn't find any details in the Xero documentation).
X509Certificate2 cert = new X509Certificate2(@"public_privatekey.pfx", "password");
var api = new Xero.Api.Example.Applications.Private.PrivateAuthenticator(cert);
var private_app_api = new XeroCoreApi("https://api.xero.com",
new PrivateAuthenticator(cert),
new Consumer("ClientId", "ClientSecret"),
null, null);
Now, I thought, I should use the api. I tried to read the list of contacts:
var contacts = private_app_api.Contacts;
var list = contacts.FindAsync().Result;
The result is the following error:
System.AggregateException: 'One or more errors occurred. (oauth_problem=consumer_key_unknown&oauth_problem_advice=Consumer%20key%20was%20not%20recognised)'
Inner Exception UnauthorizedException: oauth_problem=consumer_key_unknown&oauth_problem_advice=Consumer%20key%20was%20not%20recognised
Then, I downloaded the repository from Github. I copy and paste the ClientId and ClientSecret and run the tests. No one test is passed!
My goal is to create a contact or find one in the list, create an invoice and save the invoice in PDF format in my storage.
How can I do that? Is there any example for that?
PS: In the developer forum the login doesn't work and the Postman collection is old and it doesn't either.
Update
I was desperate. I tried to connect to the apis in another way with XOauth
. Worst. I created the connection as Xero explains on Github.
When I try to connect with
xoauth connect
a new tab in my browser is opened and...
Postman Update
I followed the steps with Postman. I opened the collection in my Postman. In the environment I updated client_id and client_secret from the Xero Developer site and then the following configurations:
re_directURI: https://developer.xero.com
scopes: offline_access profile email accounting.transactions
Auth URL: https://login.xero.com/identity/connect/authorize
Access Token: https://identity.xero.com/connect/token
I opened Get started api, Generate token and I gave the same result.