• RE: Powershell RestAPI Upload

    Solved - For anyone that also comes across this issue

    Postman was not adding the content type of the file when parsing the code into powershell.

     Add this for the XML fields file

    $fileContent.Headers.Add("Content-Type", "application/xml")

    And i did this to detect the actual document mimetype and set the header

    Add-Type -AssemblyName "System.Web"

    $Mime = [System.Web.MimeMapping]::GetMimeMapping($File)

    $fileContent.Headers.Add("Content-Type", $Mime)

  • Powershell RestAPI Upload

    Hi,

    Has anyone managed to get the powershell upload via rest API to work?
    Postman works fine and when taking the code for powershell and directly putting it in a console it fails.

    Object reference not set to an instance of an object.NullReferenceException: Object reference not set to an instance of an object.

    It looks like the code does not actually load the document. Ive tried a few ways with no luck.

    I also attempted to use the -form now available in powershell 7 to create the form directly which can be seen on the microsoft documentation for multipart forms  on Invoke-restmethod(Example 5). I get the below result

    Invoke-RestMethod: Value cannot be null.
    Parameter name: stringToUnescapeArgumentNullException: Value cannot be null.
    Parameter name: stringToUnescape


    I think the problem is the [] within the form that is required for the xml upload.

    I'm hoping someone else may have got this working via powershell and would be able to share how they did it.

    Thanks