Bulk Program Member Import - Not All Members are uploading
Utilizing the Marketo API - I have been attempting to upload program members via the bulk method. This seems to fail 30% of the time with not all members uploading to a specific program (randomly only 10/4000 people will upload). This made me think that I should probably add in logic to make sure the task job has a status of "Completed" before proceeding to the next upload. However, I am not sure what the syntax should look like and am at a loss.
Below is my code:
---------------------------------------------------------------------------------------------------------------------------------------------
def import_program_members(program_id, host, endpoint, program_status, access_token, file, filepath, log_id):
try:
args = {
'access_token': access_token,
'format': 'csv',
'programId': str(program_id),
'programMemberStatus': program_status,
'programStatus': 'completed'
}
with open(filepath, 'rb') as oFile:
files = {'file': (file, oFile, 'text/path')}
resp = requests.post(host + endpoint, params=args, files=files)
result = resp.json()
batchid = result['result'][0]['batchId']
status = result['result'][0]['status']
print(batchid)
while status == 'Queued':
endpoint1 = '/bulk/v1/program/members/import/' + str(batchid) + '/status.json'
args = {
'access_token': access_token,
'batchId': str(batchid)
}
resp = requests.get(host + endpoint1, params=args)
print(resp)
---------------------------------------------------------------------------------------------------------------------------
The arguments required in the documentation suggest it only needs batchId but that does not seem to work....nor does solely utilizing the endpoint1 (in the code).
Note: the host is utilized in other portions of the code without fail.