How to load data from Pipedrive to MS SQL Server
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 authenticate to the API securely. 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:
- X-RateLimit-Limit: the number of requests the current API token can perform for the 10 seconds window.
- X-RateLimit-Remaining: the number of requests left for the 10 seconds window.
- 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 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 representing one Person as it is represented in Pipedrive. Please note that all data are serialized in JSON.
Pipedrive Data Preparation for MS SQL Server
As in every relational database, SQL Server requires a well-defined database schema before we start populating with data. Data is organized in schemas, which are distinct namespaces where database objects belong to.
The most common database objects are of course tables that have a number of columns, with each one having a declared data type. MS SQL Server supports a large number of different data types, which gives us great flexibility in expressing the data that we have and at the same time optimizing our data warehouse.
When working with data coming from web services, where data is usually serialized in JSON, it is important to correctly map the data to the right data types. As changing the data types in the future is a process that might cost in downtime of your database, it is important to spend enough time thinking about the proper data type assignments.
For example, dates in JSON are just strings, but when storing date objects in a database, we can enhance analytics with great capabilities by transforming the raw string data into an appropriate data type. A typical strategy for loading data using a Pipedrive to MS SQL Server 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 an SQL Server compatible data type.
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 Microsoft SQL Server, you can move forward and start loading your data into the database.
Load data from Pipedrive to MS SQL Server
As a feature-rich and mature product, MS SQL Server offers a large and diverse set of methods for loading data into a database. One way of importing data into your database is by using the SQL Server Import and Export Wizard. With it and through a visual interface you will be able to bulk load data from a number of data sources that are supported.
You can import data from another SQL Server, from an Oracle database, from Flat Files, from an Access Data Source, PostgreSQL, MySQL, and finally Azure Blob Storage. Especially if you are using a managed version of MS SQL Server on Azure, you should definitely consider utilizing the Azure Blob Storage connection.
In this way, you will be loading data as Blobs on Azure, and your MS SQL Server database will sync with it through the Import and Export Wizard.
Another way for importing bulk data into an SQL Server, both on Azure and on-premises, is by using the BCP utility. This is a command-line tool that is built specifically for bulk loading and unloading of data using an MS SQL database.
Finally and for compatibility reasons, especially if you are managing databases from different vendors, you can BULK INSERT SQL statements.
In a similar way and as it happens with the rest of the databases, you can also use the standard INSERT statements, where 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 data sets.
So for bulk datasets, you better consider one of the previous methods.
Updating your Pipedrive data on MS SQL Server
As you will be generating more data on Pipedrive, you will need to update your older data on an MS SQL Server database. This includes new records together with updates to older records that for any reason, have been updated on Pipedrive.
You will need to periodically check Pipedrive 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 SQL Server 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 Pipedrive 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 MS SQL Server 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 MS SQL Server
So far we just scraped the surface of what you can do with MS SQL Server 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 MS SQL Server right away.