How to load data from Pipedrive To PostgreSQL

How to Extract my data from Pipedrive?

Pipedrive exposes its complete platform to developers through its API. As a Web API following the RESTful architecture principles, it can be accessed through HTTP.

As a RESTful API, interacting with it can be achieved by using tools like CURL or Postman or by using HTTP clients for your favorite language or framework. A few suggestions:

  • Apache HttpClient for Java
  • Spray-client for Scala
  • Hyper for Rust
  • Ruby rest-client
  • Python http-client

Pipedrive API Authentication

Pipedrive API Authentication is API-Key based. You acquire an API Key from the platform, and you can use it to securely authenticate to the API. All the calls are executed over secure HTTPS.

Pipedrive Rate Limiting

Rate limiting is considered per API token. API allows performing 100 requests per 10 seconds.

Every API response includes the following headers:

  1. X-RateLimit-Limit: the number of requests the current API token can perform for the 10 seconds window.
  2. X-RateLimit-Remaining: the number of requests left for the 10 seconds window.
  3. X-RateLimit-Reset: the amount of seconds before the limit resets.

In case the limit is exceeded for the time window, the Pipedrive API will return an error response with HTTP code 429 and Retry-After header that will indicate the number of seconds before the limit resets.

Endpoints and Available Resources

Pipedrive exposes a large number of endpoints from which we can interact with the platform. These endpoints can be used to execute commands like adding a new person to our contact list but also to pull data from it. A unique characteristic of the Pipedrive API is that for many of the resources a companion resource exists which manages the custom fields that you might have created for the resource. In this way, maximum flexibility is offered to the users of the platform.

The list of available resources follows:

  • Activities: Activities are appointments, tasks, and events in general that can be associated with a deal and your sales pipeline.
  • Activity Fields: custom fields created for your activities.
  • Activity Types: user-defined types for your activities
  • Authorization: Authorization objects can be fetched without an API token but using an email and password.
  • Currencies: Supported currencies that can be used to represent the monetary value of a Deal or a value of any monetary type custom field.
  • Deals: Deals represent ongoing, lost, or won sales to an organization or to a Person.
  • Deal Fields: DealFields represent the near-complete schema for a Deal in the context of the company of the authorized user.
  • Email Messages: EmailMessages represent e-mail messages sent or received through the Pipedrive designated e-mail account.
  • Email Threads: EmailThreads represent e-mail message threads that contain individual e-mail messages.
  • Files: Files are documents of any kind (images, spreadsheets, text files, etc) that are uploaded to Pipedrive
  • Filters: Each filter is essentially a set of data validation conditions.
  • Goals: Goals help your team meet your sales targets.
  • Mail Messages: MailMessages represent mail messages that are being synced with Pipedrive using the 2-way sync or the Smart Email BCC feature.
  • MailThreads: MailThreads represent mail threads that contain individual mail messages.
  • Notes: Notes are pieces of textual (HTML-formatted) information that can be attached to Deals, Persons, and Organizations.
  • Note Fields: Custom fields for Notes.
  • Organizations: Organizations are companies and other kinds of organizations you are making Deals with.
  • Organization Fields: OrganizationFields represent the near-complete schema for an Organization in the context of the company of the authorized user.
  • Persons: Persons are your contacts, the customers you are doing Deals with
  • Person Fields: Custom fields for persons.
  • Pipelines: Pipelines are essentially ordered collections of Stages.
  • Products: Products are the goods or services you are dealing with.
  • Product fields: ProductFields represent the near-complete schema for a Product.
  • Stages: Stage is a logical component of a Pipeline, and essentially a bucket that can hold a number of Deals.
  • Users: Users are people with access to your Pipedrive account.

For a detailed list of all endpoints together with a way to make requests to them without a client to see the data they return, if you have a Pipedrive account. Please check here.

It is clear that with such a rich platform and API, the data that can be pulled out of Pipedrive are both valuable and come in large quantities. So, let’s assume that we want to pull all the persons out of Pipedrive to use the associated data for further analysis. To do so, we need to make a GET request with your favorite client to the Persons’ endpoint like this.

SH
GET https://api.pipedrive.com/v1/persons?start=0&api_token=YOUR_KEY

The response headers and the actual response will look like the following:

Header

JSON
{
"server": "nginx",
"date": "Tue, 06 Sep 2016 15:46:38 GMT",
"content-type": "application/json",
"transfer-encoding": "chunked",
"connection": "keep-alive",
"x-frame-options": "SAMEORIGIN",
"x-xss-protection": "1; mode=block",
"x-ratelimit-limit": "100",
"x-ratelimit-remaining": "99",
"x-ratelimit-reset": "10",
"access-control-allow-origin": "*"
}

