Jump to content

Api JAVA to Sage


 Share

Recommended Posts

Hi, thank you for your question.

Could you confirm that you are successfully obtaining the code returned to your callback URL and then make the request to the token endpoint before the code expires?

In the example you provide the code looks to be static? Could you share the method you're using for the authorization request as per https://developer.sage.com/accounting/guides/authenticating/authentication/ please.

Thanks

Mark

Link to comment
Share on other sites

What does the request look like in the Postman console? 

Below is an example nodejs method used to exchange the code for tokens. You can see it uses the qs parsing library to stringify the request parameters before passing the request via axios. If you're confident the code has not expired by the time you're making the request in your method try parsing the body parameters in a similar way to the below.

Thanks

Mark

const exchange_code = async(code)=>{
//The qs library is required to stringify the data for url encoding
    var data = qs.stringify({
        client_id: String(process.env.client_id),
        client_secret: String(process.env.client_secret),
        code: code,
        grant_type: 'authorization_code',
        redirect_uri: String(config.callback_url),
      });
      var cfg = {
        method: 'post',
        url: String(config.access_token_url),
      headers: { 
        'Content-Type': 'application/x-www-form-urlencoded', 
        'Accept': 'application/json'
      },
      data : data
    }
    try {
      //Pass the config to axios and make the post request
    const resdata = await axios(cfg)
    var credentials = resdata.data;
Link to comment
Share on other sites

Hello!
Yes, I can confirm that my callback url is correct.

I've made some updates to my java code. As you can see, I'm redirected to the callback URL, with an authorization code.

I'm blocked with the step "Exchange the authorization code for the access token". I get error 400.


(It's the same error on postman if we dont send the body parameters as x-www-form-urlencoder, so I think the problem comes to the syntax of the body parameters)

a.PNG

b.PNG

d.PNG

e.PNG

f.PNG

g.PNG

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...