Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bulk Job Retrieval Error #52

Open
bob-koertge opened this issue Feb 22, 2020 · 5 comments
Open

Bulk Job Retrieval Error #52

bob-koertge opened this issue Feb 22, 2020 · 5 comments

Comments

@bob-koertge
Copy link

When trying to retrieve a bulk job file, this error is being generated:
Traceback (most recent call last): File "marketo.py", line 18, in <module> export_file_contents = mc.execute(method='get_leads_export_job_file', job_id='9e1f342e-9365-4173-8818-ec1971079f72') File "/mnt/d/code/marketo/lib/python3.8/site-packages/marketorestpython/client.py", line 273, in execute result = method_map[method](*args, **kargs) File "/mnt/d/code/marketo/lib/python3.8/site-packages/marketorestpython/client.py", line 4956, in get_leads_export_job_file return self._export_job_state_machine('leads', 'file', *args, **kargs) File "/mnt/d/code/marketo/lib/python3.8/site-packages/marketorestpython/client.py", line 4953, in _export_job_state_machine return result['result'] TypeError: 'Response' object is not subscriptable

Any Ideas?

@jepcastelein
Copy link
Owner

jepcastelein commented Feb 22, 2020 via email

@phil-epl
Copy link

Hi @jepcastelein , I am using version 0.5.8 and I am getting the above error as well.

I tried modifying the _export_job_state_machine method to return result instead of return result['result'] to see what would happen and the response was a 404. Below is the printout from the unmodified version.

You can see that the create_leads_export_job, enqueue_leads_export_job, get_leads_export_job_status methods are all working fine, the only thing throwing an error is the get_leads_export_job_file method.

[{'exportId': '46a1178f-223c-4ce7-80b0-f278a5a91533', 'format': 'CSV', 'status': 'Created', 'createdAt': '2021-01-22T16:41:51Z'}]
[{'exportId': '46a1178f-223c-4ce7-80b0-f278a5a91533', 'format': 'CSV', 'status': 'Queued', 'createdAt': '2021-01-22T16:41:51Z', 'queuedAt': '2021-01-22T16:41:52Z'}]
[{'exportId': '46a1178f-223c-4ce7-80b0-f278a5a91533', 'format': 'CSV', 'status': 'Queued', 'createdAt': '2021-01-22T16:41:51Z', 'queuedAt': '2021-01-22T16:41:52Z'}]
Traceback (most recent call last):
  File "/home/phil-epl/code/ES_MarketoSmartlist_AudienceUpload/ES_Fetch_MarketoSmartList/fetch_mkto_list.py", line 33, in <module>
    export_file_contents = mc.execute(method='get_leads_export_job_file', job_id=new_export_job_details[0]['exportId'])
  File "/home/phil-epl/code/ES_MarketoSmartlist_AudienceUpload/env/lib/python3.8/site-packages/marketorestpython/client.py", line 292, in execute
    result = method_map[method](*args, **kargs)
  File "/home/phil-epl/code/ES_MarketoSmartlist_AudienceUpload/env/lib/python3.8/site-packages/marketorestpython/client.py", line 5179, in get_leads_export_job_file
    return self._export_job_state_machine('leads', 'file', *args, **kargs)
  File "/home/phil-epl/code/ES_MarketoSmartlist_AudienceUpload/env/lib/python3.8/site-packages/marketorestpython/client.py", line 5176, in _export_job_state_machine
    return result['result']
TypeError: 'Response' object is not subscriptable

@jepcastelein
Copy link
Owner

@phil-epl I think the problem is that you're getting a 404 on the get_leads_export_job_file method because the file isn't there yet, the status is still queued. We could probably tweak the error handling for this situation, but as soon as the file is available, this method should work okay.

if state == 'file' and result.status_code == 200:
    return result.content
return result['result']

So in your case the state == 'file' but the status_code is not 200.

@jepcastelein jepcastelein reopened this Jan 22, 2021
@phil-epl
Copy link

So what do you think would be the right way of making the "get data" part of the process wait until the file is available?

new_export_job_details = mc.execute(method='create_leads_export_job', 
                                    fields=['email'] 
                                    ,filters={'smartListId': '10131936'})

#enqueue a job
enqueued_job_details = mc.execute(method='enqueue_leads_export_job', job_id=new_export_job_details[0]['exportId'])

#check job status
export_job_status = mc.execute(method='get_leads_export_job_status', job_id=new_export_job_details[0]['exportId'])

# get data
export_file_contents = mc.execute(method='get_leads_export_job_file', job_id=new_export_job_details[0]['exportId'])

@jepcastelein
Copy link
Owner

jepcastelein commented Jan 22, 2021

@phil-epl yes, you need to poll the status until it says "completed" https://developers.marketo.com/rest-api/bulk-extract/bulk-lead-extract/#polling_job_status

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants