# Use Variable in Multipart Form-Data Attachment

**URL:** <https://community.postman.com/t/use-variable-in-multipart-form-data-attachment/29973>\
**Category:** Help Hub\
**Tags:** variables, attachment, multipart\
**Created:** [November 22, 2021, 4:40pm UTC](https://community.postman.com/t/use-variable-in-multipart-form-data-attachment/29973 "2021-11-22T16:40:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![atepe](https://avatars.discourse-cdn.com/v4/letter/a/8e7dd6/32.png) [@atepe](https://community.postman.com/u/atepe)\
**Post date:** [November 22, 2021, 4:40pm UTC](https://community.postman.com/t/use-variable-in-multipart-form-data-attachment/29973/1 "2021-11-22T16:40:03Z")

</div>

In a POST, I need to pass a pdf file and a JSON file to tell the application some details about the pdf file. One of the properties is an environment variable “ParticipantID” that I receive in a previous call:

```auto
{
  "executionType": "E-Sign",
  "name": "Retail Installment Contract2",
  "order": 1,
  "participants": [
    {
      "participantUid": "{{ParticipantID}}",
      "required": true
    }
  ]
}

```

I want to just use the “{{ParticipantID}}” notation in the attachment so that I don’t have to update this file every time I run my collection but this doesn’t seem to work.

I’m following this enhancement request which would probably fix this:

> <https://github.com/postmanlabs/postman-app-support/issues/10327>
>
> \### Is there an existing request for this feature?
> 
> \- \[X\] I have searched the ex…isting issues for this feature request
> 
> \### Is your feature request related to a problem?
> 
> I need to use a value from an API response in my next API request. The trick is that the request is a multi-part message with an XML attachment, and the value from the response must be placed inside the XML file.
> 
> Many of the API calls I make in the QA testing of my company's product require XML attachments and are thus multi-part messages. Postman allows for file attachments, but what it seemingly cannot do is dynamically populate an environment variable value in a Postman file attachment.
> 
> A tangible example: I create a transaction in my first API call and a transaction ID is returned in the response. I have no problem taking the transaction ID from response #1 and placing it an environment variable, and I know how to use the environment variable in subsequent calls by placing my variable in the Body as form-data. But, I cannot take my transaction ID and use it inside XML that is an attachment to my API call. If I put a variable in the XML file (e.g., transactionSid="{{tSid}}") I receive an error when I call the API.
> 
> I recently posed this problem as a question on Stackoverflow: https://stackoverflow.com/questions/69165679/how-to-dynamically-populate-an-environment-variable-value-in-a-postman-attachmen
> 
> The answer offered is beyond my current technical ability, but in any case the solution seems somewhat cumbersome considering how many API tests I would need to implement this solution for.
> 
> ReadyAPI has the ability to handle this scenario fairly gracefully, and I really wish Postman could, too. This is the single-largest hurdle for me to switching to use Postman as my primary API testing tool.
> 
> \### Describe the solution you'd like
> 
> The ideal solution would be to make it possible to use environment variables in an XML attachment that would be populated at run-time.
> 
> \### Describe alternatives you've considered
> 
> I received an answer to my question on Stackoverflow. I may yet attempt to use this solution, but it is beyond my current technical ability and also seems more complicated than it should be. ReadyAPI solves for this scenario in a user-friendly way.
> 
> https://stackoverflow.com/questions/69165679/how-to-dynamically-populate-an-environment-variable-value-in-a-postman-attachmen
> 
> \### Additional context
> 
> \_No response\_

I’ve also looked on stackoverflow and there seem to be some pretty complicated ways (at least for me) where instead of actually attaching a file in Postman, I could submit a string of data and use a variable there.

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/9/6/96a7d028595a3d964f0f6f300812e0e108035f1c.png)

I’m certainly doing several things wrong in the screenshot above, but the variable doesn’t seem to be recognized and I think there are other things I need to do for this JSON object to be compatible with the multipart format.

If I can’t use the variable notation in the attachment, could I dynamically set the value in the attachment if it’s in my working directory? Or could I convert my attachment to a text string and use a variable there?

Knowing that there’s an enhancement request for this, wondering if anyone has suggestions on workarounds in the meantime.

Thank you!

---

<div class="post-metadata">

**Author:** ![atepe](https://avatars.discourse-cdn.com/v4/letter/a/8e7dd6/32.png) [@atepe](https://community.postman.com/u/atepe)\
**Post date:** [January 21, 2022, 5:41pm UTC](https://community.postman.com/t/use-variable-in-multipart-form-data-attachment/29973/2 "2022-01-21T17:41:22Z")

</div>

It turns out that Postman has very simple support for this, but the option I needed to make this work was just in a hidden column in the multipart form-data page.

**What worked for me:**

1. Expose the “Content Type” Column in form-data and set to application/json  

2. Change the “file” option next to the KEY to “text” and then paste the raw JSON in the VALUE  

…Of course it would be as simple as exposing a hidden column 🙂
