0

I created an app on sandbox.pipedrive.com in Marketplace Manager and then I created a callback which asked user to install the app which I setup in pipedrive.

If user allow to install they get redirected to my callback url in controller, my controller the code is :-

app.get('/pipedrive-callback', function(req, res) {
    console.log('Success')
});

Now in function I want to exchange the auth token. Can anyone help me to solve this.

Pradeep
  • 9,667
  • 13
  • 27
  • 34

1 Answers1

1

Can you try this? You need to send another post request to their server after user is redirected to your callback. After the redirection you will get the authorization_code from the request params. You have to send that code in this post request to get the actual tokens that will allow you to do magic.

app.get('/pipedrive-callback', function (req, res) {
    console.log('Success');
    const authorization_code_from_service = req.query.code; // This will extract the authorization_code from the call back url.

    //Here goes your step 4 + 5. You need to make a post request to their server now. For this, there is a library aka "request" in npm. 
    // Here is the link for that https://www.npmjs.com/package/request

    const request = require("request");

    const formData = {
        "grant_type": "authorization_code",
        "redirect_uri": "rediect url that you have set for your app",
        "code": authorization_code_from_service
    }


    request.post({
            url: 'https://oauth.pipedrive.com/oauth/token',
            form: formData
        },
        function (err, httpResponse, body) {
            //This will be the data that you need for further steps. Actual token, expiry time etc
            console.log(body);
        }
    );

});

Npm link : https://www.npmjs.com/package/request

Mudit Juneja
  • 165
  • 9