cancel
Showing results for 
Search instead for 
Did you mean: 
Reply

Xero Oauth2.0

Xero released their Oauth2.0 authenticated access to their API recently.

I am trying to write some flows to use this.

If I use Postman to generate the access code and then use it in flow, all works fine.

 

However the code needs to be refreshed every 30 minutes.

Running the token refresh call in Postman works fine, however it fails in Flow. "error": "unsupported_grant_type"

 

Post to https://identity.xero.com/connect/token

Header

"Authorization": "Basic Rjd..." - valid (checked) token 

"Content-Type": "application/x-www-form-urlencoded"

 

The body of the http call is :-

{
"grant_type":"refresh_token",
"refresh_token":"0134e4a53c...",
"client_id":"F7B7...",
"client_secret":"GEfl..."
}

 

Can anyone shed any light on this please?

38 REPLIES 38
v-alzhan-msft
Community Support
Community Support

Hi @MartinHutchcpa ,

 

Could you please share a screenshot of the configuration of your flow?

 

Best regards,

Alice       

Community Support Team _ Alice Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi Alice,

Here you go.

 

Capture.JPG

 

 

https://developer.xero.com/documentation/oauth2/auth-flow

This links to the refresh token syntax.

Did you ever get this working? I assume, if you are trying the refresh token, you had made the initial authentication work? Could you share that HTTP flow please?

Hi Luke,

I used Postman to get an initial token. The token is saved in a SharePoint list.

I have a flow that refreshes this token and saves it back to the list, this runs every 15 mins.

My flows then use this token from the SharePoint list to do their thing.

Hope this helps.

First off, thank you for replying to a post from 2020.

If my thinking is correct, the initial auth is performed via postman, and the PA flow retrieves the token saved in a sharepoint list?

 

I will explain my scenario. Google form time entry, which essentially was saved to a google sheet. I could extract the new rows and post to a sharepoint list, for time entry for a client. They have since moved to WorkFlowMax; i'm trying to create a similar process.

 

I would need to auth once per day to WFM via API and then POST add time. I imagine being in the position of auth once, and then refresh once per 24 hours, in order to post new data. 

 

You worked out how to refresh such token via PowerA, referencing the original question? 

 

Please can we keep the conversation going, I don't want to give up on my objective! 

cheers
Luke

Hi Luke,

For Xero, the refresh PA is very simple, not sure about Google api endpoint though.

The Google Sheet aspect is easy, as there is a connector.

I have used PostMan for the first time, and have my access token now. 

So I assume I can now bring that into PowerAutomate and work on the refresh cycle. 

Once that is done, I can look at adding new time entry into work flow max.

 

Any pointers with the refresh flow for the token please?

Hi Luke,

I store my token in a Dynamics 365 table, although I have used Sharepoint in the past.

MartinHutchcpa_0-1620969428165.png

 

