Easily extract Salesforce data using APIs
Your valuable company data is in Salesforce and you’ve been tasked with getting it outta there and safe and sound into your own MySQL or MS SQL databases. After all, nobody wants their precious data fragmented across third party services.
Sadly, Salesforce doesn’t currently have the option to connect directly to an external database ☹️
In this scenario you’re left with a number of questions.
- How can you export your Salesforce data with minimal hassle?
- Is there some way you can have the data pre-defined into SQL syntax including
TABLE
andINSERT
statements so you don’t need to manually do it? - Can you somehow set up an automated pipeline for all future data exports?
The answer to those questions lies with APIs.
Part one: salesforce APIs
Those lovely people over at Salesforce have a bunch of APIs for developers to do all sorts of wizardry with. Just take a look at this handy list.
We’ve chosen the Bulk API, which will export your Salesforce data to one of CSV, JSON, or XML.
You can use whichever API you prefer. Salesforce has good documentation on choosing APIs so it’s a good idea to take a look at that if you don’t want to use Bulk.
We’ll be focusing on exporting to CSV. John Miller very kindly shared his method and code, which you can see on Pastebin. His original instructions are on Stack Exchange.
For JSON and XML, Salesforce has some more documentation that outlines exactly how to export using Bulk API. And for a general overview of the Bulk API, check out this doc.
If you want to skip using a Salesforce API for some reason, you can use the Data Loader interface.
Part two: SQLizer API
Once you’ve navigated through the Salesforce export process, the hard part’s over. Now you need to convert CSV to SQL. That’s where the SQLizer API comes in.
The Sqlizer API is a simple REST interface that gives you programmatic access to our file conversion algorithm. The processes of converting a file with the API follows four steps:
- Initiate the file conversion
- Upload your file
- Monitor the conversion progress
- Download your converted file
See full docs for more detail.
Step 1: Initiate the file conversion
A JSON to SQL file conversion can be initiated with a POST request to http://sqlizer.io/api/files/
and later accessed and updated at the endpoint http://sqlizer.io/api/files/{ID}/
.
If the request is successful the server will respond with a HTTP 200 code and a JSON representation of the file conversion. The ID field is especially important as it is used in the url of all future requests for this file conversion.
Step 2: Upload your file
Once you have a file ID you can begin uploading your file data by sending POST requests to http://sqlizer.io/api/files/{ID}/data/
.
The Sqlizer API allows you to upload your data in a single request or multiple requests. The latter is achieved by splitting the file into parts and sending each individually. Most files can be uploaded in a single request but if your file is larger than 100Mb or you have an unreliable connection an upload in multiple parts is recommended.
Check out the full API documentation for in-depth details on single and multiple requests.
Step 3: Monitor the conversion progress
Once your file upload is finalised it will be placed in a queue for processing. You can check on its progress with a GET request to http://sqlizer.io/api/files/{ID}/.
curl http://sqlizer.io/api/files/7EVHQlVpq6YrRGLxNyjJdZ-b7DN3hcKpbqwK215IyPpE8ZeddSK4GVe_q0LNdCZnNCwOi1ewyTSEVMy6rkpi8g==/ \
-H "Authorization: Bearer {API-KEY}"
You can see sample responses in full API documentation.
Step 4: Download your converted file
Once the file conversion process is complete you can download the converted file from the url specified in the returned ResultUrl parameter.
🎊 Success! 🎉
Part three: SQL file into SQL database
Now all that’s left to do is simply import/upload your new SQL file into your database. Because SQLizer has pre-defined TABLE
and INSERT
statements this step is simply waiting for your file to import/upload.
Automate and be done with it
With this setup you could potentially automate the entire process of exporting Salesforce data and getting it into your own database. You can even set up a large-scale pipeline with the SQLizer API, convert files en-masse.
Happy automating!
SQLizer converts files into SQL databases. With an API to help automate conversion tasks, it’s one of the best ways to transfer data between databases. Convert a file now.
More from The Official SQLizer blog...
- All new: A JavaScript Client for SQLizer on npm Rejoice, JS developers! A JavaScript client library for SQLizer.io, easily converting CSV, JSON, XML and Spreadsheet files into SQL INSERT or UPDATE statements - is...
- [Update 2024] Convert JSON to SQL: Free and Fast If you want to convert JSON to SQL there’s no concrete or straightforward way of doing things. Conversion is usually tricky because JSON and SQL...
- [Update 2024] Convert XML to SQL Easy and Free To convert XML to SQL, a touch of wizardry is needed. Unlike CSV files and database tables, XML files aren’t naturally organized into rows and...
- [Update 2024] Converting a Word Doc to SQL with SQLizer Wait, what? A Word document? Have you ever found yourself faced with a Word document containing a wealth of data, all neatly structured in a...