Skip to content

Commit

Permalink
Merge branch 'master' into GRAL-4650
Browse files Browse the repository at this point in the history
  • Loading branch information
youssef-saber-3 committed Nov 14, 2024
2 parents 142b51e + 5ac1837 commit e41859d
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 49 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ For public Changelog covering all changes done to Pipedrive’s API, webhooks an

## [Unreleased]

## [23.4.2] - 2024-10-31
### Changed
- Updated the code examples in the README for the JavaScript SDK
### Added
- Add "custom_fields" query paremeter to GET /api/v2/products

## [23.4.1] - 2024-10-09

### Changed
Expand Down Expand Up @@ -703,7 +709,8 @@ structure
* Fixed `GET /goal/:id/results` error handling in case when there are no existing stages connected to specified goal
* Fixed typo in lead example response (`crrency` to `currency`)

[Unreleased]: https://github.com/pipedrive/api-docs/compare/v23.4.1...HEAD
[Unreleased]: https://github.com/pipedrive/api-docs/compare/v23.4.2...HEAD
[23.4.2]: https://github.com/pipedrive/api-docs/compare/v23.4.1...v23.4.2
[23.4.1]: https://github.com/pipedrive/api-docs/compare/v23.4.0...v23.4.1
[23.4.0]: https://github.com/pipedrive/api-docs/compare/v23.3.0...v23.4.0
[23.3.0]: https://github.com/pipedrive/api-docs/compare/v23.2.5...v23.3.0
Expand Down
109 changes: 64 additions & 45 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ See www.pipedrive.com for details.
This is the official Pipedrive API wrapper-client for NodeJS based apps, distributed by Pipedrive Inc freely under the MIT licence.
It provides convenient access to the Pipedrive API, allowing you to operate with objects such as Deals, Persons, Organizations, Products and much more.

## Table of Contents
## Table of Contents
- [Installation](#installation)

- [API Reference](#api-reference)
Expand Down Expand Up @@ -56,23 +56,32 @@ const pipedrive = require('pipedrive');

const PORT = 1800;

const defaultClient = new pipedrive.ApiClient();

// Configure API key authorization: apiToken
let apiToken = defaultClient.authentications.api_key;
apiToken.apiKey = 'YOUR_API_TOKEN_HERE';

app.listen(PORT, () => {
console.log(`Listening on port ${PORT}`);
console.log(`Listening on port ${PORT}`);
});

app.get('/', async (req, res) => {
const api = new pipedrive.DealsApi(defaultClient);
try {
const apiClient = new pipedrive.ApiClient();

// Configure API key authorization: apiToken
let apiToken = apiClient.authentications.api_key;
apiToken.apiKey = 'YOUR_API_TOKEN_HERE';

const api = new pipedrive.DealsApi(apiClient);
const deals = await api.getDeals();

res.send(deals);
return res.send(deals);
} catch (error) {
console.error('Error:', error);

res.status(500).json({
error: error.message,
});
}
});


```

### With OAuth2
Expand Down Expand Up @@ -238,53 +247,63 @@ const cookieParser = require('cookie-parser');
const cookieSession = require('cookie-session');

app.use(cookieParser());
app.use(cookieSession({
app.use(
cookieSession({
name: 'session',
keys: ['key1']
}));
keys: ['key1'],
}),
);
const PORT = 1800;

const pipedrive = require('pipedrive');

const apiClient = new pipedrive.ApiClient();

let oauth2 = apiClient.authentications.oauth2;
oauth2.clientId = 'clientId'; // OAuth 2 Client ID
oauth2.clientSecret = 'clientSecret'; // OAuth 2 Client Secret
oauth2.redirectUri = 'http://localhost:1800/callback'; // OAuth 2 Redirection endpoint or Callback Uri

app.listen(PORT, () => {
console.log(`Listening on port ${PORT}`);
console.log(`Listening on port ${PORT}`);
});

app.get('/', async (req, res) => {
if (req.session.accessToken !== null && req.session.accessToken !== undefined) {
// token is already set in the session
// now make API calls as required
// client will automatically refresh the token when it expires and call the token update callback
const api = new pipedrive.DealsApi(apiClient);
const deals = await api.getDeals();

res.send(deals);
} else {
const authUrl = apiClient.buildAuthorizationUrl();;

res.redirect(authUrl);
}
const apiClient = new pipedrive.ApiClient();

let oauth2 = apiClient.authentications.oauth2;
oauth2.clientId = 'clientId'; // OAuth 2 Client ID
oauth2.clientSecret = 'clientSecret'; // OAuth 2 Client Secret
oauth2.redirectUri = 'http://localhost:1800/callback'; // OAuth 2 Redirection endpoint or Callback Uri

if (
req.session.accessToken !== null &&
req.session.accessToken !== undefined
) {
// token is already set in the session
// now make API calls as required
// client will automatically refresh the token when it expires and call the token update callback
const api = new pipedrive.DealsApi(apiClient);
const deals = await api.getDeals();

res.send(deals);
} else {
const authUrl = apiClient.buildAuthorizationUrl();

res.redirect(authUrl);
}
});

app.get('/callback', (req, res) => {
const authCode = req.query.code;
const promise = apiClient.authorize(authCode);

promise.then(() => {
req.session.accessToken = apiClient.authentications.oauth2.accessToken;
res.redirect('/');
}, (exception) => {
// error occurred, exception will be of type src/exceptions/OAuthProviderException
});
const authCode = req.query.code;
const promise = apiClient.authorize(authCode);

promise.then(
() => {
req.session.accessToken = apiClient.authentications.oauth2.accessToken;
res.redirect('/');
},
(exception) => {
// error occurred, exception will be of type src/exceptions/OAuthProviderException
},
);
});



```

## Documentation for Authorization
Expand Down Expand Up @@ -312,7 +331,7 @@ app.get('/callback', (req, res) => {
- **Type**: OAuth
- **Flow**: accessCode
- **Authorization URL**: https://oauth.pipedrive.com/oauth/authorize
- **Scopes**:
- **Scopes**:
- base: Read settings of the authorized user and currencies in an account
- deals:read: Read most of the data about deals and related entities - deal fields, products, followers, participants; all notes, files, filters, pipelines, stages, and statistics. Does not include access to activities (except the last and next activity related to a deal)
- deals:full: Create, read, update and delete deals, its participants and followers; all files, notes, and filters. It also includes read access to deal fields, pipelines, stages, and statistics. Does not include access to activities (except the last and next activity related to a deal)
Expand Down Expand Up @@ -344,7 +363,7 @@ app.get('/callback', (req, res) => {

All URIs are relative to *https://api.pipedrive.com/v1*

Code examples are available through the links in the list below or on the
Code examples are available through the links in the list below or on the
[Pipedrive Developers Tutorials](https://pipedrive.readme.io/docs/tutorials) page

Class | Method | HTTP request | Description
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pipedrive",
"version": "23.4.1",
"version": "23.4.2",
"description": "Pipedrive REST client for NodeJS",
"license": "MIT",
"main": "dist/index.js",
Expand Down

0 comments on commit e41859d

Please sign in to comment.