0

I am currently working for an online market. Once a customer completes an order, I want to transfer that order into Sage Accounting using Sage API calls.

Here is how I have thought about implementing this process:

  • Customer sends an order
  • A script is called, taking the order details and creating an invoice through a sage API request.

My problem is that I cannot find a way to automatize the process before making the API request. Here is how a request must be made (according to the Sage API documentation) https://sageone-uk-help.s3.amazonaws.com/sageone_oauth.png .

I am aware of the refresh token, but the problem is the code needed to obtain the access token is generated after logging into Sage. The script will therefore do nothing if it reaches the login page.

Dharman
  • 30,962
  • 25
  • 85
  • 135
  • I believe you have used incorrect tags and I fixed it for you. You can still add three more if you would like but do not use [tag:api], please. – Dharman Jun 19 '19 at 18:34

1 Answers1

1

I'm very sorry, but it is not possible to automate the authorization process. It wouldn't make much sense as well: The Sage Accounting user has to explicitely express his consent that your application is allowed to access their accounting data.

If it's only one account your application has to use in Sage Accounting, you could just create an access and refresh token on your machine and export it to the application. Or you implement a "Connect with Sage Accounting" button in your application's backend which initiates the OAuth flow and then stores the tokens.

(And just for the sake of completeness: The authorization code is only valid a minute, so better not try to store that one anywhere.)

tosch
  • 86
  • 5
  • Yes, there is only one account I use. So, just to make thins clear. I must make a curl request to https://www.sageone.com/oauth2/auth/central, submit the form by choosing the country, get redirected to https://eu-signon3.sso.services.sage.com/, submit the login form, all programatically ? If yes, can you provide me with a code example of doing so? Thank you. – CiprianIvan Jun 20 '19 at 07:55
  • No, you do this manually once to get a set of access and refresh tokens. When you have those, you can put them into your application and then use the refresh token at the OAuth2 token endpoint to get new set. As long as you renew the tokens once in a while (the refresh token expires after 31 days), there is no need for human interaction. – tosch Jun 24 '19 at 04:50