[GH-ISSUE #741] Request: Add response data to imported JSON or option to autosave JSON response to directory #737

Open
opened 2026-03-03 19:21:28 +03:00 by kerem · 22 comments
Owner

Originally created by @Alan-Holmes-Mimi on GitHub (Dec 23, 2020).
Original GitHub issue: https://github.com/ProxymanApp/Proxyman/issues/741

Originally assigned to: @NghiaTranUIT on GitHub.

Proxyman version? Version 2.15.1 (21510)

macOS Version? 10.15.7

Feature request:

  • Often it would be nice to be able to autosave the response or request of a url to a json file for reading in other automated tests (eg: read saved json from proxyman response and only assert step after 200 response received)
  • currently it is possible to read json data using require
  • it would be nice to be able to add a response to JSON - using other addons perhaps like the fileSystem library
  • This doesn't need to be something in scripting module, anywhere in the flow would be great
Originally created by @Alan-Holmes-Mimi on GitHub (Dec 23, 2020). Original GitHub issue: https://github.com/ProxymanApp/Proxyman/issues/741 Originally assigned to: @NghiaTranUIT on GitHub. ### Proxyman version? Version 2.15.1 (21510) ### macOS Version? 10.15.7 ### Feature request: - Often it would be nice to be able to autosave the response or request of a url to a json file for reading in other automated tests (eg: read saved json from proxyman response and only assert step after 200 response received) - currently it is possible to read json data using require - it would be nice to be able to add a response to JSON - using other addons perhaps like the fileSystem library - This doesn't need to be something in scripting module, anywhere in the flow would be great
Author
Owner

@NghiaTranUIT commented on GitHub (Dec 25, 2020):

Hi @Alan-Holmes-Mimi, just like to clarify that you need some way to save the response body to the file in the Scripting Tool? 🤔

For instance, it might look like: context.export(body, "~/Desktop/my_response.txt")

function onResponse(context, url, request, response) {

  // Get Body and save to file
  var body = response.body;
  context.export(body, "~/Desktop/my_response.txt")

  // Done
  return response;
}

It will write the body as a file with given path

<!-- gh-comment-id:751159854 --> @NghiaTranUIT commented on GitHub (Dec 25, 2020): Hi @Alan-Holmes-Mimi, just like to clarify that you need some way to save the response body to the file in the Scripting Tool? 🤔 For instance, it might look like: `context.export(body, "~/Desktop/my_response.txt")` ```js function onResponse(context, url, request, response) { // Get Body and save to file var body = response.body; context.export(body, "~/Desktop/my_response.txt") // Done return response; } ``` It will write the body as a file with given path
Author
Owner

@4nif commented on GitHub (Dec 25, 2020):

I like this idea, maybe with context.import to @NghiaTranUIT 👍 so we can use it to import json payload or http header from file without clicking import menu --> search the file

<!-- gh-comment-id:751209198 --> @4nif commented on GitHub (Dec 25, 2020): I like this idea, maybe with `context.import` to @NghiaTranUIT 👍 so we can use it to import json payload or http header from file without clicking import menu --> search the file
Author
Owner

@NghiaTranUIT commented on GitHub (Dec 25, 2020):

context.export(body, file_url) seems to be useful for automation tasks, so I will implement it soon. For the import, I will consider supporting it soon since the workload doesn't seem easy 😅

<!-- gh-comment-id:751218850 --> @NghiaTranUIT commented on GitHub (Dec 25, 2020): `context.export(body, file_url)` seems to be useful for automation tasks, so I will implement it soon. For the `import`, I will consider supporting it soon since the workload doesn't seem easy 😅
Author
Owner

@Alan-Holmes-Mimi commented on GitHub (Dec 25, 2020):

Hi @Alan-Holmes-Mimi, just like to clarify that you need some way to save the response body to the file in the Scripting Tool? 🤔

For instance, it might look like: context.export(body, "~/Desktop/my_response.txt")

function onResponse(context, url, request, response) {

  // Get Body and save to file
  var body = response.body;
  context.export(body, "~/Desktop/my_response.txt")

  // Done
  return response;
}

It will write the body as a file with given path

Wow that seems like something that would definitely work for my purpose. I would essentially be looking to get around no API for catching a response, to trigger my assertion once I get a 200 from response. So within my automation framework I could read read the JSON and assert it contains 200 in response, then move on to the next step! Thanks for reponses!

<!-- gh-comment-id:751229608 --> @Alan-Holmes-Mimi commented on GitHub (Dec 25, 2020): > Hi @Alan-Holmes-Mimi, just like to clarify that you need some way to save the response body to the file in the Scripting Tool? 🤔 > > For instance, it might look like: `context.export(body, "~/Desktop/my_response.txt")` > > ```js > function onResponse(context, url, request, response) { > > // Get Body and save to file > var body = response.body; > context.export(body, "~/Desktop/my_response.txt") > > // Done > return response; > } > ``` > > It will write the body as a file with given path Wow that seems like something that would definitely work for my purpose. I would essentially be looking to get around no API for catching a response, to trigger my assertion once I get a 200 from response. So within my automation framework I could read read the JSON and assert it contains 200 in response, then move on to the next step! Thanks for reponses!
Author
Owner

@NghiaTranUIT commented on GitHub (Dec 31, 2020):

Hey @Alan-Holmes-Mimi @4nif, let check out this beta build: https://proxyman.s3.us-east-2.amazonaws.com/beta/Proxyman_2.15.2_Write_To_File.dmg

From now, you can write down the body of the request/response to a file with writeToFile(data, "~/desktop/myfile.txt")
For instance,

function onResponse(context, url, request, response) {

  // Write the Body to file
  writeToFile(response.body, "~/Desktop/sample-" + context.flow.id);
  
  // Done
  return response;
}
Screen Shot 2020-12-31 at 11 01 21
<!-- gh-comment-id:752842805 --> @NghiaTranUIT commented on GitHub (Dec 31, 2020): Hey @Alan-Holmes-Mimi @4nif, let check out this beta build: https://proxyman.s3.us-east-2.amazonaws.com/beta/Proxyman_2.15.2_Write_To_File.dmg From now, you can write down the body of the request/response to a file with `writeToFile(data, "~/desktop/myfile.txt")` For instance, ```js function onResponse(context, url, request, response) { // Write the Body to file writeToFile(response.body, "~/Desktop/sample-" + context.flow.id); // Done return response; } ``` <img width="1906" alt="Screen Shot 2020-12-31 at 11 01 21" src="https://user-images.githubusercontent.com/5878421/103394987-63e6a100-4b5e-11eb-8115-0d160f025d08.png">
Author
Owner

@Alan-Holmes-Mimi commented on GitHub (Dec 31, 2020):

Hey @Alan-Holmes-Mimi @4nif, let check out this beta build: https://proxyman.s3.us-east-2.amazonaws.com/beta/Proxyman_2.15.2_Write_To_File.dmg

From now, you can write down the body of the request/response to a file with writeToFile(data, "~/desktop/myfile.txt")
For instance,

function onResponse(context, url, request, response) {

  // Write the Body to file
  writeToFile(response.body, "~/Desktop/sample-" + context.flow.id);
  
  // Done
  return response;
}
Screen Shot 2020-12-31 at 11 01 21

@NghiaTranUIT Works like a charm! No issues when overwriting files either which is nice!

<!-- gh-comment-id:752964895 --> @Alan-Holmes-Mimi commented on GitHub (Dec 31, 2020): > Hey @Alan-Holmes-Mimi @4nif, let check out this beta build: https://proxyman.s3.us-east-2.amazonaws.com/beta/Proxyman_2.15.2_Write_To_File.dmg > > From now, you can write down the body of the request/response to a file with `writeToFile(data, "~/desktop/myfile.txt")` > For instance, > > ```js > function onResponse(context, url, request, response) { > > // Write the Body to file > writeToFile(response.body, "~/Desktop/sample-" + context.flow.id); > > // Done > return response; > } > ``` > > <img alt="Screen Shot 2020-12-31 at 11 01 21" width="1906" src="https://user-images.githubusercontent.com/5878421/103394987-63e6a100-4b5e-11eb-8115-0d160f025d08.png"> @NghiaTranUIT Works like a charm! No issues when overwriting files either which is nice!
Author
Owner

@Alan-Holmes-Mimi commented on GitHub (Dec 31, 2020):

would it be possible to push the raw data that includes the HTTP response status code. Or to allow the response/request.statuscode/status so it is possible to assert a 500/200 response code?

<!-- gh-comment-id:752969466 --> @Alan-Holmes-Mimi commented on GitHub (Dec 31, 2020): would it be possible to push the raw data that includes the HTTP response status code. Or to allow the response/request.statuscode/status so it is possible to assert a 500/200 response code?
Author
Owner

@Alan-Holmes-Mimi commented on GitHub (Dec 31, 2020):

Actually @NghiaTranUIT I believe there is no need to complicate anything. I just converted status code to string. My own oversight!

function onResponse(context, url, request, response) {

  // Write the Body to file
  var statCode = response.statusCode.toString();
  writeToFile(statCode, "~/Desktop/sample.json");
  
  // Done
  return response;
}

This feature will eliminate the need for hard coded waits in my own automation framework!

<!-- gh-comment-id:752978892 --> @Alan-Holmes-Mimi commented on GitHub (Dec 31, 2020): Actually @NghiaTranUIT I believe there is no need to complicate anything. I just converted status code to string. My own oversight! ``` function onResponse(context, url, request, response) { // Write the Body to file var statCode = response.statusCode.toString(); writeToFile(statCode, "~/Desktop/sample.json"); // Done return response; } ``` This feature will eliminate the need for hard coded waits in my own automation framework!
Author
Owner

@amorphius commented on GitHub (Jan 1, 2021):

@NghiaTranUIT writing is great! And how can I read from the file?

<!-- gh-comment-id:753361134 --> @amorphius commented on GitHub (Jan 1, 2021): @NghiaTranUIT writing is great! And how can I read from the file?
Author
Owner

@NghiaTranUIT commented on GitHub (Jan 2, 2021):

@amorphius let click on the Import File button in the Scripting Window (https://docs.proxyman.io/scripting/snippet-code#json) 👍

<!-- gh-comment-id:753416543 --> @NghiaTranUIT commented on GitHub (Jan 2, 2021): @amorphius let click on the Import File button in the Scripting Window (https://docs.proxyman.io/scripting/snippet-code#json) 👍
Author
Owner

@NghiaTranUIT commented on GitHub (Jan 2, 2021):

Awesome, glad to hear that @Alan-Holmes-Mimi 😄

<!-- gh-comment-id:753416591 --> @NghiaTranUIT commented on GitHub (Jan 2, 2021): Awesome, glad to hear that @Alan-Holmes-Mimi 😄
Author
Owner

@amorphius commented on GitHub (Jan 2, 2021):

@amorphius let click on the Import File button in the Scripting Window (https://docs.proxyman.io/scripting/snippet-code#json) 👍

I mean how can I read file with generated filename?
Will this work?

const filename = "~/cache/responses" + request.queries.filename;
const cachedFile = require(filename)
<!-- gh-comment-id:753496878 --> @amorphius commented on GitHub (Jan 2, 2021): > @amorphius let click on the Import File button in the Scripting Window (https://docs.proxyman.io/scripting/snippet-code#json) 👍 I mean how can I read file with generated filename? Will this work? ``` const filename = "~/cache/responses" + request.queries.filename; const cachedFile = require(filename) ```
Author
Owner

@NghiaTranUIT commented on GitHub (Jan 3, 2021):

Please export the file to ~/Library/Application Support/com.proxyman.NSProxy/users/, then you can import it by using:

const filename = "@users/" + request.queries.filename;
const file = require(filename);

@users is the folder: ~/Library/Application Support/com.proxyman.NSProxy/users. At the moment, Proxyman is only capable of importing from @users folder.

<!-- gh-comment-id:753581783 --> @NghiaTranUIT commented on GitHub (Jan 3, 2021): Please export the file to `~/Library/Application Support/com.proxyman.NSProxy/users/`, then you can import it by using: ```js const filename = "@users/" + request.queries.filename; const file = require(filename); ``` @users is the folder: `~/Library/Application Support/com.proxyman.NSProxy/users`. At the moment, Proxyman is only capable of importing from `@users` folder.
Author
Owner

@amorphius commented on GitHub (Jan 3, 2021):

@NghiaTranUIT hmm, that's a bit weird. So I can write file to any folder but cannot read it? Is it impossible to implement or just wasn't implemented yet?

<!-- gh-comment-id:753586347 --> @amorphius commented on GitHub (Jan 3, 2021): @NghiaTranUIT hmm, that's a bit weird. So I can write file to any folder but cannot read it? Is it impossible to implement or just wasn't implemented yet?
Author
Owner

@NghiaTranUIT commented on GitHub (Jan 3, 2021):

It's possible, but we hasn't implemented it yet 😄

<!-- gh-comment-id:753586420 --> @NghiaTranUIT commented on GitHub (Jan 3, 2021): It's possible, but we hasn't implemented it yet 😄
Author
Owner

@NghiaTranUIT commented on GitHub (Jan 3, 2021):

To work around, please follow my example. I will support import "everywhere" soon 👍

<!-- gh-comment-id:753586464 --> @NghiaTranUIT commented on GitHub (Jan 3, 2021): To work around, please follow my example. I will support import "everywhere" soon 👍
Author
Owner

@amorphius commented on GitHub (Jan 3, 2021):

@NghiaTranUIT I see, thanks!

<!-- gh-comment-id:753586638 --> @amorphius commented on GitHub (Jan 3, 2021): @NghiaTranUIT I see, thanks!
Author
Owner

@justaguywhocodes commented on GitHub (Mar 30, 2022):

One thought would be to have a shortcut monitor the folder for changes and then process the HTTP request via GetUrlContents function within Shortcuts. JXA/AppleScript is another possibility.

<!-- gh-comment-id:1082605093 --> @justaguywhocodes commented on GitHub (Mar 30, 2022): One thought would be to have a shortcut monitor the folder for changes and then process the HTTP request via GetUrlContents function within Shortcuts. JXA/AppleScript is another possibility.
Author
Owner

@jamesdh commented on GitHub (Oct 5, 2022):

Was there ever any way added to read the contents of a file? Currently writeToFile overwrites the file every time, but I'd like some way to append to the same file.

<!-- gh-comment-id:1268471809 --> @jamesdh commented on GitHub (Oct 5, 2022): Was there ever any way added to read the contents of a file? Currently `writeToFile` overwrites the file every time, but I'd like some way to append to the same file.
Author
Owner

@NghiaTranUIT commented on GitHub (Oct 5, 2022):

@jamesdh if you're using Proxyman 3.6.2+, you can provide an option to append the file, instead of overridden.

async function onResponse(context, url, request, response) {

  // Append to the existed file
  // Or create a new file if it doesn't exist
  var opt = {appendFile: true}
  writeToFile(response.body, "~/Desktop/body.json", opt);

  // Done
  return response;
}

Ref: https://docs.proxyman.io/scripting/snippet-code#write-export-to-a-local-file

<!-- gh-comment-id:1268525774 --> @NghiaTranUIT commented on GitHub (Oct 5, 2022): @jamesdh if you're using Proxyman 3.6.2+, you can provide an option to append the file, instead of overridden. ```js async function onResponse(context, url, request, response) { // Append to the existed file // Or create a new file if it doesn't exist var opt = {appendFile: true} writeToFile(response.body, "~/Desktop/body.json", opt); // Done return response; } ``` Ref: https://docs.proxyman.io/scripting/snippet-code#write-export-to-a-local-file
Author
Owner

@jamesdh commented on GitHub (Oct 5, 2022):

@NghiaTranUIT You just got yourself a paying customer, and/or possibly a paying team. Thank you!

<!-- gh-comment-id:1268603370 --> @jamesdh commented on GitHub (Oct 5, 2022): @NghiaTranUIT You just got yourself a paying customer, and/or possibly a paying team. Thank you!
Author
Owner

@NghiaTranUIT commented on GitHub (Oct 5, 2022):

@NghiaTranUIT You just got yourself a paying customer, and/or possibly a paying team. Thank you!

Wow I appreciate it 😆

<!-- gh-comment-id:1268639578 --> @NghiaTranUIT commented on GitHub (Oct 5, 2022): > @NghiaTranUIT You just got yourself a paying customer, and/or possibly a paying team. Thank you! Wow I appreciate it 😆
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/Proxyman#737
No description provided.