# system.Collections.Hashtable does not exist when calling invoke restmethod for csv upload

**URL:** <https://forums.powershell.org/t/system-collections-hashtable-does-not-exist-when-calling-invoke-restmethod-for-csv-upload/22921>\
**Category:** PowerShell Help\
**Created:** [September 26, 2023, 10:28am UTC](https://forums.powershell.org/t/system-collections-hashtable-does-not-exist-when-calling-invoke-restmethod-for-csv-upload/22921 "2023-09-26T10:28:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![script23](https://avatars.discourse-cdn.com/v4/letter/s/b3f665/32.png) [@script23](https://forums.powershell.org/u/script23)\
**Post date:** [September 26, 2023, 10:28am UTC](https://forums.powershell.org/t/system-collections-hashtable-does-not-exist-when-calling-invoke-restmethod-for-csv-upload/22921/1 "2023-09-26T10:28:17Z")

</div>

$uri = “\*\*\*\*\*\*\*\*\*\*\*\*\*\*”

$body = @{  
grant\_type = \*\*\*\*\*\*\*\*\*\*\*\*\*\*  
client\_id = \*\*\*\*\*\*\*\*\*\*\*\*\*\*  
client\_secret = \*\*\*\*\*\*\*\*\*\*\*\*\*\*  
username = \*\*\*\*\*\*\*\*\*\*\*\*\*\*  
password = \*\*\*\*\*\*\*\*\*\*\*\*\*\*  
}

$resp = Invoke-RestMethod -Method POST -Uri $uri -Body $body

$token = $resp.access\_token

$boundary = [System.Guid]::NewGuid().ToString();

$filename = “C:\Users\ ***\*** \TestUpload.csv”

$headers = New-Object “System.Collections.Generic.Dictionary[[String],[String]]”  
$headers.Add(‘Authorization’, “Bearer $token”)  
$headers.Add(‘ContentLength’,8616)

$headers

$form = @{  
file = $filename  
minorEdit = “true”  
}

Invoke-RestMethod ‘https://_ **./** _.\*\*\*\*\*\*\*\*\*’ -Method POST -infile $form -Header $headers -ContentType ‘multipart/form-data; boundary=`"$boundary`"’

token is processed fine however I get the following

Invoke-RestMethod : Cannot find path ‘C:\Users\*\*\*\*\*\*\*\System.Collections.Hashtable’ because it does not exist.

any help would be appreciated

---

<div class="post-metadata">

**Author:** ![matt-bloomfield](https://avatars.discourse-cdn.com/v4/letter/m/dec6dc/32.png) [@matt-bloomfield](https://forums.powershell.org/u/matt-bloomfield)\
**Post date:** [September 27, 2023, 8:36pm UTC](https://forums.powershell.org/t/system-collections-hashtable-does-not-exist-when-calling-invoke-restmethod-for-csv-upload/22921/2 "2023-09-27T20:36:56Z")

</div>

Hi, welcome to the forum 👋

Firstly, when posting code in the forum, please can you use the preformatted text \</\> button. It really helps us with readability, and copying and pasting your code (we don’t have to faff about replacing curly quote marks to get things working). If you can’t see the \</\> in your toolbar, you will find it under the gear icon.

[How to format code on PowerShell.org](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/2X/b/bee50c628238f2c076c0504efb6b15f2fb11f002.gif)

The problem you’re having is with the `InFile` parameter. If you check the documentation for `Invoke-RestMethod` you can see that it’s expecting an object of type `System.String` and you’re trying to pass it a hashtable (your variable `$form`).

```auto
PS E:\Temp> Get-Help Invoke-RestMethod -Parameter InFile

-InFile <System.String>
    Gets the content of the web request from a file.

    Enter a path and file name. If you omit the path, the default is the current location.

    Required? false
    Position? named
    Default value None
    Accept pipeline input? False
    Accept wildcard characters? false

```

---

<div class="post-metadata">

**Author:** ![script23](https://avatars.discourse-cdn.com/v4/letter/s/b3f665/32.png) [@script23](https://forums.powershell.org/u/script23)\
**Post date:** [September 28, 2023, 8:23am UTC](https://forums.powershell.org/t/system-collections-hashtable-does-not-exist-when-calling-invoke-restmethod-for-csv-upload/22921/3 "2023-09-28T08:23:38Z")

</div>

Hi thanks for your response - noted will use \<\> for scripts going forward.

Unfortunately I’m getting the following now when hardcoding the file

Invoke-RestMethod : {“message”:“Invalid file”}

```auto
Invoke-RestMethod 'https:// ******.*******. ********/****** / ******' -Method POST -inFile "C:\Users\********** \ *********\***** \TestUpload.csv" -Header $headers -ContentType 'multipart/form-data; boundary=`"$boundary`"'

```

So as I’m using “multipart/form-data” as the content type (this type works via postman and swagger)  
Is it ok to simply use a .csv file in this request or do i need to do additional work with any type of conversions etc…

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:14pm UTC](https://forums.powershell.org/t/system-collections-hashtable-does-not-exist-when-calling-invoke-restmethod-for-csv-upload/22921/4 "2024-05-16T20:14:37Z")

</div>


