Introduction
This article is part of a broader series covering the Salesforce API in depth. In this guide, we focus specifically on how to retrieve open tickets (Cases) using the Salesforce API.
If you’re building reporting workflows, customer support dashboards, or syncing ticket data into external systems, accessing open Cases programmatically is essential. This guide walks through prerequisites, authentication, querying open tickets for all customers, querying for a specific customer, common pitfalls, and key FAQs.
For a comprehensive deep dive into CRM API authentication, rate limits, and other use cases, refer to the complete Salesforce guide here.
Prerequisites
Before making API calls, ensure the following:
- Your Salesforce organization is enabled for API access.
- The user has the “API Enabled” permission.
- The user has necessary object-level and field-level permissions to access the Case object.
- You have the Salesforce API endpoint URL and authentication credentials:
- Client ID
- Client Secret
- Username
- Password
- Security Token
API Endpoints
- Authentication Endpoint
https://login.salesforce.com/services/oauth2/token - Query Cases Endpoint
https://yourInstance.salesforce.com/services/data/vXX.X/query/
Replace vXX.X with the API version you are using.
Step-by-Step Process
1. Authenticate with Salesforce
import requests
def authenticate(client_id, client_secret, username, password, security_token):
url = 'https://login.salesforce.com/services/oauth2/token'
payload = {
'grant_type': 'password',
'client_id': client_id,
'client_secret': client_secret,
'username': username,
'password': password + security_token
}
response = requests.post(url, data=payload)
if response.status_code == 200:
return response.json()['access_token'], response.json()['instance_url']
else:
raise Exception('Authentication failed: ' + response.text)This function returns:
access_token– required for authorized API callsinstance_url– your Salesforce instance-specific base URL
2. Query Open Tickets for All Customers
def get_open_tickets(access_token, instance_url):
query = "SELECT Id, Subject, Status FROM Case WHERE Status = 'Open'"
headers = {
'Authorization': 'Bearer ' + access_token
}
url = instance_url + '/services/data/vXX.X/query/'
params = {'q': query}
response = requests.get(url, headers=headers, params=params)
if response.status_code == 200:
return response.json()['records']
else:
raise Exception('Query failed: ' + response.text)This retrieves all Cases where the status is Open.
3. Query Open Tickets for One Customer
def get_open_tickets_for_customer(access_token, instance_url, customer_id):
query = f"SELECT Id, Subject, Status FROM Case WHERE Status = 'Open' AND AccountId = '{customer_id}'"
headers = {
'Authorization': 'Bearer ' + access_token
}
url = instance_url + '/services/data/vXX.X/query/'
params = {'q': query}
response = requests.get(url, headers=headers, params=params)
if response.status_code == 200:
return response.json()['records']
else:
raise Exception('Query failed: ' + response.text)This filters open Cases for a specific AccountId.
Common Pitfalls
When integrating with the Salesforce API to retrieve open tickets, teams often run into avoidable issues. Watch out for the following:
- Incorrect API endpoint URL – Using the wrong instance URL or incorrect API version.
- Invalid authentication credentials – Incorrect client credentials, password, or missing security token.
- Insufficient user permissions – Lack of access to the Case object or required fields.
- Incorrect SOQL syntax – Small query errors can result in failed requests.
- API version mismatch – Using deprecated or unsupported API versions.
- Rate limits exceeded – Salesforce enforces API limits based on edition and license type.
- Network connectivity issues – Timeouts or firewall restrictions can disrupt requests.
Proactively validating credentials, permissions, and API versions significantly reduces integration failures.
Frequently Asked Questions
1. What is the API limit for Salesforce?
Salesforce imposes limits based on the edition and license type of your organization.
2. How do I find my Salesforce instance URL?
It is returned in the authentication response after a successful login.
3. Can I use the API to update ticket statuses?
Yes, provided the user has appropriate permissions to update Case records.
4. What happens if my security token changes?
You must update your application with the new security token.
5. How do I handle API errors?
Check the response status code and inspect the error message returned in the response body.
6. Is there a way to test API calls?
Yes. Tools such as Postman can be used to test authentication and query endpoints.
7. Can I access closed tickets?
Yes. Modify the SOQL query to include closed statuses or remove the status filter.
Knit for Salesforce API Integration
For quick and seamless access to the Salesforce API, Knit API offers a convenient solution. By integrating with Knit once, you can streamline the entire process. Knit handles authentication, authorization, and ongoing integration maintenance.
This approach reduces engineering overhead, saves implementation time, and ensures a reliable connection to Salesforce without managing API complexity directly.




