Category Archives: salesforce

Using Salesforce API with python to create Cases and send Emails

This is an area which is pretty hard to find information about. A lot of people simply use Salesforce for accounts and sales, which means that they do not use Servicedesk at all.

When I wanted to integrate Salesforce from a SIEM solution I thought, how hard can it be. First of all, it was not hard when I finally found out how to do it. But getting there took a few hours. Here is how you can do it.

There is a nice python toolkit that is pretty outdated, but it works like a charm

Start by donwloading it.
The next step is gather a few things from your Salesforce installation. You need these:

* Your security token for the account that you are going to use.
(Help here:

* Your username and password for the account that you are going to use.

* The WSDL of your installation. In my case it was the Enterprise WSDL.
(Help here:

Once you have all these things follow these steps. I did this on Debian, but it will work the same on any Linux dist.

1. Install salesforce python toolkit (python install)

2. Save the WSDL as a file called wsdl.xml on your local system. In my example below I have created a folder in /root/ called salesforce and put it there.

3. Create the file below, called and place it in the same folder.

4. Now you should have two files, one file called “” and one called “wsdl.xml” in the same folder.

5. The next step is to replace some of the items in the code above. Start with changing the receiver e-mail. This is just an example on how you send e-mail via Salesforce.

6. Add your credentials (user,password,token) to the row at the top where you do the login.

7. The final thing is the AccountId. This is the Company (or Account in salesforce terms) that will be the owner of the Case when it is created. You can put your own Company id here for example. AccountId is located when you browse an account and look at the URL. It will be something like “001g00000XLyIxiF”. It starts with 001. Take that string and put it at the AccountId.

8. Done!

If you want to do more, have a look in the WSDL file. It is pretty straight forward and you can do a lot of things. If you search for “SingleEmailMessage” or “Case” you can find the objects and you see what kind of parameters you can set. Cases are of type Object so when you create them you use the create() function. As seen above. Read more here:
Good luck!