Response

JSON
{
"success": true,
"data": [
{
"id": 1,
"company_id": 1180166,
"owner_id": {
"id": 1682699,
"name": "Kostas",
"email": "costas.pardalis@gmail.com",
"has_pic": true,
"pic_hash": "39bf355364aacbde4fdfed3cef8a4589",
"active_flag": true,
"value": 1682699
},
"org_id": null,
"name": "Fotiz",
"first_name": null,
"last_name": "Fotiz",
"open_deals_count": 0,
"closed_deals_count": 0,
"participant_open_deals_count": 0,
"participant_closed_deals_count": 0,
"email_messages_count": 0,
"activities_count": 0,
"done_activities_count": 0,
"undone_activities_count": 0,
"reference_activities_count": 0,
"files_count": 0,
"notes_count": 0,
"followers_count": 1,
"won_deals_count": 0,
"lost_deals_count": 0,
"active_flag": true,
……

Inside the response, there will be an array of objects with each one representing one Person as it is represented in Pipedrive. Please note that all data are serialized in JSON.

Pipedrive Data Preparation for PostgreSQL

To populate a PostgreSQL database instance with data, first, you need to have a well-defined data model or schema that describes the data. As a relational database, PostgreSQL organizes data around tables.

Each table is a collection of columns with a predefined data type as an integer or VARCHAR. PostgreSQL, like any other SQL database, supports a wide range of different data types.

A typical strategy for loading data from Pipedrive to a PostgreSQL database is to create a schema where you will map each API endpoint to a table. Each key inside the Pipedrive API endpoint response should be mapped to a column of that table, and you should ensure the right conversion to a PostgreSQL compatible data type. For example, if an endpoint from Pipedrive returns a value as String, you should convert it into a VARCHAR with a predefined max size or TEXT data type. Tables can then be created on your database using the CREATE SQL statement.

Of course, you will need to ensure that as the data types from the Pipedrive API might change, you will adapt your database tables accordingly. There’s no such thing as automatic data typecasting.

After you have a complete and well-defined data model or schema for PostgreSQL, you can move forward and start loading your data into the database.

Load data from Pipedrive to PostgreSQL

Once you have defined your schema and you have created your tables with the proper data types, you can start loading data into your database.

The most straightforward way to insert data into a PostgreSQL database is by creating and executing INSERT statements. With INSERT statements, you will be adding data row-by-row directly to a table. It is the most basic and straightforward way of adding data into a table but it doesn’t scale very well with larger datasets.

The preferred way of adding larger datasets into a PostgreSQL database is by using the COPY command. COPY is copying data from a file on a file system that is accessible by the PostgreSQL instance. In this way, much larger datasets can be inserted into the database in less time.

You should also consult the documentation of PostgreSQL on how to populate a database with data. It includes a number of very useful best practices on how to optimize the process of loading data into your PostgreSQL database.

COPY requires physical access to a file system in order to load data. Nowadays, with cloud-based, fully managed databases, getting direct access to a file system is not always possible. If this is the case and you cannot use a COPY statement, then another option is to use PREPARE together with INSERT, to end up with optimized and more performant INSERT queries.

Updating your Pipedrive data on PostgreSQL

As you will be generating more data on Intercom, you will need to update your older data on PostgreSQL. This includes new records together with updates to older records that for any reason have been updated on Intercom.

You will need to periodically check Intercom for new data and repeat the process that has been described previously while updating your currently available data if needed. Updating an already existing row on a PostgreSQL table is achieved by creating UPDATE statements.

Another issue that you need to take care of is the identification and removal of any duplicate records on your database. Either because Intercom does not have a mechanism to identify new and updated records or because of errors on your data pipelines, duplicate records might be introduced to your database.

In general, ensuring the quality of the data that is inserted in your database is a big and difficult issue and PostgreSQL features like TRANSACTIONS can help tremendously, although they do not solve the problem in the general case.

The best way to load data from Pipedrive to PostgreSQL

So far we just scraped the surface of what you can do with PostgreSQL and how to load data into it. Things can get even more complicated if you want to integrate data coming from different sources.

Are you striving to achieve results right now?

Instead of writing, hosting, and maintaining a flexible data infrastructure use RudderStack that can handle everything automatically for you.

RudderStack with one click integrates with sources or services, creates analytics-ready data, and syncs your Pipedrive to PostgreSQL right away.

Sign Up For Free And Start Sending Data
Test out our event stream, ELT, and reverse-ETL pipelines. Use our HTTP source to send data in less than 5 minutes, or install one of our 12 SDKs in your website or app.
Don't want to go through the pain of direct integration? RudderStack's Pipedrive integration makes it easy to send data from Pipedrive to PostgreSQL.