function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
StephenBStephenB 

Using Workbench for Bulk API with a proxy server

Hi all, I've been using Workbench (http://wiki.developerforce.com/index.php/Workbench) and I'm annoyed I haven't used it before now - it's an awesome tool!! Quite possibly the most awesome part of it in v3.0.19 is the access to the Bulk API, which is also an amazing new feature in v19 of the API - if you haven't used it yet then you definitely should - allowing parallel processing of data is such a time-saver!

 

There are a couple of things you'll need to do in order to get the Bulk API working via Workbench, which I've been doing over the course of my Friday afternoon, and to save someone else the time, I'm documenting them here:

 

1. If you're using something like XAMPP to run Workbench locally, then you'll need to enable cURL support. This is pretty straight forward - XAMPP has very kindly packaged cURL libraries with the distribution, but you need to enable it, so

- find your php.ini (in %XAMPP%\php directory, where %XAMPP% is where you've installed XAMPP (the base dir)

- open it in your favourite text editor

- search for 'extension=php_curl' and you should get a line that's commented out

- uncomment the line and save

- restart Apache

 

Hey presto! cURL should now be working (check the phpinfo() page to confirm) and Bulk API will work.

 

If you're not using a proxy server you can stop now. If you are, read on...

 

2. The cURL call in the Bulk API php file doesn't support a proxy server, so if you're using one you'll have to add the lines manually.

- Find the file 'BulkAPIClient.php' - this will be in %XAMPP%\htdocs\workbench\restclient

- Open in a text editor

- go to line 173 if you're using v3.0.19 of Workbench. There you'll see the start of a lot of curl_setopt calls - these set the options for when cURL is called.

- You need to add 2 more lines at the end of this curl_setopt section - one for proxy host and one for proxy port.

 

eg. before I changed my code it looked like this:

if($isPost) curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $httpHeaders);
        if($isPost) curl_setopt($ch, CURLOPT_POSTFIELDS, $data);         
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);                                //TODO: use ca-bundle instead
        if($this->compressionEnabled) curl_setopt($ch, CURLOPT_ENCODING, "gzip");  //TODO: add  outbound compression support

 

After I changed it looked like this:

if($isPost) curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $httpHeaders);
        if($isPost) curl_setopt($ch, CURLOPT_POSTFIELDS, $data);         
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);                                //TODO: use ca-bundle instead
        if($this->compressionEnabled) curl_setopt($ch, CURLOPT_ENCODING, "gzip");  //TODO: add  outbound compression support
        curl_setopt($ch, CURLOPT_PROXYPORT, "80");
        curl_setopt($ch, CURLOPT_PROXY, "proxy.internal");

 

If you need authentication for your proxy then add another line using the option CURLOPT_PROXYUSERPWD and the user/pass in the format "username:password"

 

Then save the php file and you should be good to go!

 

Enjoy,

Stephen