SalesPyForce Core Object¶
This section provides details around the core module and the methods used within the core object for the salespyforce package, which are listed below.
Init Module (salespyforce)¶
This module (being the primary __init__.py file for the library) provides a
“jumping-off-point” to initialize the primary salespyforce.core.Salesforce object.
- Module:
salespyforce
- Synopsis:
This is the
__init__module for the salespyforce package- Created By:
Jeff Shurtliff
- Last Modified:
Jeff Shurtliff
- Modified Date:
08 May 2023
- class salespyforce.Salesforce(connection_info=None, version=None, base_url=None, org_id=None, username=None, password=None, endpoint_url=None, client_id=None, client_secret=None, security_token=None, helper=None)[source]¶
This is the class for the core object leveraged in this module.
- class Chatter(sfdc_object)[source]¶
This class includes methods associated with Salesforce Chatter.
- __init__(sfdc_object)[source]¶
This method initializes the
salespyforce.core.Salesforce.Chatterinner class object.- Parameters:
sfdc_object (class[salespyforce.Salesforce]) – The core
salespyforce.Salesforceobject
- get_group_feed(group_id, site_id=None)[source]¶
This method retrieves a group’s news feed. (Reference)
- Parameters:
- Returns:
The news feed data
- Raises:
- get_my_news_feed(site_id=None)[source]¶
This method retrieves the news feed for the user calling the function. (Reference)
- Parameters:
site_id (str, None) – The ID of an Experience Cloud site against which to query (optional)
- Returns:
The news feed data
- Raises:
- get_user_news_feed(user_id, site_id=None)[source]¶
This method retrieves another user’s news feed. (Reference)
- Parameters:
- Returns:
The news feed data
- Raises:
- post_comment(feed_element_id, message_text=None, message_segments=None, site_id=None, created_by_id=None)[source]¶
This method publishes a comment on a Chatter feed item. (Reference)
- Parameters:
feed_element_id (str) – The ID of the feed element on which to post the comment
message_text – Plaintext to be used as the message body
message_segments (list, None) – Collection of message segments to use instead of a plaintext message
site_id (str, None) – The ID of an Experience Cloud site against which to query (optional)
created_by_id (str, None) – The ID of the user to impersonate (Experimental)
- Returns:
The response of the POST request
- Raises:
- post_feed_item(subject_id, message_text=None, message_segments=None, site_id=None, created_by_id=None)[source]¶
This method publishes a new Chatter feed item. (Reference)
- Parameters:
subject_id (str) – The Subject ID against which to publish the feed item (e.g.
0F9B000000000W2)message_text – Plaintext to be used as the message body
message_segments (list, None) – Collection of message segments to use instead of a plaintext message
site_id (str, None) – The ID of an Experience Cloud site against which to query (optional)
created_by_id (str, None) – The ID of the user to impersonate (Experimental)
- Returns:
The response of the POST request
- Raises:
- class Knowledge(sfdc_object)[source]¶
This class includes methods associated with Salesforce Knowledge.
- __init__(sfdc_object)[source]¶
This method initializes the
salespyforce.core.Salesforce.Knowledgeinner class object.- Parameters:
sfdc_object (class[salespyforce.Salesforce]) – The core
salespyforce.Salesforceobject
- archive_article(article_id)[source]¶
This function archives a published knowledge article. (Reference)
Added in version 1.3.0.
- Parameters:
article_id (str) – The ID of the article to archive
- Returns:
The API response from the POST request
- Raises:
- assign_data_category(article_id, category_group_name, category_name)[source]¶
This method assigns a single data category for a knowledge article. (Reference)
Added in version 1.2.0.
- Parameters:
- Returns:
The API response from the POST request
- Raises:
- check_for_existing_article(title: str, sobject: str | None = None, return_id: bool = False, return_id_and_number: bool = False, include_archived: bool = False)[source]¶
This method checks to see if an article already exists with a given title and returns its article number. (Reference 1. Reference 2)
- Parameters:
title (str) – The title of the knowledge article for which to check
sobject (str, None) – The Salesforce object to query (
Knowledge__kavby default)return_id (bool) – Determines if the Article ID should be returned (
Falseby default)return_id_and_number (bool) – Determines if Article ID and Article Number should be returned (
Falseby default)include_archived (bool) – Determines if archived articles should be included (
Falseby default)
- Returns:
The Article Number, Article ID, or both (if found), or a blank string if not found
- create_article(article_data: dict, sobject: str | None = None, full_response: bool = False)[source]¶
This method creates a new knowledge article draft. (Reference)
- Parameters:
- Returns:
The API response or the ID of the article draft
- Raises:
- create_draft_from_master_version(article_id: str | None = None, knowledge_article_id: str | None = None, article_data: dict | None = None, sobject: str | None = None, full_response: bool = False)[source]¶
This method creates an online version of a master article. (Reference)
- Parameters:
article_id (str, None) – The Article ID from which to create the draft
knowledge_article_id (str, None) – The Knowledge Article ID (
KnowledgeArticleId) from which to create the draftarticle_data (dict, None) – The article data associated with the article from which to create the draft
sobject (str, None) – The Salesforce object to query (
Knowledge__kavby default)full_response (bool) – Determines if the full API response should be returned instead of the article ID (
Falseby default)
- Returns:
The API response or the ID of the article draft
- Raises:
- create_draft_from_online_article(article_id: str, unpublish: bool = False)[source]¶
This method creates a draft knowledge article from an online article. (Reference)
- Parameters:
- Returns:
The API response from the POST request
- Raises:
- delete_article_draft(version_id: str, use_knowledge_management_endpoint: bool = True)[source]¶
This function deletes an unpublished knowledge article draft.
Added in version 1.4.0.
- Parameters:
- Returns:
The API response from the DELETE request
- Raises:
- get_article_details(article_id: str, sobject: str | None = None, use_knowledge_articles_endpoint: bool | None = None)[source]¶
This method retrieves details for a single knowledge article. (Reference)
Changed in version 1.4.0: A logic issue was resolved and the new optional
use_knowledge_articles_endpointparameter can now be set to force theknowledgeArticlesendpoint to be used for the GET request rather than thesobjectsendpoint.- Parameters:
article_id (str) – The Article ID for which to retrieve details
sobject (str, None) – The Salesforce object to query (
Knowledge__kavby default)use_knowledge_articles_endpoint (bool, None) – Optionally use the
knowledgeArticlesendpoint rather thansobjectsto retrieve the article details (Falseby default)
- Returns:
The details for the knowledge article
- Raises:
RuntimeError,salespyforce.errors.exceptions.DataMismatchError
- get_article_id_from_number(article_number, sobject: str | None = None, return_uri: bool = False)[source]¶
This method returns the Article ID when an article number is provided. (Reference 1, Reference 2)
Warning
The ability to retrieve the article URI/URL rather than the ID will be moved to a separate function in a future release.
- Parameters:
- Returns:
The Article ID or Article URI, or a blank string if no article is found
- Raises:
- get_article_metadata(article_id: str) dict[source]¶
This method retrieves metadata for a specific knowledge article. (Reference)
- Parameters:
article_id (str) – The Article ID for which to retrieve details
- Returns:
The article metadata as a dictionary
- Raises:
- get_article_url(article_id: str | None = None, article_number=None, sobject: str | None = None)[source]¶
This function constructs the URL to view a knowledge article in Lightning or Classic.
- Parameters:
- Returns:
The article URL as a string
- Raises:
- get_article_version(article_id: str)[source]¶
This method retrieves the version ID for a given master article ID. (Reference)
- Parameters:
article_id (str) – The Article ID for which to retrieve details
- Returns:
The version ID for the given master article ID
- Raises:
- get_articles_list(query: str | None = None, sort: str | None = None, order: str | None = None, page_size: int = 20, page_num: int = 1) list[source]¶
This method retrieves a list of knowledge articles. (Reference)
- Parameters:
query (str, None) – A SOQL query with which to filter the results (optional)
sort (str, None) – Optionally sort the results with one of the following values:
LastPublishedDate,CreatedDate,Title, orViewScoreorder (str, None) – Optionally define the ORDER BY as
ASCorDESCpage_size (int) – The number of results per page (
20by default)page_num (int) – The starting page number (
1by default)
- Returns:
The list of retrieved knowledge articles
- Raises:
- get_validation_status(article_id: str | None = None, article_details: dict | None = None, sobject: str | None = None) str[source]¶
This method retrieves the Validation Status for a given Article ID. (Reference)
Changed in version 1.4.0: This method now returns an empty string rather than a
Nonevalue if theValidationStatusfield is not found in the article details data, and a more specific exception class is used when input data is missing instead of the genericRuntimeErrorexception class.- Parameters:
- Returns:
The validation status as a text string
- Raises:
RuntimeError,salespyforce.errors.exceptions.MissingRequiredDataError
- publish_article(article_id, major_version=True, full_response=False)[source]¶
This method publishes a draft knowledge article as a major or minor version. (Reference)
- Parameters:
- Returns:
A Boolean value indicating the success of the action or the API response from the PATCH request
- Raises:
- publish_multiple_articles(article_id_list, major_version=True)[source]¶
This method publishes multiple knowledge article drafts at one time. (Reference)
- Parameters:
- Returns:
The API response from the POST request
- Raises:
- update_article(record_id: str, article_data: dict, sobject: str | None = None, include_status_code: bool = False)[source]¶
This method updates an existing knowledge article draft. (Reference)
- Parameters:
record_id (str) – The ID of the article draft record to be updated
article_data (dict) – The article data used to update the article
sobject (str, None) – The Salesforce object to query (
Knowledge__kavby default)include_status_code (bool) – Determines if the API response status code should be returned (
Falseby default)
- Returns:
A Boolean indicating if the update operation was successful, and optionally the API response status code
- Raises:
- __init__(connection_info=None, version=None, base_url=None, org_id=None, username=None, password=None, endpoint_url=None, client_id=None, client_secret=None, security_token=None, helper=None)[source]¶
This method instantiates the core Salesforce object.
Changed in version 1.4.0: The authorized Salesforce org is now queried to determine the latest API version to leverage unless explicitly defined with the
versionparameter when instantiating the object.- Parameters:
connection_info (dict, None) – The information for connecting to the Salesforce instance
version (str, None) – The Salesforce API version to utilize (uses latest version from org if not explicitly defined)
base_url (str, None) – The base URL of the Salesforce instance
org_id (str, None) – The Org ID of the Salesforce instance
username (str, None) – The username of the API user
password (str, None) – The password of the API user
endpoint_url (str, None) – The endpoint URL for the Salesforce instance
client_id (str, None) – The Client ID for the Salesforce instance
client_secret (str, None) – The Client Secret for the Salesforce instance
security_token (str, None) – The Security Token for the Salesforce instance
helper (str, None) – The file path of a helper file
- Returns:
The instantiated object
- Raises:
- api_call_with_payload(method, endpoint, payload, params=None, headers=None, timeout=None, show_full_error=True, return_json=True)[source]¶
This method performs a POST call against the Salesforce instance. (Reference)
Changed in version 1.4.0: A global constant is now leveraged for the API timeout value instead of hardcoding the value. (Timeout is still 30 seconds in this version)
- Parameters:
method (str) – The API method (
post,put, orpatch)endpoint (str) – The API endpoint to query
payload (dict) – The payload to leverage in the API call
params (dict, None) – The query parameters (where applicable)
headers (dict, None) – Specific API headers to use when performing the API call
timeout (int, None) – The timeout period in seconds (defaults to
30)show_full_error (bool) – Determines if the full error message should be displayed (defaults to
True)return_json – Determines if the response should be returned in JSON format (defaults to
True)
- Returns:
The API response in JSON format or as a
requestsobject- Raises:
TypeError,RuntimeError,ValueError,salespyforce.errors.exceptions.InvalidURLError
- can_access_record(access_type, record_id, user_id=None, record_access_data=None, raise_exc_on_failure=True)[source]¶
This method evaluates if a user can access a specific record given the access type.
Added in version 1.4.0.
- Parameters:
access_type (str) – The type of access to evaluate (
read,edit, ordelete)record_id (str) – The ID of the record
user_id (str, None) – The ID of the user to evaluate (defaults to the current/running user if not defined)
record_access_data (dict, None) – The user record access data that has already been retrieved (optional)
raise_exc_on_failure (bool) – Raises an exception rather than returning a
Nonevalue (Trueby default)
- Returns:
Boolean value indicating the access level for the given field
- Raises:
- can_delete_record(record_id, user_id=None, record_access_data=None, raise_exc_on_failure=True)[source]¶
This method evaluates if a user has access to delete a specific record.
Added in version 1.4.0.
- Parameters:
record_id (str) – The ID of the record
user_id (str, None) – The ID of the user to evaluate (defaults to the current/running user if not defined)
record_access_data (dict, None) – The user record access data that has already been retrieved (optional)
raise_exc_on_failure (bool) – Raises an exception rather than returning a
Nonevalue (Trueby default)
- Returns:
Boolean value indicating the access level for the given field
- Raises:
- can_edit_record(record_id, user_id=None, record_access_data=None, raise_exc_on_failure=True)[source]¶
This method evaluates if a user has access to edit a specific record.
Added in version 1.4.0.
- Parameters:
record_id (str) – The ID of the record
user_id (str, None) – The ID of the user to evaluate (defaults to the current/running user if not defined)
record_access_data (dict, None) – The user record access data that has already been retrieved (optional)
raise_exc_on_failure (bool) – Raises an exception rather than returning a
Nonevalue (Trueby default)
- Returns:
Boolean value indicating the access level for the given field
- Raises:
- can_read_record(record_id, user_id=None, record_access_data=None, raise_exc_on_failure=True)[source]¶
This method evaluates if a user has access to read a specific record.
Added in version 1.4.0.
- Parameters:
record_id (str) – The ID of the record
user_id (str, None) – The ID of the user to evaluate (defaults to the current/running user if not defined)
record_access_data (dict, None) – The user record access data that has already been retrieved (optional)
raise_exc_on_failure (bool) – Raises an exception rather than returning a
Nonevalue (Trueby default)
- Returns:
Boolean value indicating the access level for the given field
- Raises:
- check_user_record_access(record_id: str, user_id=None) dict[source]¶
This method checks the Read, Edit, and Delete access for a given record and user.
Added in version 1.4.0.
- Parameters:
- Returns:
Dictionary with Boolean values for
HasReadAccess,HasEditAccess, andHasDeleteAccess- Raises:
RuntimeError,salespyforce.errors.exceptions.APIRequestError
- connect()[source]¶
This method connects to the Salesforce instance to obtain the access token. (Reference)
- Returns:
The API call response with the authorization information
- Raises:
- create_sobject_record(sobject, payload)[source]¶
This method creates a new record for a specific sObject. (Reference)
- Parameters:
- Returns:
The API response from the POST request
- Raises:
- delete(endpoint, params=None, headers=None, timeout=None, show_full_error=True, return_json=True)[source]¶
This method performs a DELETE request against the Salesforce instance. (Reference)
Added in version 1.4.0.
- Parameters:
endpoint (str) – The API endpoint to query
params (dict, None) – The query parameters (where applicable)
headers (dict, None) – Specific API headers to use when performing the API call
timeout (int, None) – The timeout period in seconds (defaults to
30)show_full_error (bool) – Determines if the full error message should be displayed (defaults to
True)return_json – Determines if the response should be returned in JSON format (defaults to
True)
- Returns:
The API response in JSON format or as a
requestsobject- Raises:
TypeError,RuntimeError,salespyforce.errors.exceptions.InvalidURLError
- describe_object(object_name)[source]¶
This method returns the full (describe) information for a specific sObject. (Reference)
- Parameters:
object_name (str) – The name of the Salesforce object
- Returns:
The Salesforce object data
- Raises:
- download_image(image_url, record_id, field_name, file_path=None, sobject=None)[source]¶
This method downloads an image using the sObject Rich Text Image Retrieve functionality. (Reference 1, Reference 2)
- Parameters:
image_url (str) – The URL for the image to be downloaded
record_id (str) – The Record ID where the image is found
field_name (str) – The field name within the record where the image is found
file_path (str, None) – The path to the directory where the image should be saved (current directory if not defined)
sobject (str) – The sObject for the record where the image is found (
Knowledge__kavby default)
- Returns:
The full path to the downloaded image
- Raises:
- get(endpoint, params=None, headers=None, timeout=None, show_full_error=True, return_json=True)[source]¶
This method performs a GET request against the Salesforce instance. (Reference)
Changed in version 1.4.0: A global constant is now leveraged for the API timeout value instead of hardcoding the value. (Timeout is still 30 seconds in this version)
- Parameters:
endpoint (str) – The API endpoint to query
params (dict, None) – The query parameters (where applicable)
headers (dict, None) – Specific API headers to use when performing the API call
timeout (int, None) – The timeout period in seconds (defaults to
30)show_full_error (bool) – Determines if the full error message should be displayed (defaults to
True)return_json – Determines if the response should be returned in JSON format (defaults to
True)
- Returns:
The API response in JSON format or as a
requestsobject- Raises:
TypeError,RuntimeError,salespyforce.errors.exceptions.InvalidURLError
- static get_18_char_id(record_id: str) str[source]¶
This method converts a 15-character Salesforce record ID to its 18-character case-insensitive form.
Added in version 1.4.0.
- Parameters:
record_id (str) – The Salesforce record ID to convert (or return unchanged if already 18 characters)
- Returns:
The 18-character Salesforce record ID
- Raises:
- get_all_sobjects()[source]¶
This method returns a list of all Salesforce objects. (i.e. sObjects) (Reference)
- Returns:
The list of all Salesforce objects
- Raises:
- get_api_versions() list[source]¶
This method returns the API versions for the Salesforce releases. (Reference)
- Returns:
A list containing the API metadata from the
/services/dataendpoint.- Raises:
- get_latest_api_version() str[source]¶
This method returns the latest Salesforce API version by querying the authorized org.
Added in version 1.4.0.
- Returns:
The latest Salesforce API version for the authorized org as a string (e.g.
65.0)
- get_org_limits()[source]¶
This method returns a list of all org limits.
Added in version 1.1.0.
- Returns:
The Salesforce org governor limits data
- Raises:
- get_rest_resources()[source]¶
This method returns a list of all available REST resources. (Reference)
- Returns:
The list of all available REST resources for the Salesforce org
- Raises:
- get_sobject(object_name, describe=False)[source]¶
This method returns basic information or the full (describe) information for a specific sObject. (Reference 1, Reference 2)
- Parameters:
- Returns:
The Salesforce object data
- Raises:
- patch(endpoint, payload, params=None, headers=None, timeout=None, show_full_error=True, return_json=False)[source]¶
This method performs a PATCH call against the Salesforce instance. (Reference)
Changed in version 1.4.0: A global constant is now leveraged for the API timeout value instead of hardcoding the value. (Timeout is still 30 seconds in this version)
- Parameters:
endpoint (str) – The API endpoint to query
payload (dict) – The payload to leverage in the API call
params (dict, None) – The query parameters (where applicable)
headers (dict, None) – Specific API headers to use when performing the API call
timeout (int, None) – The timeout period in seconds (defaults to
30)show_full_error (bool) – Determines if the full error message should be displayed (defaults to
True)return_json – Determines if the response should be returned in JSON format (defaults to
True)
- Returns:
The API response in JSON format or as a
requestsobject- Raises:
TypeError,RuntimeError,ValueError,salespyforce.errors.exceptions.InvalidURLError
- post(endpoint, payload, params=None, headers=None, timeout=None, show_full_error=True, return_json=True)[source]¶
This method performs a POST call against the Salesforce instance. (Reference)
Changed in version 1.4.0: A global constant is now leveraged for the API timeout value instead of hardcoding the value. (Timeout is still 30 seconds in this version)
- Parameters:
endpoint (str) – The API endpoint to query
payload (dict) – The payload to leverage in the API call
params (dict, None) – The query parameters (where applicable)
headers (dict, None) – Specific API headers to use when performing the API call
timeout (int, None) – The timeout period in seconds (defaults to
30)show_full_error (bool) – Determines if the full error message should be displayed (defaults to
True)return_json – Determines if the response should be returned in JSON format (defaults to
True)
- Returns:
The API response in JSON format or as a
requestsobject- Raises:
TypeError,RuntimeError,ValueError,salespyforce.errors.exceptions.InvalidURLError
- put(endpoint, payload, params=None, headers=None, timeout=None, show_full_error=True, return_json=True)[source]¶
This method performs a PUT call against the Salesforce instance. (Reference)
Changed in version 1.4.0: A global constant is now leveraged for the API timeout value instead of hardcoding the value. (Timeout is still 30 seconds in this version)
- Parameters:
endpoint (str) – The API endpoint to query
payload (dict) – The payload to leverage in the API call
params (dict, None) – The query parameters (where applicable)
headers (dict, None) – Specific API headers to use when performing the API call
timeout (int, None) – The timeout period in seconds (defaults to
30)show_full_error (bool) – Determines if the full error message should be displayed (defaults to
True)return_json – Determines if the response should be returned in JSON format (defaults to
True)
- Returns:
The API response in JSON format or as a
requestsobject- Raises:
TypeError,RuntimeError,ValueError,salespyforce.errors.exceptions.InvalidURLError
- retrieve_current_user_info(all_data=False, raise_exc_on_error=False, on_init=False) dict[source]¶
This method retrieves the
userinfodata for the current/running user.Added in version 1.4.0.
- Parameters:
all_data (bool) – Returns all
userinfodata from the API when True instead of only the relevant fields/values (Falseby default)raise_exc_on_error (bool) – Raises an exception if the API retrieval attempt fails when True (
Falseby default)on_init (bool) – Indicates if the method is being called during the core object instantiation (
Falseby default)
- Returns:
The user info data within a dictionary
- Raises:
RuntimeError,salespyforce.errors.exceptions.APIRequestError
- search_string(string_to_search)[source]¶
This method performs a SOSL query to search for a given string. (Reference)
Added in version 1.1.0.
- Parameters:
string_to_search (str) – The string for which to search
- Returns:
The SOSL response data in JSON format
- Raises:
- soql_query(query, replace_quotes=True, next_records_url=False)[source]¶
This method performs a SOQL query and returns the results in JSON format. (Reference 1, Reference 2)
- Parameters:
- Returns:
The result of the SOQL query
- Raises:
Core Module (salespyforce.core)¶
This module contains the core object and functions to establish the connection to the API and leverage it to perform various actions.
- Module:
salespyforce.core
- Synopsis:
This module performs the core Salesforce-related operations
- Usage:
from salespyforce import Salesforce- Example:
sfdc = Salesforce(helper=helper_file_path)- Created By:
Jeff Shurtliff
- Last Modified:
Jeff Shurtliff
- Modified Date:
03 Feb 2026
- class salespyforce.core.Salesforce(connection_info=None, version=None, base_url=None, org_id=None, username=None, password=None, endpoint_url=None, client_id=None, client_secret=None, security_token=None, helper=None)[source]¶
This is the class for the core object leveraged in this module.
- class Chatter(sfdc_object)[source]¶
This class includes methods associated with Salesforce Chatter.
- __init__(sfdc_object)[source]¶
This method initializes the
salespyforce.core.Salesforce.Chatterinner class object.- Parameters:
sfdc_object (class[salespyforce.Salesforce]) – The core
salespyforce.Salesforceobject
- get_group_feed(group_id, site_id=None)[source]¶
This method retrieves a group’s news feed. (Reference)
- Parameters:
- Returns:
The news feed data
- Raises:
- get_my_news_feed(site_id=None)[source]¶
This method retrieves the news feed for the user calling the function. (Reference)
- Parameters:
site_id (str, None) – The ID of an Experience Cloud site against which to query (optional)
- Returns:
The news feed data
- Raises:
- get_user_news_feed(user_id, site_id=None)[source]¶
This method retrieves another user’s news feed. (Reference)
- Parameters:
- Returns:
The news feed data
- Raises:
- post_comment(feed_element_id, message_text=None, message_segments=None, site_id=None, created_by_id=None)[source]¶
This method publishes a comment on a Chatter feed item. (Reference)
- Parameters:
feed_element_id (str) – The ID of the feed element on which to post the comment
message_text – Plaintext to be used as the message body
message_segments (list, None) – Collection of message segments to use instead of a plaintext message
site_id (str, None) – The ID of an Experience Cloud site against which to query (optional)
created_by_id (str, None) – The ID of the user to impersonate (Experimental)
- Returns:
The response of the POST request
- Raises:
- post_feed_item(subject_id, message_text=None, message_segments=None, site_id=None, created_by_id=None)[source]¶
This method publishes a new Chatter feed item. (Reference)
- Parameters:
subject_id (str) – The Subject ID against which to publish the feed item (e.g.
0F9B000000000W2)message_text – Plaintext to be used as the message body
message_segments (list, None) – Collection of message segments to use instead of a plaintext message
site_id (str, None) – The ID of an Experience Cloud site against which to query (optional)
created_by_id (str, None) – The ID of the user to impersonate (Experimental)
- Returns:
The response of the POST request
- Raises:
- class Knowledge(sfdc_object)[source]¶
This class includes methods associated with Salesforce Knowledge.
- __init__(sfdc_object)[source]¶
This method initializes the
salespyforce.core.Salesforce.Knowledgeinner class object.- Parameters:
sfdc_object (class[salespyforce.Salesforce]) – The core
salespyforce.Salesforceobject
- archive_article(article_id)[source]¶
This function archives a published knowledge article. (Reference)
Added in version 1.3.0.
- Parameters:
article_id (str) – The ID of the article to archive
- Returns:
The API response from the POST request
- Raises:
- assign_data_category(article_id, category_group_name, category_name)[source]¶
This method assigns a single data category for a knowledge article. (Reference)
Added in version 1.2.0.
- Parameters:
- Returns:
The API response from the POST request
- Raises:
- check_for_existing_article(title: str, sobject: str | None = None, return_id: bool = False, return_id_and_number: bool = False, include_archived: bool = False)[source]¶
This method checks to see if an article already exists with a given title and returns its article number. (Reference 1. Reference 2)
- Parameters:
title (str) – The title of the knowledge article for which to check
sobject (str, None) – The Salesforce object to query (
Knowledge__kavby default)return_id (bool) – Determines if the Article ID should be returned (
Falseby default)return_id_and_number (bool) – Determines if Article ID and Article Number should be returned (
Falseby default)include_archived (bool) – Determines if archived articles should be included (
Falseby default)
- Returns:
The Article Number, Article ID, or both (if found), or a blank string if not found
- create_article(article_data: dict, sobject: str | None = None, full_response: bool = False)[source]¶
This method creates a new knowledge article draft. (Reference)
- Parameters:
- Returns:
The API response or the ID of the article draft
- Raises:
- create_draft_from_master_version(article_id: str | None = None, knowledge_article_id: str | None = None, article_data: dict | None = None, sobject: str | None = None, full_response: bool = False)[source]¶
This method creates an online version of a master article. (Reference)
- Parameters:
article_id (str, None) – The Article ID from which to create the draft
knowledge_article_id (str, None) – The Knowledge Article ID (
KnowledgeArticleId) from which to create the draftarticle_data (dict, None) – The article data associated with the article from which to create the draft
sobject (str, None) – The Salesforce object to query (
Knowledge__kavby default)full_response (bool) – Determines if the full API response should be returned instead of the article ID (
Falseby default)
- Returns:
The API response or the ID of the article draft
- Raises:
- create_draft_from_online_article(article_id: str, unpublish: bool = False)[source]¶
This method creates a draft knowledge article from an online article. (Reference)
- Parameters:
- Returns:
The API response from the POST request
- Raises:
- delete_article_draft(version_id: str, use_knowledge_management_endpoint: bool = True)[source]¶
This function deletes an unpublished knowledge article draft.
Added in version 1.4.0.
- Parameters:
- Returns:
The API response from the DELETE request
- Raises:
- get_article_details(article_id: str, sobject: str | None = None, use_knowledge_articles_endpoint: bool | None = None)[source]¶
This method retrieves details for a single knowledge article. (Reference)
Changed in version 1.4.0: A logic issue was resolved and the new optional
use_knowledge_articles_endpointparameter can now be set to force theknowledgeArticlesendpoint to be used for the GET request rather than thesobjectsendpoint.- Parameters:
article_id (str) – The Article ID for which to retrieve details
sobject (str, None) – The Salesforce object to query (
Knowledge__kavby default)use_knowledge_articles_endpoint (bool, None) – Optionally use the
knowledgeArticlesendpoint rather thansobjectsto retrieve the article details (Falseby default)
- Returns:
The details for the knowledge article
- Raises:
RuntimeError,salespyforce.errors.exceptions.DataMismatchError
- get_article_id_from_number(article_number, sobject: str | None = None, return_uri: bool = False)[source]¶
This method returns the Article ID when an article number is provided. (Reference 1, Reference 2)
Warning
The ability to retrieve the article URI/URL rather than the ID will be moved to a separate function in a future release.
- Parameters:
- Returns:
The Article ID or Article URI, or a blank string if no article is found
- Raises:
- get_article_metadata(article_id: str) dict[source]¶
This method retrieves metadata for a specific knowledge article. (Reference)
- Parameters:
article_id (str) – The Article ID for which to retrieve details
- Returns:
The article metadata as a dictionary
- Raises:
- get_article_url(article_id: str | None = None, article_number=None, sobject: str | None = None)[source]¶
This function constructs the URL to view a knowledge article in Lightning or Classic.
- Parameters:
- Returns:
The article URL as a string
- Raises:
- get_article_version(article_id: str)[source]¶
This method retrieves the version ID for a given master article ID. (Reference)
- Parameters:
article_id (str) – The Article ID for which to retrieve details
- Returns:
The version ID for the given master article ID
- Raises:
- get_articles_list(query: str | None = None, sort: str | None = None, order: str | None = None, page_size: int = 20, page_num: int = 1) list[source]¶
This method retrieves a list of knowledge articles. (Reference)
- Parameters:
query (str, None) – A SOQL query with which to filter the results (optional)
sort (str, None) – Optionally sort the results with one of the following values:
LastPublishedDate,CreatedDate,Title, orViewScoreorder (str, None) – Optionally define the ORDER BY as
ASCorDESCpage_size (int) – The number of results per page (
20by default)page_num (int) – The starting page number (
1by default)
- Returns:
The list of retrieved knowledge articles
- Raises:
- get_validation_status(article_id: str | None = None, article_details: dict | None = None, sobject: str | None = None) str[source]¶
This method retrieves the Validation Status for a given Article ID. (Reference)
Changed in version 1.4.0: This method now returns an empty string rather than a
Nonevalue if theValidationStatusfield is not found in the article details data, and a more specific exception class is used when input data is missing instead of the genericRuntimeErrorexception class.- Parameters:
- Returns:
The validation status as a text string
- Raises:
RuntimeError,salespyforce.errors.exceptions.MissingRequiredDataError
- publish_article(article_id, major_version=True, full_response=False)[source]¶
This method publishes a draft knowledge article as a major or minor version. (Reference)
- Parameters:
- Returns:
A Boolean value indicating the success of the action or the API response from the PATCH request
- Raises:
- publish_multiple_articles(article_id_list, major_version=True)[source]¶
This method publishes multiple knowledge article drafts at one time. (Reference)
- Parameters:
- Returns:
The API response from the POST request
- Raises:
- update_article(record_id: str, article_data: dict, sobject: str | None = None, include_status_code: bool = False)[source]¶
This method updates an existing knowledge article draft. (Reference)
- Parameters:
record_id (str) – The ID of the article draft record to be updated
article_data (dict) – The article data used to update the article
sobject (str, None) – The Salesforce object to query (
Knowledge__kavby default)include_status_code (bool) – Determines if the API response status code should be returned (
Falseby default)
- Returns:
A Boolean indicating if the update operation was successful, and optionally the API response status code
- Raises:
- __init__(connection_info=None, version=None, base_url=None, org_id=None, username=None, password=None, endpoint_url=None, client_id=None, client_secret=None, security_token=None, helper=None)[source]¶
This method instantiates the core Salesforce object.
Changed in version 1.4.0: The authorized Salesforce org is now queried to determine the latest API version to leverage unless explicitly defined with the
versionparameter when instantiating the object.- Parameters:
connection_info (dict, None) – The information for connecting to the Salesforce instance
version (str, None) – The Salesforce API version to utilize (uses latest version from org if not explicitly defined)
base_url (str, None) – The base URL of the Salesforce instance
org_id (str, None) – The Org ID of the Salesforce instance
username (str, None) – The username of the API user
password (str, None) – The password of the API user
endpoint_url (str, None) – The endpoint URL for the Salesforce instance
client_id (str, None) – The Client ID for the Salesforce instance
client_secret (str, None) – The Client Secret for the Salesforce instance
security_token (str, None) – The Security Token for the Salesforce instance
helper (str, None) – The file path of a helper file
- Returns:
The instantiated object
- Raises:
- api_call_with_payload(method, endpoint, payload, params=None, headers=None, timeout=None, show_full_error=True, return_json=True)[source]¶
This method performs a POST call against the Salesforce instance. (Reference)
Changed in version 1.4.0: A global constant is now leveraged for the API timeout value instead of hardcoding the value. (Timeout is still 30 seconds in this version)
- Parameters:
method (str) – The API method (
post,put, orpatch)endpoint (str) – The API endpoint to query
payload (dict) – The payload to leverage in the API call
params (dict, None) – The query parameters (where applicable)
headers (dict, None) – Specific API headers to use when performing the API call
timeout (int, None) – The timeout period in seconds (defaults to
30)show_full_error (bool) – Determines if the full error message should be displayed (defaults to
True)return_json – Determines if the response should be returned in JSON format (defaults to
True)
- Returns:
The API response in JSON format or as a
requestsobject- Raises:
TypeError,RuntimeError,ValueError,salespyforce.errors.exceptions.InvalidURLError
- can_access_record(access_type, record_id, user_id=None, record_access_data=None, raise_exc_on_failure=True)[source]¶
This method evaluates if a user can access a specific record given the access type.
Added in version 1.4.0.
- Parameters:
access_type (str) – The type of access to evaluate (
read,edit, ordelete)record_id (str) – The ID of the record
user_id (str, None) – The ID of the user to evaluate (defaults to the current/running user if not defined)
record_access_data (dict, None) – The user record access data that has already been retrieved (optional)
raise_exc_on_failure (bool) – Raises an exception rather than returning a
Nonevalue (Trueby default)
- Returns:
Boolean value indicating the access level for the given field
- Raises:
- can_delete_record(record_id, user_id=None, record_access_data=None, raise_exc_on_failure=True)[source]¶
This method evaluates if a user has access to delete a specific record.
Added in version 1.4.0.
- Parameters:
record_id (str) – The ID of the record
user_id (str, None) – The ID of the user to evaluate (defaults to the current/running user if not defined)
record_access_data (dict, None) – The user record access data that has already been retrieved (optional)
raise_exc_on_failure (bool) – Raises an exception rather than returning a
Nonevalue (Trueby default)
- Returns:
Boolean value indicating the access level for the given field
- Raises:
- can_edit_record(record_id, user_id=None, record_access_data=None, raise_exc_on_failure=True)[source]¶
This method evaluates if a user has access to edit a specific record.
Added in version 1.4.0.
- Parameters:
record_id (str) – The ID of the record
user_id (str, None) – The ID of the user to evaluate (defaults to the current/running user if not defined)
record_access_data (dict, None) – The user record access data that has already been retrieved (optional)
raise_exc_on_failure (bool) – Raises an exception rather than returning a
Nonevalue (Trueby default)
- Returns:
Boolean value indicating the access level for the given field
- Raises:
- can_read_record(record_id, user_id=None, record_access_data=None, raise_exc_on_failure=True)[source]¶
This method evaluates if a user has access to read a specific record.
Added in version 1.4.0.
- Parameters:
record_id (str) – The ID of the record
user_id (str, None) – The ID of the user to evaluate (defaults to the current/running user if not defined)
record_access_data (dict, None) – The user record access data that has already been retrieved (optional)
raise_exc_on_failure (bool) – Raises an exception rather than returning a
Nonevalue (Trueby default)
- Returns:
Boolean value indicating the access level for the given field
- Raises:
- check_user_record_access(record_id: str, user_id=None) dict[source]¶
This method checks the Read, Edit, and Delete access for a given record and user.
Added in version 1.4.0.
- Parameters:
- Returns:
Dictionary with Boolean values for
HasReadAccess,HasEditAccess, andHasDeleteAccess- Raises:
RuntimeError,salespyforce.errors.exceptions.APIRequestError
- connect()[source]¶
This method connects to the Salesforce instance to obtain the access token. (Reference)
- Returns:
The API call response with the authorization information
- Raises:
- create_sobject_record(sobject, payload)[source]¶
This method creates a new record for a specific sObject. (Reference)
- Parameters:
- Returns:
The API response from the POST request
- Raises:
- delete(endpoint, params=None, headers=None, timeout=None, show_full_error=True, return_json=True)[source]¶
This method performs a DELETE request against the Salesforce instance. (Reference)
Added in version 1.4.0.
- Parameters:
endpoint (str) – The API endpoint to query
params (dict, None) – The query parameters (where applicable)
headers (dict, None) – Specific API headers to use when performing the API call
timeout (int, None) – The timeout period in seconds (defaults to
30)show_full_error (bool) – Determines if the full error message should be displayed (defaults to
True)return_json – Determines if the response should be returned in JSON format (defaults to
True)
- Returns:
The API response in JSON format or as a
requestsobject- Raises:
TypeError,RuntimeError,salespyforce.errors.exceptions.InvalidURLError
- describe_object(object_name)[source]¶
This method returns the full (describe) information for a specific sObject. (Reference)
- Parameters:
object_name (str) – The name of the Salesforce object
- Returns:
The Salesforce object data
- Raises:
- download_image(image_url, record_id, field_name, file_path=None, sobject=None)[source]¶
This method downloads an image using the sObject Rich Text Image Retrieve functionality. (Reference 1, Reference 2)
- Parameters:
image_url (str) – The URL for the image to be downloaded
record_id (str) – The Record ID where the image is found
field_name (str) – The field name within the record where the image is found
file_path (str, None) – The path to the directory where the image should be saved (current directory if not defined)
sobject (str) – The sObject for the record where the image is found (
Knowledge__kavby default)
- Returns:
The full path to the downloaded image
- Raises:
- get(endpoint, params=None, headers=None, timeout=None, show_full_error=True, return_json=True)[source]¶
This method performs a GET request against the Salesforce instance. (Reference)
Changed in version 1.4.0: A global constant is now leveraged for the API timeout value instead of hardcoding the value. (Timeout is still 30 seconds in this version)
- Parameters:
endpoint (str) – The API endpoint to query
params (dict, None) – The query parameters (where applicable)
headers (dict, None) – Specific API headers to use when performing the API call
timeout (int, None) – The timeout period in seconds (defaults to
30)show_full_error (bool) – Determines if the full error message should be displayed (defaults to
True)return_json – Determines if the response should be returned in JSON format (defaults to
True)
- Returns:
The API response in JSON format or as a
requestsobject- Raises:
TypeError,RuntimeError,salespyforce.errors.exceptions.InvalidURLError
- static get_18_char_id(record_id: str) str[source]¶
This method converts a 15-character Salesforce record ID to its 18-character case-insensitive form.
Added in version 1.4.0.
- Parameters:
record_id (str) – The Salesforce record ID to convert (or return unchanged if already 18 characters)
- Returns:
The 18-character Salesforce record ID
- Raises:
- get_all_sobjects()[source]¶
This method returns a list of all Salesforce objects. (i.e. sObjects) (Reference)
- Returns:
The list of all Salesforce objects
- Raises:
- get_api_versions() list[source]¶
This method returns the API versions for the Salesforce releases. (Reference)
- Returns:
A list containing the API metadata from the
/services/dataendpoint.- Raises:
- get_latest_api_version() str[source]¶
This method returns the latest Salesforce API version by querying the authorized org.
Added in version 1.4.0.
- Returns:
The latest Salesforce API version for the authorized org as a string (e.g.
65.0)
- get_org_limits()[source]¶
This method returns a list of all org limits.
Added in version 1.1.0.
- Returns:
The Salesforce org governor limits data
- Raises:
- get_rest_resources()[source]¶
This method returns a list of all available REST resources. (Reference)
- Returns:
The list of all available REST resources for the Salesforce org
- Raises:
- get_sobject(object_name, describe=False)[source]¶
This method returns basic information or the full (describe) information for a specific sObject. (Reference 1, Reference 2)
- Parameters:
- Returns:
The Salesforce object data
- Raises:
- patch(endpoint, payload, params=None, headers=None, timeout=None, show_full_error=True, return_json=False)[source]¶
This method performs a PATCH call against the Salesforce instance. (Reference)
Changed in version 1.4.0: A global constant is now leveraged for the API timeout value instead of hardcoding the value. (Timeout is still 30 seconds in this version)
- Parameters:
endpoint (str) – The API endpoint to query
payload (dict) – The payload to leverage in the API call
params (dict, None) – The query parameters (where applicable)
headers (dict, None) – Specific API headers to use when performing the API call
timeout (int, None) – The timeout period in seconds (defaults to
30)show_full_error (bool) – Determines if the full error message should be displayed (defaults to
True)return_json – Determines if the response should be returned in JSON format (defaults to
True)
- Returns:
The API response in JSON format or as a
requestsobject- Raises:
TypeError,RuntimeError,ValueError,salespyforce.errors.exceptions.InvalidURLError
- post(endpoint, payload, params=None, headers=None, timeout=None, show_full_error=True, return_json=True)[source]¶
This method performs a POST call against the Salesforce instance. (Reference)
Changed in version 1.4.0: A global constant is now leveraged for the API timeout value instead of hardcoding the value. (Timeout is still 30 seconds in this version)
- Parameters:
endpoint (str) – The API endpoint to query
payload (dict) – The payload to leverage in the API call
params (dict, None) – The query parameters (where applicable)
headers (dict, None) – Specific API headers to use when performing the API call
timeout (int, None) – The timeout period in seconds (defaults to
30)show_full_error (bool) – Determines if the full error message should be displayed (defaults to
True)return_json – Determines if the response should be returned in JSON format (defaults to
True)
- Returns:
The API response in JSON format or as a
requestsobject- Raises:
TypeError,RuntimeError,ValueError,salespyforce.errors.exceptions.InvalidURLError
- put(endpoint, payload, params=None, headers=None, timeout=None, show_full_error=True, return_json=True)[source]¶
This method performs a PUT call against the Salesforce instance. (Reference)
Changed in version 1.4.0: A global constant is now leveraged for the API timeout value instead of hardcoding the value. (Timeout is still 30 seconds in this version)
- Parameters:
endpoint (str) – The API endpoint to query
payload (dict) – The payload to leverage in the API call
params (dict, None) – The query parameters (where applicable)
headers (dict, None) – Specific API headers to use when performing the API call
timeout (int, None) – The timeout period in seconds (defaults to
30)show_full_error (bool) – Determines if the full error message should be displayed (defaults to
True)return_json – Determines if the response should be returned in JSON format (defaults to
True)
- Returns:
The API response in JSON format or as a
requestsobject- Raises:
TypeError,RuntimeError,ValueError,salespyforce.errors.exceptions.InvalidURLError
- retrieve_current_user_info(all_data=False, raise_exc_on_error=False, on_init=False) dict[source]¶
This method retrieves the
userinfodata for the current/running user.Added in version 1.4.0.
- Parameters:
all_data (bool) – Returns all
userinfodata from the API when True instead of only the relevant fields/values (Falseby default)raise_exc_on_error (bool) – Raises an exception if the API retrieval attempt fails when True (
Falseby default)on_init (bool) – Indicates if the method is being called during the core object instantiation (
Falseby default)
- Returns:
The user info data within a dictionary
- Raises:
RuntimeError,salespyforce.errors.exceptions.APIRequestError
- search_string(string_to_search)[source]¶
This method performs a SOSL query to search for a given string. (Reference)
Added in version 1.1.0.
- Parameters:
string_to_search (str) – The string for which to search
- Returns:
The SOSL response data in JSON format
- Raises:
- soql_query(query, replace_quotes=True, next_records_url=False)[source]¶
This method performs a SOQL query and returns the results in JSON format. (Reference 1, Reference 2)
- Parameters:
- Returns:
The result of the SOQL query
- Raises:
- salespyforce.core.compile_connection_info(base_url, org_id, username, password, endpoint_url, client_id, client_secret, security_token)[source]¶
This function compiles the connection info into a dictionary that can be consumed by the core object.
- Parameters:
base_url (str) – The base URL of the Salesforce instance
org_id (str) – The Org ID of the Salesforce instance
username (str) – The username of the API user
password (str) – The password of the API user
endpoint_url (str) – The endpoint URL for the Salesforce instance
client_id (str) – The Client ID for the Salesforce instance
client_secret (str) – The Client Secret for the Salesforce instance
security_token (str) – The Security Token for the Salesforce instance
- Returns:
The connection info in a dictionary
- salespyforce.core.define_connection_info()[source]¶
This function prompts the user for the connection information.
- Returns:
The connection info in a dictionary
Core Functionality Subclasses (salespyforce.core.Salesforce)¶
These classes below are inner/nested classes within the core salespyforce.core.Salesforce class.
Note
The classes themselves are PascalCase format and singular (e.g. Knowledge, etc.) whereas
the names used to call the inner class methods are all lowercase (or snake_case) and plural.
(e.g. core_object.knowledge.check_for_existing_article(), etc.)
Chatter Subclass (salespyforce.core.Salesforce.Chatter)¶
- class Salesforce.Chatter(sfdc_object)[source]
This class includes methods associated with Salesforce Chatter.
- get_group_feed(group_id, site_id=None)[source]
This method retrieves a group’s news feed. (Reference)
- Parameters:
- Returns:
The news feed data
- Raises:
- get_my_news_feed(site_id=None)[source]
This method retrieves the news feed for the user calling the function. (Reference)
- Parameters:
site_id (str, None) – The ID of an Experience Cloud site against which to query (optional)
- Returns:
The news feed data
- Raises:
- get_user_news_feed(user_id, site_id=None)[source]
This method retrieves another user’s news feed. (Reference)
- Parameters:
- Returns:
The news feed data
- Raises:
- post_comment(feed_element_id, message_text=None, message_segments=None, site_id=None, created_by_id=None)[source]
This method publishes a comment on a Chatter feed item. (Reference)
- Parameters:
feed_element_id (str) – The ID of the feed element on which to post the comment
message_text – Plaintext to be used as the message body
message_segments (list, None) – Collection of message segments to use instead of a plaintext message
site_id (str, None) – The ID of an Experience Cloud site against which to query (optional)
created_by_id (str, None) – The ID of the user to impersonate (Experimental)
- Returns:
The response of the POST request
- Raises:
- post_feed_item(subject_id, message_text=None, message_segments=None, site_id=None, created_by_id=None)[source]
This method publishes a new Chatter feed item. (Reference)
- Parameters:
subject_id (str) – The Subject ID against which to publish the feed item (e.g.
0F9B000000000W2)message_text – Plaintext to be used as the message body
message_segments (list, None) – Collection of message segments to use instead of a plaintext message
site_id (str, None) – The ID of an Experience Cloud site against which to query (optional)
created_by_id (str, None) – The ID of the user to impersonate (Experimental)
- Returns:
The response of the POST request
- Raises:
Knowledge Subclass (salespyforce.core.Salesforce.Knowledge)¶
- class Salesforce.Knowledge(sfdc_object)[source]
This class includes methods associated with Salesforce Knowledge.
- archive_article(article_id)[source]
This function archives a published knowledge article. (Reference)
Added in version 1.3.0.
- Parameters:
article_id (str) – The ID of the article to archive
- Returns:
The API response from the POST request
- Raises:
- assign_data_category(article_id, category_group_name, category_name)[source]
This method assigns a single data category for a knowledge article. (Reference)
Added in version 1.2.0.
- Parameters:
- Returns:
The API response from the POST request
- Raises:
- check_for_existing_article(title: str, sobject: str | None = None, return_id: bool = False, return_id_and_number: bool = False, include_archived: bool = False)[source]
This method checks to see if an article already exists with a given title and returns its article number. (Reference 1. Reference 2)
- Parameters:
title (str) – The title of the knowledge article for which to check
sobject (str, None) – The Salesforce object to query (
Knowledge__kavby default)return_id (bool) – Determines if the Article ID should be returned (
Falseby default)return_id_and_number (bool) – Determines if Article ID and Article Number should be returned (
Falseby default)include_archived (bool) – Determines if archived articles should be included (
Falseby default)
- Returns:
The Article Number, Article ID, or both (if found), or a blank string if not found
- create_article(article_data: dict, sobject: str | None = None, full_response: bool = False)[source]
This method creates a new knowledge article draft. (Reference)
- Parameters:
- Returns:
The API response or the ID of the article draft
- Raises:
- create_draft_from_master_version(article_id: str | None = None, knowledge_article_id: str | None = None, article_data: dict | None = None, sobject: str | None = None, full_response: bool = False)[source]
This method creates an online version of a master article. (Reference)
- Parameters:
article_id (str, None) – The Article ID from which to create the draft
knowledge_article_id (str, None) – The Knowledge Article ID (
KnowledgeArticleId) from which to create the draftarticle_data (dict, None) – The article data associated with the article from which to create the draft
sobject (str, None) – The Salesforce object to query (
Knowledge__kavby default)full_response (bool) – Determines if the full API response should be returned instead of the article ID (
Falseby default)
- Returns:
The API response or the ID of the article draft
- Raises:
- create_draft_from_online_article(article_id: str, unpublish: bool = False)[source]
This method creates a draft knowledge article from an online article. (Reference)
- Parameters:
- Returns:
The API response from the POST request
- Raises:
- delete_article_draft(version_id: str, use_knowledge_management_endpoint: bool = True)[source]
This function deletes an unpublished knowledge article draft.
Added in version 1.4.0.
- Parameters:
- Returns:
The API response from the DELETE request
- Raises:
- get_article_details(article_id: str, sobject: str | None = None, use_knowledge_articles_endpoint: bool | None = None)[source]
This method retrieves details for a single knowledge article. (Reference)
Changed in version 1.4.0: A logic issue was resolved and the new optional
use_knowledge_articles_endpointparameter can now be set to force theknowledgeArticlesendpoint to be used for the GET request rather than thesobjectsendpoint.- Parameters:
article_id (str) – The Article ID for which to retrieve details
sobject (str, None) – The Salesforce object to query (
Knowledge__kavby default)use_knowledge_articles_endpoint (bool, None) – Optionally use the
knowledgeArticlesendpoint rather thansobjectsto retrieve the article details (Falseby default)
- Returns:
The details for the knowledge article
- Raises:
RuntimeError,salespyforce.errors.exceptions.DataMismatchError
- get_article_id_from_number(article_number, sobject: str | None = None, return_uri: bool = False)[source]
This method returns the Article ID when an article number is provided. (Reference 1, Reference 2)
Warning
The ability to retrieve the article URI/URL rather than the ID will be moved to a separate function in a future release.
- Parameters:
- Returns:
The Article ID or Article URI, or a blank string if no article is found
- Raises:
- get_article_metadata(article_id: str) dict[source]
This method retrieves metadata for a specific knowledge article. (Reference)
- Parameters:
article_id (str) – The Article ID for which to retrieve details
- Returns:
The article metadata as a dictionary
- Raises:
- get_article_url(article_id: str | None = None, article_number=None, sobject: str | None = None)[source]
This function constructs the URL to view a knowledge article in Lightning or Classic.
- Parameters:
- Returns:
The article URL as a string
- Raises:
- get_article_version(article_id: str)[source]
This method retrieves the version ID for a given master article ID. (Reference)
- Parameters:
article_id (str) – The Article ID for which to retrieve details
- Returns:
The version ID for the given master article ID
- Raises:
- get_articles_list(query: str | None = None, sort: str | None = None, order: str | None = None, page_size: int = 20, page_num: int = 1) list[source]
This method retrieves a list of knowledge articles. (Reference)
- Parameters:
query (str, None) – A SOQL query with which to filter the results (optional)
sort (str, None) – Optionally sort the results with one of the following values:
LastPublishedDate,CreatedDate,Title, orViewScoreorder (str, None) – Optionally define the ORDER BY as
ASCorDESCpage_size (int) – The number of results per page (
20by default)page_num (int) – The starting page number (
1by default)
- Returns:
The list of retrieved knowledge articles
- Raises:
- get_validation_status(article_id: str | None = None, article_details: dict | None = None, sobject: str | None = None) str[source]
This method retrieves the Validation Status for a given Article ID. (Reference)
Changed in version 1.4.0: This method now returns an empty string rather than a
Nonevalue if theValidationStatusfield is not found in the article details data, and a more specific exception class is used when input data is missing instead of the genericRuntimeErrorexception class.- Parameters:
- Returns:
The validation status as a text string
- Raises:
RuntimeError,salespyforce.errors.exceptions.MissingRequiredDataError
- publish_article(article_id, major_version=True, full_response=False)[source]
This method publishes a draft knowledge article as a major or minor version. (Reference)
- Parameters:
- Returns:
A Boolean value indicating the success of the action or the API response from the PATCH request
- Raises:
- publish_multiple_articles(article_id_list, major_version=True)[source]
This method publishes multiple knowledge article drafts at one time. (Reference)
- Parameters:
- Returns:
The API response from the POST request
- Raises:
- update_article(record_id: str, article_data: dict, sobject: str | None = None, include_status_code: bool = False)[source]
This method updates an existing knowledge article draft. (Reference)
- Parameters:
record_id (str) – The ID of the article draft record to be updated
article_data (dict) – The article data used to update the article
sobject (str, None) – The Salesforce object to query (
Knowledge__kavby default)include_status_code (bool) – Determines if the API response status code should be returned (
Falseby default)
- Returns:
A Boolean indicating if the update operation was successful, and optionally the API response status code
- Raises: