0

I am trying to create a query with python using a IN clause :

def sf_api_call(action, parameters = {}, method = 'get', data = {}, keys = {}): # pylint: disable=dangerous-default-value
"""
Helper function to make calls to Salesforce REST API.
Parameters: action (the URL), URL params, method (get, post or patch), data for POST/PATCH.
"""
session = requests.Session()
retry = Retry(connect = 3, backoff_factor = 0.5)
adapter = HTTPAdapter(max_retries = retry)
session.mount('http://', adapter)
session.mount('https://', adapter)

headers = {
    'Content-type': 'application/json',
    'Accept-Encoding': 'gzip',
    'Authorization': 'Bearer ' + keys['access_token']
}
if method == 'get':
    #r = requests.request(method, keys['instance_url']+action, headers=headers, params=parameters, timeout=500) #pylint: disable=line-too-long, invalid-name
    r = session.get(keys['instance_url']+action, headers=headers, params=parameters, timeout=500)
#elif method in ['post', 'patch']:
elif method == 'post':
    #r = requests.request(method, keys['instance_url']+action, headers=headers, json=data, params=parameters, timeout=500) #pylint: disable=line-too-long, invalid-name
    r = session.post(keys['instance_url']+action, headers=headers, json=data, params=parameters, timeout=500)
elif method == 'patch':
    r = session.patch(keys['instance_url']+action, headers=headers, json=data, params=parameters, timeout=500) #pylint: disable=line-too-long, invalid-name
else:
    # other methods not implemented in this example
    raise ValueError('Method should be get or post or patch.')
print('Debug: API %s call: %s' % (method, r.url) ) #pylint: disable=consider-using-f-string
if r.status_code < 300: #pylint: disable=no-else-return
    if method=='patch':
        return None
    return r.json()
else:
    raise Exception('API error when calling %s : %s %s' % (r.url, r.content, r)) #pylint: disable=consider-using-f-string

COMMENT_IDS = ",".join(f"'{w}'" for w in lst_ids)
get_comments = sf_api_call('/services/data/v53.0/query/', {
               'q': 'SELECT Id, Name, frm_LastModifiedDate__c, frm_ExternalCommentId__c, frm_ExternalCommentReplyId__c, frm_ExtenalTopicId__c, frm_Topic__c,  frm_MigrationFlag__c, LastModifiedDate, frm_CommentBodyValue__c '+ 
                f'FROM frm_Post__c WHERE frm_ExternalCommentId__c IN ({COMMENT_IDS})'
                }, keys = keys)

But I notice that the result only shows 250 records. I check the same query with the Query editor and retrieve 629.

Note: I check that the credentials are from the same org.

I would like to know what happened

1
  • 1
    Please edit to show us what sf_api_call does.
    – David Reed
    Commented Nov 2, 2022 at 20:41

1 Answer 1

1

I noticed that I made the GET call retrieved an key with the name nextRecordsUrl and the key done was in false. I have to create another call to retrieve the rest of the records but with the nextRecordsURL endpoint to retrieve the rest of them.

When the response doesn't show the key and the key done is in true, the records are completed.

1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .