harshanas / ZamzarConverter

Allows you to convert Files from Command Line by using Zamzar APIs
3 stars 0 forks source link

File download ID causes HTTP 404 #1

Closed whyleyc closed 3 years ago

whyleyc commented 3 years ago

It looks like there is an error in the code to kick off the download of a converted file:

https://github.com/harshanas/ZamzarConverter/blob/f65fa8593b29c52510e01fbe541082b31752877a/convert.py#L67

The code here uses a /job/ID to initiate a file download, whereas a file ID should be used instead. Using the Job ID would cause an HTTP 404 error to be thrown.

The file ID can be found by querying the /job/ID endpoint for a job with a status of successful and interrogating the target_files array. For example in the response below we can see that the file ID to use for download would be 3:

{
    "id" : 15,
    "key" : "GiVUYsF4A8ssq93FR48H",
    "status" : "successful",
    "sandbox" : true,
    "created_at" : "2013-10-27T13:41:00Z",
    "finished_at" : "2013-10-27T13:41:13Z",
    "source_file" : {"id":2,"name":"portrait.gif","size":90571},
    "target_files" : [{"id":3,"name":"portrait.png","size":15311}],
    "target_format" : "png",
    "credit_cost" : 1
}

You may wish to modify the script to have a routine to check the job status before trying to find the file ID, like this:

def check_job(id):
    print ("Checking if job is finished")
    endpoint = "https://sandbox.zamzar.com/v1/jobs/{}".format(job_id)
    response = requests.get(endpoint, auth=HTTPBasicAuth(api_key, ''))
    return json.loads(json.dumps(response.json()))

job_status = ""
job_details = ""
while job_status != "successful" :
     job_details = check_job(job_id)
     job_status = (job_details['status'])
     print (job_status)
     time.sleep(2) 
     if job_status == "successful" :
    break

file_id = (job_details['target_files'][0]['id'])

...

If you would like to chat further let me know, I'm one of the lead developers for the Zamzar API.

harshanas commented 3 years ago

First of all, thanks for figuring this out. I'd like to chat about this further. So, we can have a better understanding of this. :)

whyleyc commented 3 years ago

@harshanas Sure - what questions do you have?

harshanas commented 3 years ago

I fixed the issue you mentioned. Thanks again for figuring this out :) Hope this will help someone.