Invoke-RestMethod OutOfMemory

I’m trying to retrieve a large dataset from a site using this command

$alldevices=Invoke-RestMethod -Method "Get" -Uri "https://<website>/Service/Device" -UseBasicParsing -UseDefaultCredentials

But am getting this message:

Invoke-RestMethod : Exception of type 'System.OutOfMemoryException' was thrown.
At line:1 char:13
+ $alldevices=Invoke-RestMethod -Method "Get" -Uri "https://<website> ...
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Invoke-RestMethod], OutOfMemoryException
    + FullyQualifiedErrorId : System.OutOfMemoryException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

Then I tried to use this command:

Invoke-WebRequest -Uri "https://<website>/Service/Device" -UseBasicParsing -UseDefaultCredentials

Then I get this message:

At line:1 char:15
+ ...       $alld=Invoke-WebRequest -Uri "https://<website>...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Invoke-WebRequest], OutOfMemoryException
    + FullyQualifiedErrorId : System.OutOfMemoryException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

Is there a way to get this dataset in chunks, so I don’t run into this memory issue? I’m open to any other way to get this information, too.

Invoke-RestMerhod has a parameter TransferEncoding which you can specify Chunked