{ "info": { "author": "Iqbal Talaat", "author_email": "iqbaltalaat@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "Intended Audience :: System Administrators", "License :: OSI Approved :: Apache Software License", "Operating System :: OS Independent", "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: Implementation :: PyPy", "Topic :: Internet :: WWW/HTTP" ], "description": "*************************\nSimple Salesforce Wrapper\n*************************\n\nSimple Salesforce is a basic Salesforce.com REST API client built for Python 2.6, 2.7, 3.3 and 3.4. The goal is to provide a very low-level interface to the REST Resource and APEX API, returning a dictionary of the API JSON response.\n\nSimple Salesforce wrapper is a small wrapper, that does not do much except adds reconnection upon session expiry and handles the SOAP call for converting a Lead to a Contact\n\nYou can find out more regarding the format of the results in the `Official Salesforce.com REST API Documentation`_\n\n.. _Official Salesforce.com REST API Documentation: http://www.salesforce.com/us/developer/docs/api_rest/index.htm\n\n99% of the Documentation is plagiarized from simple-salesforce. This module does not do much, it just serves me well.\nSimple Salesforce is available here: https://github.com/simple-salesforce/simple-salesforce\n\nInstallation\n------------\n\n.. code-block:: bash\n\n pip3 install simple_salesforce_wrapper\n\nExample\n-------\nThere are two ways to gain access to Salesforce\n\nThe first is to simply pass the domain of your Salesforce instance and an access token straight to ``Salesforce()``\n\nFor example:\n\n.. code-block:: python\n\n from simple_salesforce_wrapper import Salesforce\n sf = Salesforce(instance='na1.salesforce.com', session_id='')\n\nIf you have the full URL of your instance (perhaps including the schema, as is included in the OAuth2 request process), you can pass that in instead using ``instance_url``:\n\n.. code-block:: python\n\n from simple_salesforce_wrapper import Salesforce\n sf = Salesforce(instance_url='https://na1.salesforce.com', session_id='')\n\nThere are also two means of authentication, one that uses username, password and security token and the other that uses IP filtering, username, password and organizationId\n\nTo login using the security token method, simply include the Salesforce method and pass in your Salesforce username, password and token (this is usually provided when you change your password):\n\n.. code-block:: python\n\n from simple_salesforce_wrapper import Salesforce\n sf = Salesforce(username='myemail@example.com', password='password', security_token='token')\n\nTo login using IP-whitelist Organization ID method, simply use your Salesforce username, password and organizationId:\n\n.. code-block:: python\n\n from simple_salesforce_wrapper import Salesforce\n sf = Salesforce(password='password', username='myemail@example.com', organizationId='OrgId')\n\nIf you'd like to enter a sandbox, simply add ``sandbox=True`` to your ``Salesforce()`` call.\n\nFor example:\n\n.. code-block:: python\n\n from simple_salesforce_wrapper import Salesforce\n sf = Salesforce(username='myemail@example.com.sandbox', password='password', security_token='token', sandbox=True)\n\nNote that specifying if you want to use a sandbox is only necessary if you are using the built-in username/password/security token authentication and is used exclusively during the authentication step.\n\nIf you'd like to keep track where your API calls are coming from, simply add ``client_id='My App'`` to your ``Salesforce()`` call.\n\n.. code-block:: python\n\n from simple_salesforce_wrapper import Salesforce\n sf = Salesforce(username='myemail@example.com.sandbox', password='password', security_token='token', sandbox=True, client_id='My App')\n\nIf you view the API calls in your Salesforce instance by Client Id it will be prefixed with ``RestForce/``, for example ``RestForce/My App``.\n\nWhen instantiating a `Salesforce` object, it's also possible to include an\ninstance of `requests.Session`. This is to allow for specialized\nsession handling not otherwise exposed by simple_salesforce_wrapper.\n\nFor example:\n\n.. code-block:: python\n\n from simple_salesforce_wrapper import Salesforce\n import requests\n\n session = requests.Session()\n # manipulate the session instance (optional)\n sf = Salesforce(\n username='user@example.com', password='password', organizationId='OrgId',\n session=session)\n\nRecord Management\n-----------------\n\nTo create a new 'Contact' in Salesforce:\n\n.. code-block:: python\n\n sf.Contact.create({'LastName':'Smith','Email':'example@example.com'})\n\nThis will return a dictionary such as ``{u'errors': [], u'id': u'003e0000003GuNXAA0', u'success': True}``\n\nTo get a dictionary with all the information regarding that record, use:\n\n.. code-block:: python\n\n contact = sf.Contact.get('003e0000003GuNXAA0')\n\nTo get a dictionary with all the information regarding that record, using a **custom** field that was defined as External ID:\n\n.. code-block:: python\n\n contact = sf.Contact.get_by_custom_id('My_Custom_ID__c', '22')\n\nTo change that contact's last name from 'Smith' to 'Jones' and add a first name of 'John' use:\n\n.. code-block:: python\n\n sf.Contact.update('003e0000003GuNXAA0',{'LastName': 'Jones', 'FirstName': 'John'})\n\nTo delete the contact:\n\n.. code-block:: python\n\n sf.Contact.delete('003e0000003GuNXAA0')\n\nTo retrieve a list of deleted records between ``2013-10-20`` to ``2013-10-29`` (datetimes are required to be in UTC):\n\n.. code-block:: python\n\n import pytz\n import datetime\n end = datetime.datetime.now(pytz.UTC) # we need to use UTC as salesforce API requires this!\n sf.Contact.deleted(end - datetime.timedelta(days=10), end)\n\nTo retrieve a list of updated records between ``2014-03-20`` to ``2014-03-22`` (datetimes are required to be in UTC):\n\n.. code-block:: python\n\n import pytz\n import datetime\n end = datetime.datetime.now(pytz.UTC) # we need to use UTC as salesforce API requires this\n sf.Contact.updated(end - datetime.timedelta(days=10), end)\n\nNote that Update, Delete and Upsert actions return the associated `Salesforce HTTP Status Code`_\n\n.. _Salesforce HTTP Status Code: http://www.salesforce.com/us/developer/docs/api_rest/Content/errorcodes.htm\n\nUse the same format to create any record, including 'Account', 'Opportunity', and 'Lead'.\nMake sure to have all the required fields for any entry. The `Salesforce API`_ has all objects found under 'Reference -> Standard Objects' and the required fields can be found there.\n\n.. _Salesforce HTTP Status Code: http://www.salesforce.com/us/developer/docs/api_rest/Content/errorcodes.htm\n.. _Salesforce API: https://www.salesforce.com/developer/docs/api/\n\nQueries\n-------\n\nIt's also possible to write select queries in Salesforce Object Query Language (SOQL) and search queries in Salesforce Object Search Language (SOSL).\n\nSOQL queries are done via:\n\n.. code-block:: python\n\n sf.query(\"SELECT Id, Email FROM Contact WHERE LastName = 'Jones'\")\n\nIf, due to an especially large result, Salesforce adds a ``nextRecordsUrl`` to your query result, such as ``\"nextRecordsUrl\" : \"/services/data/v26.0/query/01gD0000002HU6KIAW-2000\"``, you can pull the additional results with either the ID or the full URL (if using the full URL, you must pass 'True' as your second argument)\n\n.. code-block:: python\n\n sf.query_more(\"01gD0000002HU6KIAW-2000\")\n sf.query_more(\"/services/data/v26.0/query/01gD0000002HU6KIAW-2000\", True)\n\nAs a convenience, to retrieve all of the results in a single local method call use\n\n.. code-block:: python\n\n sf.query_all(\"SELECT Id, Email FROM Contact WHERE LastName = 'Jones'\")\n\nSOSL queries are done via:\n\n.. code-block:: python\n\n sf.search(\"FIND {Jones}\")\n\nThere is also 'Quick Search', which inserts your query inside the {} in the SOSL syntax. Be careful, there is no escaping!\n\n.. code-block:: python\n\n sf.quick_search(\"Jones\")\n\nSearch and Quick Search return ``None`` if there are no records, otherwise they return a dictionary of search results.\n\nMore details about syntax is available on the `Salesforce Query Language Documentation Developer Website`_\n\n.. _Salesforce Query Language Documentation Developer Website: http://www.salesforce.com/us/developer/docs/soql_sosl/index.htm\n\nLead Conversion\n---------------\n\n.. code-block:: python\n\n (convert_success, convert_response) = sf.convert_lead(lead_id=lead_sfid, account_id=account_sfid)\n\nConvert Lead returns a tuple containing a boolean status and a convert_response.\nIf convert_success is True then so is convert_response is the contact ID\nIf convert_success is False then so is convert_response is the error code e.g. CANNOT_UPDATE_CONVERTED_LEAD\n\nOther Options\n-------------\n\nTo insert or update (upsert) a record using an external ID, use:\n\n.. code-block:: python\n\n sf.Contact.upsert('customExtIdField__c/11999',{'LastName': 'Smith','Email': 'smith@example.com'})\n\nTo retrieve basic metadata use:\n\n.. code-block:: python\n\n sf.Contact.metadata()\n\nTo retrieve a description of the object, use:\n\n.. code-block:: python\n\n sf.Contact.describe()\n\nTo retrieve a description of the record layout of an object by its record layout unique id, use:\n\n.. code-block:: python\n\n sf.Contact.describe_layout('39wmxcw9r23r492')\n\nTo retrieve a list of top level description of instance metadata, user:\n\n.. code-block:: python\n\n sf.describe()\n\n for x in sf.describe()[\"sobjects\"]:\n print x[\"label\"]\n\n\nUsing Bulk\n----------\n\nYou can use this library to access Bulk API functions.\n\nCreate new records:\n\n.. code-block:: python\n\n data = [{'LastName':'Smith','Email':'example@example.com'}, {'LastName':'Jones','Email':'test@test.com'}]\n\n sf.bulk.Contact.insert(data)\n\nUpdate existing records:\n\n.. code-block:: python\n\n data = [{'Id': '0000000000AAAAA', 'Email': 'examplenew@example.com'}, {'Id': '0000000000BBBBB', 'Email': 'testnew@test.com'}]\n\n sf.bulk.Contact.update(data)\n\nUpsert records:\n\n.. code-block:: python\n\n data = [{'Id': '0000000000AAAAA', 'Email': 'examplenew2@example.com'}, {'Id': '', 'Email': 'foo@foo.com'}]\n\n sf.bulk.Contact.upsert(data, 'Id')\n\nQuery records:\n\n.. code-block:: python\n\n query = 'SELECT Id, Name FROM Account LIMIT 10'\n\n sf.bulk.Account.query(query)\n\nDelete records (soft deletion):\n\n.. code-block:: python\n\n data = [{'Id': '0000000000AAAAA'}]\n\n sf.bulk.Contact.delete(data)\n\nHard deletion:\n\n.. code-block:: python\n\n data = [{'Id': '0000000000BBBBB'}]\n\n sf.bulk.Contact.hard_delete(data)\n\n\nUsing Apex\n----------\n\nYou can also use this library to call custom Apex methods:\n\n.. code-block:: python\n\n payload = {\n \"activity\": [\n {\"user\": \"12345\", \"action\": \"update page\", \"time\": \"2014-04-21T13:00:15Z\"}\n ]\n }\n result = sf.apexecute('User/Activity', method='POST', data=payload)\n\nThis would call the endpoint ``https://.salesforce.com/services/apexrest/User/Activity`` with ``data=`` as\nthe body content encoded with ``json.dumps``\n\nYou can read more about Apex on the `Force.com Apex Code Developer's Guide`_\n\n.. _Force.com Apex Code Developer's Guide: http://www.salesforce.com/us/developer/docs/apexcode\n\nAdditional Features\n-------------------\n\nThere are a few helper classes that are used internally and available to you.\n\nIncluded in them are ``SalesforceLogin``, which takes in a username, password, security token, optional boolean sandbox indicator and optional version and returns a tuple of ``(session_id, sf_instance)`` where `session_id` is the session ID to use for authentication to Salesforce and ``sf_instance`` is the domain of the instance of Salesforce to use for the session.\n\nFor example, to use SalesforceLogin for a sandbox account you'd use:\n\n.. code-block:: python\n\n from simple_salesforce_wrapp import SalesforceLogin\n session_id, instance = SalesforceLogin(\n username='myemail@example.com.sandbox',\n password='password',\n security_token='token',\n sandbox=True)\n\nSimply leave off the final ``True`` if you do not wish to use a sandbox.\n\nAlso exposed is the ``SFType`` class, which is used internally by the ``__getattr__()`` method in the ``Salesforce()`` class and represents a specific SObject type. ``SFType`` requires ``object_name`` (i.e. ``Contact``), ``session_id`` (an authentication ID), ``sf_instance`` (hostname of your Salesforce instance), and an optional ``sf_version``\n\nTo add a Contact using the default version of the API you'd use:\n\n.. code-block:: python\n\n from simple_salesforce_wrapper import SFType\n contact = SFType('Contact','sesssionid','na1.salesforce.com')\n contact.create({'LastName':'Smith','Email':'example@example.com'})\n\nTo use a proxy server between your client and the SalesForce endpoint, use the proxies argument when creating SalesForce object.\nThe proxy argument is the same as what requests uses, a map of scheme to proxy URL:\n\n.. code-block:: python\n\n proxies = {\n \"http\": \"http://10.10.1.10:3128\",\n \"https\": \"http://10.10.1.10:1080\",\n }\n SalesForce(instance='na1.salesforce.com', session_id='', proxies=proxies)\n\nAll results are returned as JSON converted OrderedDict to preserve order of keys from REST responses.\n", "description_content_type": null, "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/afrobeard/simple-salesforce-wrapper", "keywords": "python salesforce salesforce.com", "license": "Apache 2.0", "maintainer": "", "maintainer_email": "", "name": "simple-salesforce-wrapper", "package_url": "https://pypi.org/project/simple-salesforce-wrapper/", "platform": "", "project_url": "https://pypi.org/project/simple-salesforce-wrapper/", "project_urls": { "Homepage": "https://github.com/afrobeard/simple-salesforce-wrapper" }, "release_url": "https://pypi.org/project/simple-salesforce-wrapper/0.2.0/", "requires_dist": null, "requires_python": "", "summary": "Simple Salesforce is a basic Salesforce.com REST API client. The goal is to provide a very low-level interface to the API, returning an ordered dictionary of the API JSON response.", "version": "0.2.0" }, "last_serial": 3105346, "releases": { "0.2.0": [ { "comment_text": "", "digests": { "md5": "4c90fbd3b94b089b48aaa52e22bd9b0f", "sha256": "428abad44d115e489bdc254592e6506886feae2972f61a5a75cf905980177adf" }, "downloads": -1, "filename": "simple-salesforce-wrapper-0.2.0.tar.gz", "has_sig": false, "md5_digest": "4c90fbd3b94b089b48aaa52e22bd9b0f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10087, "upload_time": "2017-08-18T04:44:10", "url": "https://files.pythonhosted.org/packages/64/26/072e55431118f9b5ef24347c9fc0a1bf515989eee9d4e646a12ee0335fc1/simple-salesforce-wrapper-0.2.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "4c90fbd3b94b089b48aaa52e22bd9b0f", "sha256": "428abad44d115e489bdc254592e6506886feae2972f61a5a75cf905980177adf" }, "downloads": -1, "filename": "simple-salesforce-wrapper-0.2.0.tar.gz", "has_sig": false, "md5_digest": "4c90fbd3b94b089b48aaa52e22bd9b0f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10087, "upload_time": "2017-08-18T04:44:10", "url": "https://files.pythonhosted.org/packages/64/26/072e55431118f9b5ef24347c9fc0a1bf515989eee9d4e646a12ee0335fc1/simple-salesforce-wrapper-0.2.0.tar.gz" } ] }