Skip to main content

Attach Files to a Test Step Using JSON (API)

Send a file as Base64 in a JSON request using the Test Run number, Jira space key, and step number or script type.

Attach a file to an existing Test Run step by sending its contents as Base64 inside a JSON request. Base64 represents the file’s bytes as text so they can be included in JSON.

If your tool can upload local files directly, use Attach Files to a Test Step for the multipart form-data workflow.

Endpoint

Action

Method

Endpoint

Attach a Base64-encoded file using JSON

POST

/api/v2/testRun/attachment

Add the endpoint path to your Vansah base URL.

Before you begin

  • Create a Vansah API token with Jira access configured for the workspace containing the run.

  • Have an existing Test Run and the step or script log that should receive the file. Use Record a Test Step Result to check or record its outcome.

  • For a run shown as DEMO-TR248, send run number 248 and Jira space key DEMO in separate fields.

The cURL example uses Bash. Set VANSAH_URL to your Vansah base URL without a trailing slash and VANSAH_TOKEN to your API token. Replace the sample space, run number, step, filename, and encoded file contents with your values.

1. Prepare a complete JSON request

Endpoint: POST /api/v2/testRun/attachment

This valid example attaches a small text file to step 1 of run DEMO-TR248. Save it as step-attachment.json:

{
"projectKey": "DEMO",
"testRunKey": "248",
"testStep": 1,
"attachments": [
{
"name": "login-result",
"extension": "txt",
"file": "TG9naW4gcmV0dXJuZWQgYW4gZXJyb3IuCg=="
}
]
}

The sample Base64 value decodes to Login returned an error. followed by a newline. It is a complete text file. Replace it with the Base64 contents of the file you want to upload.

Parent object

JSON field

Type

Example value

Use

Request body

projectKey

String

"DEMO"

Required with the run number. The Jira space key.

Request body

testRunKey

String

"248"

Required. The numeric portion of the Test Run key, as a JSON string.

Request body

testStep

Integer

1

Required for a Multi Steps run. The step must already have a log in this run.

The attachments array holds one object per file. Add another object to the array for each additional file. Each object uses these exact keys:

Parent object

JSON field

Type

Example value

Use

attachments[]

name

String

"login-result"

Required. Base filename without the extension.

attachments[]

extension

String

"txt"

Required. File extension without a leading period, matching the actual file.

attachments[]

file

Base64 string

"TG9naW4gcmV0dXJuZWQgYW4gZXJyb3IuCg=="

Required. The encoded file contents, without a data-URL prefix.

projectKey refers to the Jira space key. These are flat request fields; there is no nested project object in this upload request.

2. Encode your own file

Endpoint: POST /api/v2/testRun/attachment

Encode the file’s bytes as Base64. Put that output in the attachment’s file field. Do not put a local path, URL, or a prefix such as data:image/png;base64, in that field.

For example, PowerShell can encode a local screenshot:

$attachmentBytes = [System.IO.File]::ReadAllBytes('C:\test-results\login-failure.png')
[Convert]::ToBase64String($attachmentBytes)

Copy the generated text into the JSON file and set the attachment name and extension to match your screenshot. Keep the complete JSON valid: use double quotes, and do not add comments or trailing commas.

3. Send the JSON request

Endpoint: POST /api/v2/testRun/attachment

curl --request POST \
--url "$VANSAH_URL/api/v2/testRun/attachment" \
--header "Authorization: $VANSAH_TOKEN" \
--header "Content-Type: application/json" \
--header "Accept: application/json" \
--data-binary @step-attachment.json

Header

Value

Authorization

Your Vansah API token directly, without a Bearer prefix.

Content-Type

application/json

Accept

application/json

Run the command from the directory containing step-attachment.json. In Postman, use POST, add the same headers, and choose Body → raw → JSON before pasting the complete request.

Base64 adds to the request size. The JSON parser is configured for a complete request up to 100 MiB, including all encoded files and the JSON structure. For direct file uploads, use the multipart workflow and follow its separate file and request limits.

Example: upload to a script log

Endpoint: POST /api/v2/testRun/attachment

For a BDD run, use the script type in place of the step number. Save this complete body as step-attachment.json and use the same cURL command:

{
"projectKey": "DEMO",
"testRunKey": "249",
"scriptType": "Bdd",
"attachments": [
{
"name": "checkout-result",
"extension": "txt",
"file": "Q2hlY2tvdXQgZmFpbGVkLgo="
}
]
}

Parent object

JSON field

Type

Example value

Use

Request body

scriptType

String

"plainText"

Use for a Plain Text run instead of testStep.

Request body

scriptType

String

"Bdd"

Use for a BDD run instead of testStep.

Request body

scriptType

String

"automation"

Use for an Automation run instead of testStep.

Send one location selector: testStep for Multi Steps, or scriptType for the other formats. The sample report decodes to Checkout failed. followed by a newline.

Check that the script log exists. If a matching Plain Text, BDD, or Automation run has no log, this endpoint can attach the file to the run itself. Omitting both the step number and script type also creates a run-level attachment.

Read the response

Endpoint: POST /api/v2/testRun/attachment

A successful request returns HTTP 200. This example uses a synthetic URL:

{
"success": true,
"message": "Test Run Attachment(s) created successfully.",
"data": {
"attachments": [
"https://attachments.example.com/login-result.txt"
]
}
}

Check JSON path data.attachments for a nonempty URL for each expected file. Open the Test Run in Vansah and verify the file appears under the intended step or script log. Check saved attachments before retrying to avoid duplicates.

Errors and troubleshooting

HTTP status

Meaning

400

Invalid JSON, invalid Base64 or fields, missing run or step log, script mismatch, oversized JSON body, empty attachment array, or an upload-processing failure.

401

Missing, invalid, expired, or inactive token, or the token is not configured for Jira access.

403

The account is blocked during authorization.

A missing or invalid step can return:

{
"success": false,
"message": "Please provide a valid Test Step Number",
"data": [],
"errorCode": 1306
}

Issue

What to check

Validation errors

Read the field messages under JSON path data.errors. An error code is not present on every response.

Invalid Base64

Encode the full file and remove any data-URL prefix. Keep the encoded value on one JSON string line.

Run not found

Use the numeric run portion as a string and the correct Jira space key.

Step not found

Confirm that the selected run has an existing log for that step.

File appears at run level

Include the intended testStep or scriptType and confirm its log exists.

Empty returned URL or processing failure

Check whether any attachment was saved before retrying. Contact Vansah Support with the request and response after removing your token and file contents if the problem continues.

Did this answer your question?