# There was a problem in creating a paired read collection using API

**URL:** <https://help.galaxyproject.org/t/there-was-a-problem-in-creating-a-paired-read-collection-using-api/11655>\
**Category:** Uncategorized\
**Tags:** devops-bioblend-api\
**Created:** [February 4, 2024, 3:02pm UTC](https://help.galaxyproject.org/t/there-was-a-problem-in-creating-a-paired-read-collection-using-api/11655 "2024-02-04T15:02:13Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![chenqiang](https://avatars.discourse-cdn.com/v4/letter/c/e36b37/32.png) [@chenqiang](https://help.galaxyproject.org/u/chenqiang)\
**Post date:** [February 4, 2024, 3:02pm UTC](https://help.galaxyproject.org/t/there-was-a-problem-in-creating-a-paired-read-collection-using-api/11655/1 "2024-02-04T15:02:13Z")

</div>

Hello, I am very anxious, please help, thank you, I am using bioblend to connect to the usegalaxy API, my workflow input is Collection of paired reads.When a paired collection is generated, it is found that there are 2 paireds instead of 1 pair, which causes the input of Collection of paired reads to be unable to connect.Part of my python code is as follows:  
dataset\_1 = gi.tools.upload\_file(Input1\_forward, history\_id=history\_id, file\_type=‘fastqsanger.gz’)  
dataset\_1\_id = dataset\_1[‘outputs’][0][‘id’]

dataset\_2 = gi.tools.upload\_file(Input1\_reverse, history\_id=history\_id, file\_type=‘fastqsanger.gz’)  
dataset\_2\_id = dataset\_2[‘outputs’][0][‘id’]

collection\_payload = {  
‘collection\_type’: ‘list:paired’,  
‘name’: ‘Paired Collection’,  
‘element\_identifiers’: [{‘name’: ‘forward’, ‘src’: ‘hda’, ‘id’: dataset\_1\_id},  
{‘name’: ‘reverse’, ‘src’: ‘hda’, ‘id’: dataset\_2\_id}]  
}

uploaded\_collection = gi.histories.create\_dataset\_collection(history\_id, collection\_payload)

inputs = {  
‘input1’: {‘src’: ‘hdca’, ‘id’: uploaded\_collection[‘id’], ‘name’: ‘Collection of paired reads’, ‘format’: ‘fastqsanger.gz’,  
‘paired’: True}  
}

workflow\_id = ‘c0d6e75e9e3f9763’  
invocation = gi.workflows.invoke\_workflow(workflow\_id, inputs=inputs)  
gi.workflows.wait\_for\_invocation(invocation[‘id’])

 ![735f2f3e354706a1e82859854c3cf48](https://us1.discourse-cdn.com/flex020/uploads/galaxy/original/2X/f/f3f3998c952d52bd52d8d7781d90cfba783ec6c0.png)  
 ![bc2ac3548d2c87ea0ebe30bb62c97f4](https://us1.discourse-cdn.com/flex020/uploads/galaxy/original/2X/5/551bb6f0e4b000671f8a71f942a20627282ddc6c.png)  
 ![1289723717fcfde4ecd233a639db8ed](https://us1.discourse-cdn.com/flex020/uploads/galaxy/original/2X/6/654276e863a222c295cb63dd32a079bb7f6527ce.png)

---

<div class="post-metadata">

**Author:** ![mvdbeek](https://sea2.discourse-cdn.com/flex020/user_avatar/help.galaxyproject.org/mvdbeek/32/110_2.png) [@mvdbeek](https://help.galaxyproject.org/u/mvdbeek)\
**Post date:** [February 5, 2024, 6:46pm UTC](https://help.galaxyproject.org/t/there-was-a-problem-in-creating-a-paired-read-collection-using-api/11655/2 "2024-02-05T18:46:10Z")

</div>

I’m sorry, it’s not quite clear what the problem is you’re encountering.

---

<div class="post-metadata">

**Author:** ![chenqiang](https://avatars.discourse-cdn.com/v4/letter/c/e36b37/32.png) [@chenqiang](https://help.galaxyproject.org/u/chenqiang)\
**Post date:** [February 6, 2024, 4:15am UTC](https://help.galaxyproject.org/t/there-was-a-problem-in-creating-a-paired-read-collection-using-api/11655/3 "2024-02-06T04:15:51Z")

</div>

Hello, I am trying to create a Collection of paired reads using the API. However, when I attempt to create it with a pair of paired-end data, I noticed that it is being uploaded as a list with 2 pairs. As a result, I am unable to proceed with the “Collection of paired reads” step. Could you please assist me in resolving this issue?

---

<div class="post-metadata">

**Author:** ![mvdbeek](https://sea2.discourse-cdn.com/flex020/user_avatar/help.galaxyproject.org/mvdbeek/32/110_2.png) [@mvdbeek](https://help.galaxyproject.org/u/mvdbeek)\
**Post date:** [February 6, 2024, 7:35am UTC](https://help.galaxyproject.org/t/there-was-a-problem-in-creating-a-paired-read-collection-using-api/11655/4 "2024-02-06T07:35:44Z")

</div>

You’ve created a list:paired collection, if your workflow input is a list:paired or paired input this should just work. Make sure this works correctly with a manually built collection just to make sure you’ve correctly set the data type and that your workflow input accepts list:paired collections

---

<div class="post-metadata">

**Author:** ![chenqiang](https://avatars.discourse-cdn.com/v4/letter/c/e36b37/32.png) [@chenqiang](https://help.galaxyproject.org/u/chenqiang)\
**Post date:** [February 6, 2024, 10:45am UTC](https://help.galaxyproject.org/t/there-was-a-problem-in-creating-a-paired-read-collection-using-api/11655/5 "2024-02-06T10:45:01Z")

</div>

Thank you for your reply.I use the api of bioblend, and the’ collection\_type’ is’ list:paired’. Isn’t it right?Why is the Paired Collection a list with 2 pairs instead of a list with 1 pair after my data is uploaded? My workflow input is Collection of paired reads, but I can’t upload a list with 1 pair. If I use the UI of usegalaxy, I can build A list with 1 pair and upload it to the workflow. Part of my code is as follows:

```
history_name = 'MetaWin Results'
history_id = gi.histories.create_history(name=history_name)['id']

dataset_1 = gi.tools.upload_file(Input1_forward, history_id=history_id, file_type='fastqsanger.gz')
dataset_1_id = dataset_1['outputs'][0]['id']

dataset_2 = gi.tools.upload_file(Input1_reverse, history_id=history_id, file_type='fastqsanger.gz')
dataset_2_id = dataset_2['outputs'][0]['id']

collection_payload = {
    'collection_type': 'list:paired',
    'name': 'Paired Collection',
    'element_identifiers': [{'name': 'forward', 'src': 'hda', 'id': dataset_1_id},
                            {'name': 'reverse', 'src': 'hda', 'id': dataset_2_id}]
}

uploaded_collection = gi.histories.create_dataset_collection(history_id, collection_payload)

inputs = {
    'input1': {'src': 'hdca', 'id': uploaded_collection['id'], 'name': 'Collection of paired reads', 'format': 'fastqsanger.gz',
               'paired': True}
}

workflow_id = 'c0d6e75e9e3f9763'  
invocation = gi.workflows.invoke_workflow(workflow_id, inputs=inputs)
gi.workflows.wait_for_invocation(invocation['id'])

```

 ![945d0cface6fb16e0e85ac49a7a45bd](https://us1.discourse-cdn.com/flex020/uploads/galaxy/original/2X/d/dc18b119c1fbec09db6bbfba896c76c7cd025eec.png)

---

<div class="post-metadata">

**Author:** ![mvdbeek](https://sea2.discourse-cdn.com/flex020/user_avatar/help.galaxyproject.org/mvdbeek/32/110_2.png) [@mvdbeek](https://help.galaxyproject.org/u/mvdbeek)\
**Post date:** [February 6, 2024, 1:28pm UTC](https://help.galaxyproject.org/t/there-was-a-problem-in-creating-a-paired-read-collection-using-api/11655/6 "2024-02-06T13:28:19Z")

</div>

Oh, I see, it’s cause you’re not providing the elements for a nested collection.

Your collection payload should look something like:

```auto
{
    'collection_type': 'list:paired',
    'name': 'Paired Collection',
    'element_identifiers': [
        {
            'collection_type': 'paired',
            'name': 'first_element',
            'src': 'new_collection',
            'element_identifiers': [
                {
                     'name': 'forward', 
                     'src': 'hda',
                     'id': dataset_1_id
                }, {
                    'name': 
                    'reverse',
                    'src': 'hda',
                    'id': dataset_2_id
                }
            ]
        }
    ]
}

```

---

<div class="post-metadata">

**Author:** ![chenqiang](https://avatars.discourse-cdn.com/v4/letter/c/e36b37/32.png) [@chenqiang](https://help.galaxyproject.org/u/chenqiang)\
**Post date:** [February 6, 2024, 3:23pm UTC](https://help.galaxyproject.org/t/there-was-a-problem-in-creating-a-paired-read-collection-using-api/11655/7 "2024-02-06T15:23:25Z")

</div>

Hi!This problem has been solved. Thank you very much.But I encountered another problem, which was displayed at runtime:  
Traceback (most recent call last):  
File “C:\Users\dongge\AppData\Local\Programs\Python\Python311\Lib\site-packages\bioblend\galaxyclient.py”, line 196, in make\_post\_request  
raise ConnectionError(  
bioblend.ConnectionError: Unexpected HTTP status code: 400: {“err\_msg”: “Workflow cannot be run because input step ‘6952123’ (Collection of paired reads) is not optional and no input provided.”, “err\_code”: 0}

Part of my code is as follows:  
history\_name = ‘MetaWin Results’  
history\_id = gi.histories.create\_history(name=history\_name)[‘id’]

```
dataset_1 = gi.tools.upload_file(Input1_forward, history_id=history_id, file_type='fastqsanger.gz')
dataset_1_id = dataset_1['outputs'][0]['id']

dataset_2 = gi.tools.upload_file(Input1_reverse, history_id=history_id, file_type='fastqsanger.gz')
dataset_2_id = dataset_2['outputs'][0]['id']

collection_payload = {
    'collection_type': 'list:paired',
    'name': 'Paired Collection',
    'element_identifiers': [
        {
            'collection_type': 'paired',
            'name': 'first_element',
            'src': 'new_collection',
            'element_identifiers': [
                {
                    'name': 'forward',
                    'src': 'hda',
                    'id': dataset_1_id
                }, {
                    'name':'reverse',
                    'src': 'hda',
                    'id': dataset_2_id
                }
            ]
        }
    ]
}

uploaded_collection = gi.histories.create_dataset_collection(history_id, collection_payload)

inputs = {
    'input1': {'src': 'hdca', 'id': uploaded_collection['id'], 'name': 'Collection of paired reads', 'format': 'fastqsanger.gz',
               'paired': True}
}

workflow_id = '1aa75989b24978e3'  
invocation = gi.workflows.invoke_workflow(workflow_id, inputs=inputs)
gi.workflows.wait_for_invocation(invocation['id'])

```

---

<div class="post-metadata">

**Author:** ![chenqiang](https://avatars.discourse-cdn.com/v4/letter/c/e36b37/32.png) [@chenqiang](https://help.galaxyproject.org/u/chenqiang)\
**Post date:** [February 7, 2024, 5:32am UTC](https://help.galaxyproject.org/t/there-was-a-problem-in-creating-a-paired-read-collection-using-api/11655/8 "2024-02-07T05:32:52Z")

</div>

This error occurs at runtime:  
Traceback (most recent call last):  
File “C:\Users\dongge\PycharmProjects\宏基因组分析\meta.py”, line 83, in   
main()  
File “C:\Users\dongge\AppData\Local\Programs\Python\Python311\Lib\site-packages\gooey\python\_bindings\gooey\_decorator.py”, line 134, in   
return lambda \*args, \*\*kwargs: func(\*args, \*\*kwargs)  
^^^^^^^^^^^^^^^^^^^^^  
File “C:\Users\dongge\PycharmProjects\宏基因组分析\meta.py”, line 79, in main  
invocation = gi.workflows.invoke\_workflow(workflow\_id, inputs=inputs)  
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  
File “C:\Users\dongge\AppData\Local\Programs\Python\Python311\Lib\site-packages\bioblend\galaxy\workflows\__init_\_.py”, line 494, in invoke\_workflow  
return self.\_post(payload, url=url)  
^^^^^^^^^^^^^^^^^^^^^^^^^^^^  
File “C:\Users\dongge\AppData\Local\Programs\Python\Python311\Lib\site-packages\bioblend\galaxy\client.py”, line 169, in \_post  
return self.gi.make\_post\_request(url, payload=payload, files\_attached=files\_attached)  
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  
File “C:\Users\dongge\AppData\Local\Programs\Python\Python311\Lib\site-packages\bioblend\galaxyclient.py”, line 196, in make\_post\_request  
raise ConnectionError(  
bioblend.ConnectionError: Unexpected HTTP status code: 400: {“err\_msg”: “Workflow cannot be run because input step ‘6952123’ (Collection of paired reads) is not optional and no input provided.”, “err\_code”: 0}

---

<div class="post-metadata">

**Author:** ![chenqiang](https://avatars.discourse-cdn.com/v4/letter/c/e36b37/32.png) [@chenqiang](https://help.galaxyproject.org/u/chenqiang)\
**Post date:** [February 7, 2024, 7:01am UTC](https://help.galaxyproject.org/t/there-was-a-problem-in-creating-a-paired-read-collection-using-api/11655/9 "2024-02-07T07:01:14Z")

</div>

Furthermore, I encountered another error:

During handling of the above exception, another exception occurred:  
Traceback (most recent call last):  
File “C:\Users\dongge\PycharmProjects\宏基因组分析\meta.py”, line 83, in   
main()  
File “C:\Users\dongge\AppData\Local\Programs\Python\Python311\Lib\site-packages\gooey\python\_bindings\gooey\_decorator.py”, line 134, in   
return lambda \*args, \*\*kwargs: func(\*args, \*\*kwargs)  
^^^^^^^^^^^^^^^^^^^^^  
File “C:\Users\dongge\PycharmProjects\宏基因组分析\meta.py”, line 42, in main  
dataset\_1 = gi.tools.upload\_file(Input1\_forward, history\_id=history\_id, file\_type=‘fastqsanger.gz’)  
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  
File “C:\Users\dongge\AppData\Local\Programs\Python\Python311\Lib\site-packages\bioblend\galaxy\tools\__init_\_.py”, line 497, in upload\_file  
uploader.upload()  
File “C:\Users\dongge\AppData\Local\Programs\Python\Python311\Lib\site-packages\tusclient\uploader\uploader.py”, line 45, in upload  
self.upload\_chunk()  
File “C:\Users\dongge\AppData\Local\Programs\Python\Python311\Lib\site-packages\tusclient\uploader\uploader.py”, line 59, in upload\_chunk  
self.\_do\_request()  
File “C:\Users\dongge\AppData\Local\Programs\Python\Python311\Lib\site-packages\tusclient\uploader\uploader.py”, line 88, in \_do\_request  
self.\_retry\_or\_cry(error)  
File “C:\Users\dongge\AppData\Local\Programs\Python\Python311\Lib\site-packages\tusclient\uploader\uploader.py”, line 102, in \_retry\_or\_cry  
raise error  
File “C:\Users\dongge\AppData\Local\Programs\Python\Python311\Lib\site-packages\tusclient\uploader\uploader.py”, line 85, in \_do\_request  
self.request.perform()  
File “C:\Users\dongge\AppData\Local\Programs\Python\Python311\Lib\site-packages\tusclient\request.py”, line 92, in perform  
raise TusUploadFailed(error)  
tusclient.exceptions.TusUploadFailed: HTTPSConnectionPool(host=‘[usegalaxy.org](http://usegalaxy.org)’, port=443): Max retries exceeded with url: /api/upload/resumable\_upload/f354effc64c89aa22689da415ea96f78 (Caused by SSLError(SSLEOFError(8, ‘EOF occurred in violation of protocol (\_ssl.c:2423)’)))

---

<div class="post-metadata">

**Author:** ![mvdbeek](https://sea2.discourse-cdn.com/flex020/user_avatar/help.galaxyproject.org/mvdbeek/32/110_2.png) [@mvdbeek](https://help.galaxyproject.org/u/mvdbeek)\
**Post date:** [February 7, 2024, 11:22am UTC](https://help.galaxyproject.org/t/there-was-a-problem-in-creating-a-paired-read-collection-using-api/11655/10 "2024-02-07T11:22:29Z")

</div>

Please have a look at [API documentation for interacting with Galaxy — BioBlend 1.2.0 documentation](https://bioblend.readthedocs.io/en/latest/api_docs/galaxy/all.html#module-bioblend.galaxy.workflows), you’re providing an input for `input1`, which is not the step index.  
It should probably be

```auto
inputs = {
    'Collection of paired reads': {'src': 'hdca', 'id': uploaded_collection['id']}
}

```

and then set inputs\_by to label.

---

<div class="post-metadata">

**Author:** ![mvdbeek](https://sea2.discourse-cdn.com/flex020/user_avatar/help.galaxyproject.org/mvdbeek/32/110_2.png) [@mvdbeek](https://help.galaxyproject.org/u/mvdbeek)\
**Post date:** [February 7, 2024, 11:24am UTC](https://help.galaxyproject.org/t/there-was-a-problem-in-creating-a-paired-read-collection-using-api/11655/11 "2024-02-07T11:24:17Z")

</div>

I’d also recommend taking a look at [Running Galaxy workflows — Planemo 0.75.20 documentation](https://planemo.readthedocs.io/en/latest/running.html#workflow-execution-against-an-external-galaxy) which provides this functionality at a higher level.

---

<div class="post-metadata">

**Author:** ![chenqiang](https://avatars.discourse-cdn.com/v4/letter/c/e36b37/32.png) [@chenqiang](https://help.galaxyproject.org/u/chenqiang)\
**Post date:** [February 7, 2024, 11:59am UTC](https://help.galaxyproject.org/t/there-was-a-problem-in-creating-a-paired-read-collection-using-api/11655/12 "2024-02-07T11:59:42Z")

</div>

Hi!That’s not right either。My workflow only has one input: Collection of paired reads.

 ![99ef896ca827fcca51ff9a107a40607](https://us1.discourse-cdn.com/flex020/uploads/galaxy/original/2X/5/5e8319d6f709c0c08c55cba166e25099fb7c15d5.png)

dataset\_1 = gi.tools.upload\_file(Input1\_forward, history\_id=history\_id, file\_type=‘fastqsanger.gz’)  
dataset\_1\_id = dataset\_1[‘outputs’][0][‘id’]

```
dataset_2 = gi.tools.upload_file(Input1_reverse, history_id=history_id, file_type='fastqsanger.gz')
dataset_2_id = dataset_2['outputs'][0]['id']

collection_payload = {
    'collection_type': 'list:paired',
    'name': 'Paired Collection',
    'element_identifiers': [
        {
            'collection_type': 'paired',
            'name': 'first_element',
            'src': 'new_collection',
            'element_identifiers': [
                {
                    'name': 'forward',
                    'src': 'hda',
                    'id': dataset_1_id
                }, {
                    'name':'reverse',
                    'src': 'hda',
                    'id': dataset_2_id
                }
            ]
        }
    ]
}

uploaded_collection = gi.histories.create_dataset_collection(history_id, collection_payload)
inputs = {
    'Collection of paired reads': {'src': 'hdca', 'id': uploaded_collection['id'], 'inputs_by': 'Collection of paired reads'}
}

workflow_id = '1aa75989b24978e3'
invocation = gi.workflows.invoke_workflow(workflow_id, inputs=inputs)
gi.workflows.wait_for_invocation(invocation['id'])

```

---

<div class="post-metadata">

**Author:** ![mvdbeek](https://sea2.discourse-cdn.com/flex020/user_avatar/help.galaxyproject.org/mvdbeek/32/110_2.png) [@mvdbeek](https://help.galaxyproject.org/u/mvdbeek)\
**Post date:** [February 7, 2024, 12:13pm UTC](https://help.galaxyproject.org/t/there-was-a-problem-in-creating-a-paired-read-collection-using-api/11655/13 "2024-02-07T12:13:02Z")

</div>

If you compare this with the documentation you’ll see that you’re not setting the parameters correctly.

```auto
inputs = {
    'Collection of paired reads': {'src': 'hdca', 'id': uploaded_collection['id']}
}

workflow_id = '1aa75989b24978e3'
invocation = gi.workflows.invoke_workflow(workflow_id, inputs=inputs, inputs_by="name")

```

---

<div class="post-metadata">

**Author:** ![chenqiang](https://avatars.discourse-cdn.com/v4/letter/c/e36b37/32.png) [@chenqiang](https://help.galaxyproject.org/u/chenqiang)\
**Post date:** [February 7, 2024, 2:51pm UTC](https://help.galaxyproject.org/t/there-was-a-problem-in-creating-a-paired-read-collection-using-api/11655/14 "2024-02-07T14:51:35Z")

</div>

Oh,thank you for your reply.God bless you.I successfully run the workflow. I want to wait until the workflow is finished and my project is finished.But I found that gi. workflows.wait\_for\_invocation doesn’t seem to exist.

---

<div class="post-metadata">

**Author:** ![mvdbeek](https://sea2.discourse-cdn.com/flex020/user_avatar/help.galaxyproject.org/mvdbeek/32/110_2.png) [@mvdbeek](https://help.galaxyproject.org/u/mvdbeek)\
**Post date:** [February 7, 2024, 3:06pm UTC](https://help.galaxyproject.org/t/there-was-a-problem-in-creating-a-paired-read-collection-using-api/11655/15 "2024-02-07T15:06:33Z")

</div>

What I’d suggest is first polling using show\_invocation until the state is scheduled, and then wait for the job states using [API documentation for interacting with Galaxy — BioBlend 1.2.0 documentation](https://bioblend.readthedocs.io/en/latest/api_docs/galaxy/all.html#bioblend.galaxy.jobs.JobsClient.get_jobs) and passing the invocation\_id to filter for jobs belonging to your invocation.

---

<div class="post-metadata">

**Author:** ![chenqiang](https://avatars.discourse-cdn.com/v4/letter/c/e36b37/32.png) [@chenqiang](https://help.galaxyproject.org/u/chenqiang)\
**Post date:** [February 11, 2024, 2:03pm UTC](https://help.galaxyproject.org/t/there-was-a-problem-in-creating-a-paired-read-collection-using-api/11655/20 "2024-02-11T14:03:46Z")

</div>

What should I do if I want to download the results generated by workflow to the local area? Do you have any good suggestions? What should my code example be?

---

<div class="post-metadata">

**Author:** ![mvdbeek](https://sea2.discourse-cdn.com/flex020/user_avatar/help.galaxyproject.org/mvdbeek/32/110_2.png) [@mvdbeek](https://help.galaxyproject.org/u/mvdbeek)\
**Post date:** [February 12, 2024, 9:16am UTC](https://help.galaxyproject.org/t/there-was-a-problem-in-creating-a-paired-read-collection-using-api/11655/21 "2024-02-12T09:16:26Z")

</div>

You can look at the outputs of your invocation (as shown by `show_invocation`) and download them as you would any other dataset, or you could trigger an invocation export. Still, you seem to be replicating `planemo run` functionality, I’d really recommend that you look into this.

---

<div class="post-metadata">

**Author:** ![chenqiang](https://avatars.discourse-cdn.com/v4/letter/c/e36b37/32.png) [@chenqiang](https://help.galaxyproject.org/u/chenqiang)\
**Post date:** [February 13, 2024, 5:12pm UTC](https://help.galaxyproject.org/t/there-was-a-problem-in-creating-a-paired-read-collection-using-api/11655/22 "2024-02-13T17:12:04Z")

</div>

Hi!I’m sorry to bother you again. It’s true that I have a problem.I tried to use this api document.But not detailed enough.I only saw show \_ invocation (invocation \_ id: str) → dict [str, any].There is still an error in my code.Can you help me revise it? Or be more specific?Thank you very much indeed.Here is my code:

# …

def poll\_invocation(invocation\_id):  
while True:  
invocation\_details = gi.invocations.show\_invocation(invocation\_id)  
invocation\_state = invocation\_details[‘state’]  
if invocation\_state == ‘scheduled’:  
break  
time.sleep(5) # Wait for 5 seconds before polling again

def wait\_for\_jobs(invocation\_id):  
while True:  
jobs = gi.invocations.get\_invocation\_jobs(invocation\_id)  
all\_jobs\_completed = all(job[‘state’] == ‘ok’ for job in jobs)  
if all\_jobs\_completed:  
break  
time.sleep(5) # Wait for 5 seconds before checking again

```
invocation_id = invocation['id']

# Poll the invocation status until it is scheduled
poll_invocation(invocation_id)

# Wait for all jobs to complete
wait_for_jobs(invocation_id)

# Get the workflow invocation details
invocation_details = gi.invocations.show_invocation(invocation_id)

# Retrieve the output datasets
output_datasets = invocation_details['output_datasets']

# Download the output datasets
for dataset in output_datasets:
    dataset_id = dataset['id']
    dataset_name = dataset['name']
    output_path = os.path.join(output_dir, dataset_name)
    gi.datasets.download_dataset(dataset_id, file_path=output_path)

```

---

<div class="post-metadata">

**Author:** ![jennaj](https://sea2.discourse-cdn.com/flex020/user_avatar/help.galaxyproject.org/jennaj/32/27_2.png) [@jennaj](https://help.galaxyproject.org/u/jennaj)\
**Post date:** [April 2, 2026, 8:03pm UTC](https://help.galaxyproject.org/t/there-was-a-problem-in-creating-a-paired-read-collection-using-api/11655/24 "2026-04-02T20:03:46Z")

</div>