Awesome! Over on GIT is a Postman environment to import. Has all the workings of getting started with the Worflow max api - (GitHub - XeroAPI/workflowmax-postman-oauth2: A postman collection for use with WorkflowMax's API and...

 

So I can get to speed with interacting with the API via Postman and then bring my learnings into Power Automate.

cheers for the screenshot 

@MartinHutchcpa , what is the redirect URL back to Power Automate that you use?

I didnt need one as I was working in private mode

Please could you post the breakdown of the HTTP flow, where you are refreshing the token.

I can't work out what should be in the Body and the Headers, however much I try I get Invalid_Client or Invalid_Request, where trying to refresh

 

Also, how is this string made up: Do I use the text as is, but replace the id and secret?

"Basic " + base64encode(client_id + ":" + client_secret)

Its this Authorization string which is throwing me now! I'm getting back Invalid_Client in PA. Could you give me some pointers please on how you have encoded it? I see at the first screen shot, its an expression with Basic and then I assume your base64encode string for client id and pass - how did you encode it?

OK I sorted it!!! Wow... talk about learning.

 

In the HTTP call I formed the body as form-data (reference from the way POSTMAN was forming the refresh request) 

 

grant_type=refresh_token&refresh_Token=REFRESHTOKEN&client_id=CLIENTID&client_secret=CLIENTSECRET

 

No need for Authorization header and the base64encode stringScreenshot 2021-05-17 181252.png

Screenshot 2021-05-17 181509.png

Thanks @WillPage (Adding formData to HTTP Request - Power Platform Community (microsoft.com))

 

Thanks @MartinHutchcpa 

Hi @LukePWilkins (et all)

 

Credit for your persistence here.  I am trying to do exactly the same thing and can't seem to get past "{"error":"invalid_client"}".

 

I have successfully authenticated, refreshed tokens, retrieved invoices, and created invoices using Postman.

 

I have created a single flow with the three variables below and validated that the values are all correct and matching what is in Postman.

 

I have also tried formatting the body in JSON (noting to change content-type) however this returns 'invalid request'.

 

When I format the body exactly how you have set out, or copy/pasting from Postman both result in 'invalid client'.

 

My process to test this scenario is as follows:

  1. Generate new token in Postman
  2. Copy access_token and refresh token to environment variables in Postman
  3. Run authentication in Postman (sign in etc)
  4. Run Refresh token in Postman
  5. Run Get connections to obtain and store client_id in environment variables in Postman
  6. Test retrieve and create Invoices in Postman
  7. Ensure token is not expired
  8. Run my refresh token flow in PowerAutomate

 

Hoping you can shed some light on this for me. Here are some of my questions:

  1. There was one auto-generated KEY-VALUE in Postman called "Host" and it mentions that if this is removed it will likely result in a 400 error. It doesn't look like you have included this. Did this cause you any problems?
  2. Did you have to first create a flow for steps 1-3 in my process above in order to run the Refresh Token flow?

 

Here is the the output of my flow:

Screen Shot 2021-06-02 at 4.41.19 pm.png

 

Any help would be greatly appreciated.

I have the access token and refresh token saved in a txt file on OneDrive. ClientID and Secret are hardcoded in the variables. RefreshToken, retrieves the refresh token from OneDrive, then its a POST to the API

Screenshot 2021-06-05 093219.png

@LukePWilkins 

 

Thanks for the response!

 

I ended up moving client_id, client_secret, xero-tenant-id, access_token, and refresh_token values to a Davaverse table.

 

I am 99.99999% sure these were all the exact same values that I had initialised as variables in my original flow.

 

Then the only change I made is that I noticed you had an uppercase T in the body for 'refresh_Token'.

 

The flow now works perfectly.  I also added a Do Until status code = 200 so it will retry if it fails for any reason. The flow then updates the dataverse table with the new tokenset (access and refresh) details.

 

My flow now looks like this:

Screen Shot 2021-06-05 at 5.23.03 pm.png

 

Thanks again for your response!

Do you have a typo in Grant_type refresh_tocken???? 

I have my flow scheduled to run every 29 mins and refresh the access token. 

Glad you got it sorted! Two people extra now working with the API via Power Automate

@Nebulas , i'm going to look into storing data in the dataverse, which feels as much better option than onedrive TXT file!!!

Helpful resources

Announcements

Community will be READ ONLY July 16th, 5p PDT -July 22nd

Dear Community Members,   We'd like to let you know of an upcoming change to the community platform: starting July 16th, the platform will transition to a READ ONLY mode until July 22nd.   During this period, members will not be able to Kudo, Comment, or Reply to any posts.   On July 22nd, please be on the lookout for a message sent to the email address registered on your community profile. This email is crucial as it will contain your unique code and link to register for the new platform encompassing all of the communities.   What to Expect in the New Community: A more unified experience where all products, including Power Apps, Power Automate, Copilot Studio, and Power Pages, will be accessible from one community.Community Blogs that you can syndicate and link to for automatic updates. We appreciate your understanding and cooperation during this transition. Stay tuned for the exciting new features and a seamless community experience ahead!

Summer of Solutions | Week 4 Results | Winners will be posted on July 24th

We are excited to announce the Summer of Solutions Challenge!    This challenge is kicking off on Monday, June 17th and will run for (4) weeks.  The challenge is open to all Power Platform (Power Apps, Power Automate, Copilot Studio & Power Pages) community members. We invite you to participate in a quest to provide solutions to as many questions as you can. Answers can be provided in all the communities.    Entry Period: This Challenge will consist of four weekly Entry Periods as follows (each an “Entry Period”)   - 12:00 a.m. PT on June 17, 2024 – 11:59 p.m. PT on June 23, 2024 - 12:00 a.m. PT on June 24, 2024 – 11:59 p.m. PT on June 30, 2024 - 12:00 a.m. PT on July 1, 2024 – 11:59 p.m. PT on July 7, 2024 - 12:00 a.m. PT on July 8, 2024 – 11:59 p.m. PT on July 14, 2024   Entries will be eligible for the Entry Period in which they are received and will not carryover to subsequent weekly entry periods.  You must enter into each weekly Entry Period separately.   How to Enter: We invite you to participate in a quest to provide "Accepted Solutions" to as many questions as you can. Answers can be provided in all the communities. Users must provide a solution which can be an “Accepted Solution” in the Forums in all of the communities and there are no limits to the number of “Accepted Solutions” that a member can provide for entries in this challenge, but each entry must be substantially unique and different.    Winner Selection and Prizes: At the end of each week, we will list the top ten (10) Community users which will consist of: 5 Community Members & 5 Super Users and they will advance to the final drawing. We will post each week in the News & Announcements the top 10 Solution providers.  At the end of the challenge, we will add all of the top 10 weekly names and enter them into a random drawing.  Then we will randomly select ten (10) winners (5 Community Members & 5 Super Users) from among all eligible entrants received across all weekly Entry Periods to receive the prize listed below. If a winner declines, we will draw again at random for the next winner.  A user will only be able to win once overall. If they are drawn multiple times, another user will be drawn at random.  Individuals will be contacted before the announcement with the opportunity to claim or deny the prize.  Once all of the winners have been notified, we will post in the News & Announcements of each community with the list of winners.   Each winner will receive one (1) Pass to the Power Platform Conference in Las Vegas, Sep. 18-20, 2024 ($1800 value). NOTE: Prize is for conference attendance only and any other costs such as airfare, lodging, transportation, and food are the sole responsibility of the winner. Tickets are not transferable to any other party or to next year’s event.   ** PLEASE SEE THE ATTACHED RULES for this CHALLENGE**   Week 1 Results: Congratulations to the Week 1 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge.   Community MembersNumber SolutionsSuper UsersNumber Solutions Deenuji 9 @NathanAlvares24  17 @Anil_g  7 @ManishSolanki  13 @eetuRobo  5 @David_MA  10 @VishnuReddy1997  5 @SpongYe  9JhonatanOB19932 (tie) @Nived_Nambiar  8 @maltie  2 (tie)   @PA-Noob  2 (tie)   @LukeMcG  2 (tie)   @tgut03  2 (tie)       Week 2 Results: Congratulations to the Week 2 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 2: Community MembersSolutionsSuper UsersSolutionsPower Automate  @Deenuji  12@ManishSolanki 19 @Anil_g  10 @NathanAlvares24  17 @VishnuReddy1997  6 @Expiscornovus  10 @Tjan  5 @Nived_Nambiar  10 @eetuRobo  3 @SudeepGhatakNZ 8     Week 3 Results: Congratulations to the Week 3 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 3:Community MembersSolutionsSuper UsersSolutionsPower Automate Deenuji32ManishSolanki55VishnuReddy199724NathanAlvares2444Anil_g22SudeepGhatakNZ40eetuRobo18Nived_Nambiar28Tjan8David_MA22   Week 4 Results: Congratulations to the Week 4 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 4:Community MembersSolutionsSuper UsersSolutionsPower Automate Deenuji11FLMike31Sayan11ManishSolanki16VishnuReddy199710creativeopinion14Akshansh-Sharma3SudeepGhatakNZ7claudiovc2CFernandes5 misc2Nived_Nambiar5 Usernametwice232rzaneti5 eetuRobo2   Anil_g2   SharonS2  

Check Out | 2024 Release Wave 2 Plans for Microsoft Dynamics 365 and Microsoft Power Platform

On July 16, 2024, we published the 2024 release wave 2 plans for Microsoft Dynamics 365 and Microsoft Power Platform. These plans are a compilation of the new capabilities planned to be released between October 2024 to March 2025. This release introduces a wealth of new features designed to enhance customer understanding and improve overall user experience, showcasing our dedication to driving digital transformation for our customers and partners.    The upcoming wave is centered around utilizing advanced AI and Microsoft Copilot technologies to enhance user productivity and streamline operations across diverse business applications. These enhancements include intelligent automation, AI-powered insights, and immersive user experiences that are designed to break down barriers between data, insights, and individuals. Watch a summary of the release highlights.    Discover the latest features that empower organizations to operate more efficiently and adaptively. From AI-driven sales insights and customer service enhancements to predictive analytics in supply chain management and autonomous financial processes, the new capabilities enable businesses to proactively address challenges and capitalize on opportunities.    

Updates to Transitions in the Power Platform Communities

We're embarking on a journey to enhance your experience by transitioning to a new community platform. Our team has been diligently working to create a fresh community site, leveraging the very Dynamics 365 and Power Platform tools our community advocates for.  We started this journey with transitioning Copilot Studio forums and blogs in June. The move marks the beginning of a new chapter, and we're eager for you to be a part of it. The rest of the Power Platform product sites will be moving over this summer.   Stay tuned for more updates as we get closer to the launch. We can't wait to welcome you to our new community space, designed with you in mind. Let's connect, learn, and grow together.   Here's to new beginnings and endless possibilities!   If you have any questions, observations or concerns throughout this process please go to https://aka.ms/PPCommSupport.   To stay up to date on the latest details of this migration and other important Community updates subscribe to our News and Announcements forums: Copilot Studio, Power Apps, Power Automate, Power Pages

Users online (971)