# Tests OK in Postman but KO in newman?

**URL:** <https://community.postman.com/t/tests-ok-in-postman-but-ko-in-newman/31954>\
**Category:** Help Hub\
**Tags:** newman-project\
**Created:** [January 27, 2022, 3:10pm UTC](https://community.postman.com/t/tests-ok-in-postman-but-ko-in-newman/31954 "2022-01-27T15:10:01Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Legaly-esignature](https://avatars.discourse-cdn.com/v4/letter/l/f05b48/32.png) [@Legaly-esignature](https://community.postman.com/u/Legaly-esignature)\
**Post date:** [January 27, 2022, 3:10pm UTC](https://community.postman.com/t/tests-ok-in-postman-but-ko-in-newman/31954/1 "2022-01-27T15:10:01Z")

</div>

Hello to the Postman community 🙂,

Here I run into a concern about using newman on a test campaign I created in postman. Indeed in some of my test scenarios I test the upload of a pdf file. The POST requests that handle upload all return status 201 in Postman as I see fit.

In newman, however, some of these requests return a 415, as if the format was not supported by the API.

I tried to run a `newman run mycollection.json --verbose` to try to see the contents of the headers, but it did not give anything. Impossible to visualize the headers.

 ![Capture d’écran du 2022-01-27 16-04-21](https://us1.discourse-cdn.com/getpostman/original/2X/1/1bb48e4e27020d6ff7dc44cc77e27eeab4a73664.png)

Here are the headers and more specifically the Content-Type on the Postman side:

 ![Capture d’écran du 2022-01-27 11-30-28](https://us1.discourse-cdn.com/getpostman/original/2X/a/a68498c206aa56ecabffb97e8fb1718a23b5e2f2.png)

My environment and my collection are up to date. My OS is ubuntu 20.04.  
I don’t understand why the API returns the correct status (201) in Postman and not in newman

I am at your disposal for more information

Thanks

---

<div class="post-metadata">

**Author:** ![w4dd325](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/w4dd325/32/12436_2.png) [@w4dd325](https://community.postman.com/u/w4dd325)\
**Post date:** [January 28, 2022, 11:05am UTC](https://community.postman.com/t/tests-ok-in-postman-but-ko-in-newman/31954/2 "2022-01-28T11:05:02Z")

</div>

I’d guess from looking at the output (no such file), that you need to express the **full** file path for the PDF.

eg; /tmp/Postman/filename.pdf

---

<div class="post-metadata">

**Author:** ![Legaly-esignature](https://avatars.discourse-cdn.com/v4/letter/l/f05b48/32.png) [@Legaly-esignature](https://community.postman.com/u/Legaly-esignature)\
**Post date:** [January 28, 2022, 7:11pm UTC](https://community.postman.com/t/tests-ok-in-postman-but-ko-in-newman/31954/3 "2022-01-28T19:11:01Z")

</div>

Hello @w4dd325,

Thank you so much, you put me on the path.  
Indeed the paths of my files were incorrect in my json collection file.

I don’t understand how this is possible. I was careful to update the export of my collection. I had to change the path by hand in the collection file (22,000 lines…). I didn’t find any other way. But it works now.

---

<div class="post-metadata">

**Author:** ![w4dd325](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/w4dd325/32/12436_2.png) [@w4dd325](https://community.postman.com/u/w4dd325)\
**Post date:** [January 28, 2022, 11:02pm UTC](https://community.postman.com/t/tests-ok-in-postman-but-ko-in-newman/31954/4 "2022-01-28T23:02:03Z")

</div>

Could you not throw your collection.json file into Notepad++ and do a find and replace?

Or even throw it back in Postman and add the filename as a variable so you only have to change it in 1 location?

Just a thought. Glad it’s working for you now!! 🙃

---

<div class="post-metadata">

**Author:** ![Legaly-esignature](https://avatars.discourse-cdn.com/v4/letter/l/f05b48/32.png) [@Legaly-esignature](https://community.postman.com/u/Legaly-esignature)\
**Post date:** [January 29, 2022, 11:12am UTC](https://community.postman.com/t/tests-ok-in-postman-but-ko-in-newman/31954/5 "2022-01-29T11:12:38Z")

</div>

Thanks for your answer @w4dd325 ,

Indeed I used ctrl+f to find each “src”, then I pasted the right path. Otherwise I’m interested in the second option you describe. But how do I create a variable with file names? For now I will search for the files in my working directory, then add them to the body of the request.

 ![Capture d’écran du 2022-01-29 12-12-10](https://us1.discourse-cdn.com/getpostman/original/3X/7/3/73f894599fcc5cba30d77b6fd67432c07d23b71f.png)

---

<div class="post-metadata">

**Author:** ![w4dd325](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/w4dd325/32/12436_2.png) [@w4dd325](https://community.postman.com/u/w4dd325)\
**Post date:** [January 31, 2022, 2:15pm UTC](https://community.postman.com/t/tests-ok-in-postman-but-ko-in-newman/31954/6 "2022-01-31T14:15:14Z")

</div>

I have not done it myself but there is a discussion about it [here](https://community.postman.com/t/newman-run-with-relative-file-paths-in-form-data-for-file-upload/16069).

Hope it helps.

---

<div class="post-metadata">

**Author:** ![Whersh](https://avatars.discourse-cdn.com/v4/letter/w/9d8465/32.png) [@Whersh](https://community.postman.com/u/Whersh)\
**Post date:** [January 31, 2022, 3:18pm UTC](https://community.postman.com/t/tests-ok-in-postman-but-ko-in-newman/31954/7 "2022-01-31T15:18:40Z")

</div>

This is how I have done this exact same thing.

1. You can run a bash script to do find and replace after exporting your collection. This will hopefully add the correct location of your needed files.

There is another option as well though… You can use the [working Directory](https://learning.postman.com/docs/getting-started/settings/#working-directory). The working directory is also used by Newman, so any test needing a file upload should work the same if your file is located there.

---

<div class="post-metadata">

**Author:** ![w4dd325](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/w4dd325/32/12436_2.png) [@w4dd325](https://community.postman.com/u/w4dd325)\
**Post date:** [January 31, 2022, 7:01pm UTC](https://community.postman.com/t/tests-ok-in-postman-but-ko-in-newman/31954/8 "2022-01-31T19:01:03Z")

</div>

Do you by any chance have an example of the bash script?

---

<div class="post-metadata">

**Author:** ![Whersh](https://avatars.discourse-cdn.com/v4/letter/w/9d8465/32.png) [@Whersh](https://community.postman.com/u/Whersh)\
**Post date:** [January 31, 2022, 7:44pm UTC](https://community.postman.com/t/tests-ok-in-postman-but-ko-in-newman/31954/9 "2022-01-31T19:44:12Z")

</div>

It has been a bit since I have ran this but if you leave the source blank then you can do this. The script/exported collection and file need to be in the same file as it is setup here. This will also replace ALL instances where there is not a file specified in the collection used.

```auto
#!/bin/bash
sed -i 's/"src": ""/"src": "filename.pdf"/g' mycollection.json

```

---

<div class="post-metadata">

**Author:** ![Legaly-esignature](https://avatars.discourse-cdn.com/v4/letter/l/f05b48/32.png) [@Legaly-esignature](https://community.postman.com/u/Legaly-esignature)\
**Post date:** [February 1, 2022, 6:44pm UTC](https://community.postman.com/t/tests-ok-in-postman-but-ko-in-newman/31954/10 "2022-02-01T18:44:02Z")

</div>

Hello,

Thanks for the replies ! Indeed I tried the method used by @vdespa and it’s work well.

> [@Newman run with relative file paths in form-data for file upload](https://community.postman.com/t/newman-run-with-relative-file-paths-in-form-data-for-file-upload/16069/8):
>
> Last time I have checked the only way is to do this by exporting the collection, editing it and re-importing it. But once you have this running, you don’t need to worry about this anymore.

But actually I don’t see how to create a variable on the path especially since the body of the request offers a location using the file manager and not a written path.

For @whersh, I’ve already set up the working directory like this:  
 ![Capture d’écran du 2022-02-01 19-41-47](https://us1.discourse-cdn.com/getpostman/original/3X/0/e/0ea497620fa9b2293600ed77780fed997325c903.png)

I’m going to try your method with the bash script. Do you have the source of your bash script or a tutorial where this is explained? The next challenge will be to share this collection with the rest of my team.

Thanks to both of you

---

<div class="post-metadata">

**Author:** ![Whersh](https://avatars.discourse-cdn.com/v4/letter/w/9d8465/32.png) [@Whersh](https://community.postman.com/u/Whersh)\
**Post date:** [February 3, 2022, 7:59pm UTC](https://community.postman.com/t/tests-ok-in-postman-but-ko-in-newman/31954/11 "2022-02-03T19:59:24Z")

</div>

Sorry I do not have a source or a tutorial as I wrote this myself. I am sure looking a bit of sed documentation will help with the explanation. [Example tutorial](https://www.cyberciti.biz/faq/how-to-use-sed-to-find-and-replace-text-in-files-in-linux-unix-shell/)

Shareing the collection can either be done a few different ways but a few are described [here in the sharing section](https://community.postman.com/t/editing-shared-environments-environment-variables/443) of Postman documentation

---

<div class="post-metadata">

**Author:** ![Legaly-esignature](https://avatars.discourse-cdn.com/v4/letter/l/f05b48/32.png) [@Legaly-esignature](https://community.postman.com/u/Legaly-esignature)\
**Post date:** [February 7, 2022, 11:15am UTC](https://community.postman.com/t/tests-ok-in-postman-but-ko-in-newman/31954/12 "2022-02-07T11:15:40Z")

</div>

Thanks for your help @Whersh !
