I’d like to use the API to replace some PDF files every day, I managed to do everything in postman, but now I would like to implement that into a powershell script.
The call for the access_token is already the first problem. In postman this call only works if I go to the authorization tab and then Get New Access Token (Relevant post: Postman API Tutorial -> 404 with access_token - #3 by TxT)
Doing the same thing in Powershell leaves me again with a 404 error:
With an access_token that I got from Postman, I was able to some basic calls without any issues. The second Problem is the part when I try to upload an actual file. Again, no problem in postman. How would powershell syntax look like for this? This is what I currently have:
Is there any way of solving these issues? Should I be using a different language with postman export functionality? Is there a way of exporting from postman through the HTTP thing and using that somehow in powershell?
Thanks a lot for your help!
I used the Method get for my access_token call, changed to post still doesnt work. But I somehow got it working in postman, no idea what I changed tho
Edit: Shuffled some things around between header and body and now I get the token Still the same problem with the media file upload
You’re passing the path of the file up in a post request, but what you actually want to do is post up the actual file.
I’m not sure if you can do that with PowerShell, but a Google on the subject does seem to indicate that it is possible. You;d need to set the content type and then pass the actual file bytes somehow.
Technically, content-type is not required, though I found it not to impact results and allows for leveraging a single Invoke-RestMethod command (i.e. wrapped in a function).
While densan’s solution does work, the above is leveraging native PS. I hope this helps others.
This is what we’re doing in PowerShell Universal - when we need to call the Xibo API we call this function first to get a bearer token.
The Cache variables will probably need to be global variables for most people