OAuth2 to connect to Xero API

I’m wrestling with the Xero API but hit an early problem. I’ve successfully connected to it using Postman and have retrieved an invoice record successfully there. I’ve copied all the credentials into my Server Connect actions but it’s giving me a 500 error:

Error: unauthorized_client : Unknown client or client not enabled

I’ve set up my Action Steps like this:

Screenshot 2020-05-06 at 22.33.31

These are all the details:

I was expecting to be taken to the Xero login page to log in and get the various credentials but I just get the error mentioned above.

Can anyone offer any help for me?

Are you calling this server action directly, rather than through app connect? I believe you need a direct link to

http(s)://YOUR-DOMAIN/dmxConnect/api/PATH_TO_YOUR_PHP_FILE.php

Hi @mebeingken

Yes, initially I did it through app connect and the console showed it stuck at the API stage with status ‘pending’ so I then browsed directly to the .php file and that’s what gave me the Xero page showing:

Error: unauthorized_client : Unknown client or client not enabled

If you manage to get this working @sitestreet please post a step by step guide.
I gave up trying to get OAuth2 Server Connect and Xero working.
I managed to call the login to my Xero tenant, but was struggling with redirect_uri and retrieving contacts

Where are you seeing this? On xero side, or when u open the server action file? I see you have enabled ssl verify, so is the action file opening as https?

Hi @Akayy

I’m running the Server Connect script directly via the /dmxConnect/api/… URL and I then see this on Xero when I was expecting to get the login form.

Yep, would be happy to do that. Got to get it working first!

In the xero URL you are directed to, is this well-formed like this (source):

You might want to put the URL into a URL decoder online to decode it…

https://login.xero.com/identity/connect/authorize?response_type=code&client_id=YOURCLIENTID&redirect_uri=YOURREDIRECTURI&scope=openid profile email accounting.transactions&state=123

I will probably check specifically if the redirect_uri is correct with https.

Wahey! I have it working! I tried so many different things, I’m not actually sure what fixed it. I am now onto the next bit in the process and once I have that all working, I’ll try and post a how-to.

3 Likes

Hey @sitestreet ,
I hope you are keeping well.
Did you manage to get Xero integration up and running.
I never did quite get anywhere with it and just revisited it with no success.
Would love to see a guide on how to get Wappler connected with Xero.

Thanks in advance.

Sorry for the delay in replying, @mimuk. Yes, I have it fully working. Let me know where you’re stuck (PM is fine) and I’ll see if I can help.

Hi @sitestreet
Thanks for offering to help
I dont even get as far as authenticating.

Error code: 500
Error: invalid_scope : Invalid scope 

I’ve just done some comparisons with the site I built and the Client Id and Client Secret fields in the OAuth2 Provider needs to be completed. I’m trying to remember where I got these from but must be in the Xero account.

Have you used Postman at all? It used to be a browser plugin but is now a standalone application (free) at https://www.postman.com/. There is also some good instructions at https://developer.xero.com/documentation/tools/postman which I used a lot.

Also, make sure you’ve added all the scopes you need. I have 7 in total: offline_access, accounting.transactions, openid, profile, email, accounting.contacts, accounting.settings.

Hopefully this points you in the right direction.

Thanks @sitestreet
I have managed to setup the OAuth2 connector and to Authorize which loads the login to xero to authenticate page. This is successful, but errors with…

{"status":"500","message":"Http status code 400. {\"error\":\"invalid_client\"}","stack":"Error: Http status code 400. {\"error\":\"invalid_client\"}\n at IncomingMessage.<anonymous> (E:\\inetpub\\wwwroot\\Xero\\lib\\oauth\\index.js:95:39)\n at IncomingMessage.emit (events.js:205:15)\n at endReadableNT (_stream_readable.js:1154:12)\n at processTicksAndRejections (internal/process/task_queues.js:84:9)"}

Mim

@patrick Do you know if this error is a Wappler issue?
This is NodeJS page

Thanks.

Hmm is your client id containing only numbers?

No, its like this (not the actual value)
66C8Z2BC9B6C55SDB6DD0A4CE3575722

Still happening after updating to 3.5.2

Any ideas?