I want to make a PowerShell script that can take my Postman code and use the same json file with variables to execute as many times needed. Using postman I was able to replace the parts of code with variables. Then using the runner, and selecting the json file. It successfully uploaded three files correctly. To make it easier on the end user, I want to just give them a PowerShell script that will execute in the same way.
OK, that’s a nice plan. And what is your question?
And BTW: When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.
So what are you looking for help with exactly? What have you tried? Does your PS you wrote work or are you running into an error? If an error, what’s the error? Is your issue that you don’t know how to store code or what?
Help us help you, it’s not clear what you are needing help with.
Use PS objects. You don’t need to use JSON here for like… your body ($payload variable). Let PS do the work for you, and it will make your code cleaner. You’ll see from the docs body happily accepts an object.
One reason we went with json file for the different inputs, is that we are handing this over to someone else to use. Rather than having them modify the script. It’s safer for them to update the json file.
Moreover, I’m more of a contributor to what was needed than the actual author, taking time to learn as I help. So while I trust you know what you’re saying it’s still Greek to me. Thank you for the input tho, I appreciate it.
In your code, you literally have JSON. It’s not a separate file. Don’t confuse that with the JSON file you are importing. JSON’s merely a format for data in a file:
{
"FirstName" : "John",
"LastName" : "Cena"
}
I was pretty clear in my previous statement. Your $payload variable is JSON. I’d suggest doing an Object instead, it’ll make it easier to read. You can just do a hashtable really. It has nothing to do with the JSON file your using in the other part of your code. As a quick example (partial you could do something like this (replacing the hardcoded values with your variables of course)
As you can hopefully see, that’s much more readable. In any case it’s up to you, or i guess the author (which you might ask for help on it since they are the responsible party).