How to bulk export and import test case attachments?

Tracia Almeida 40 Reputation points
2025-03-24T02:44:59.25+00:00

Hi There,

Here's our scenario

We have 350 test cases each with one attachment. These exist in our internal ADO project.

We would like to bulk export these test cases and their attachments and import them into our client's ADO.

The end result should be that the test cases should have their relevant attachments linked in the new client ADO.

I am aware that we can use Inherited process to bulk export the test cases to maintain their parent/child linkages.
But after we get the test cases into the new ADO, how do we then bulk export and import the attachments associated with those test cases from our ADO to the clients ADO?

Cheers,

Azure DevOps
0 comments No comments
{count} votes

Accepted answer
  1. Bodapati Harish 320 Reputation points Microsoft External Staff
    2025-03-26T12:48:19.2933333+00:00

    Hello @Tracia Almeida ,

    Azure DevOps doesn't offer a built-in way to bulk export and import test case attachments. you already have your test cases exported with their parent/child relationships intact, you'll need to handle the attachments separately using the REST APIs.

    First, for each test case in your internal ADO, you can retrieve its details with a GET API call. This call returns a JSON response that includes a "relations" section containing any attachment links. For example, you’d use:

     GET https://dev.azure.com/{organization}/{project}/_apis/wit/workitems/{workItemId}?api-version=6.0

    Once you have those links, you can download each attachment. Use the following API endpoint to download the file:

     GET https://dev.azure.com/{organization}/{project}/_apis/wit/attachments/{attachmentId}?api-version=6.0

    Save these files locally or in a temporary storage area.

    After you've imported the test cases into your client's ADO project, you need to upload the attachments there. Upload each file using this endpoint:

     POST https://dev.azure.com/{organization}/{project}/_apis/wit/attachments?fileName={filename}&api-version=6.0

    This call returns a new URL for the attachment in the client’s environment.

    The final step is to update each test case in the client's project so that its attachment link points to the new URL. You can do this with a PATCH request. Here’s an example of JSON Patch payload that updates the attachment URL:

    [
    
      {
    
        "op": "replace",
    
        "path": "/relations/0/url",
    
        "value": "https://dev.azure.com/{newOrg}/{newProject}/_apis/wit/attachments/{newAttachmentId}?api-version=6.0"
    
      }
    
    ]
    

    In this example, the "0" represents the index of the attachment in the "relations" array—adjust it as necessary based on your work item structure.

    Because you’re dealing with 350 test cases, automating these steps with a script (using PowerShell, Python, etc.)

    • Retrieve each test case’s details to extract the attachment links,
    • Download each attachment,
    • Upload them to the client’s project to obtain new URLs,
    • And update the test cases to reference these new attachment links.

    This approach ensures that all your test cases in the client's ADO have their relevant attachments properly linked. Hope it helps!


    Please do not forget to click "Accept the answer” and Yes wherever the information provided helps you, this can be beneficial to other community members.

    If you have any other questions or still running into more issues, let me know in the "comments" and I would be happy to help you.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.