Issue with Starting an Export using Powershell
Hi friends,
When starting an export from powershell commands as below, I get error but it seems to have worked on server side since getting status works. Same command in Postman runs without error. Any thoughts?
$exportHeaders = @ {Authorization = "Bearer $token" "Content-Type" = "application/json"}
$exportBody = @ { localeName = 'en_US'}
$exportUrl = "$baseUrl/workspaces/$workspaceId/models/$modelId/exports/$exportId/tasks"
Invoke-RestMethod -Uri $exportUrl -Method Post -Headers $exportHeaders -Body $exportBody
This returns an error but the same command runs fine in Postman
Invoke-RestMethod : The remote server returned an error: (400) Bad Request.
At line:1 char:1
- Invoke-RestMethod -Uri $exportUrl -Method Post -Headers $exportHeader ...
- + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
However, subsequent request to get status of the export succeeds without error which mean export started successfully.
Invoke-RestMethod -Uri $exportUrl -Method Get -Headers $exportHeaders -Body $exportBody
@{taskId=CEC8B83827C04CF3B9DA2C1DBD78E295; taskState=COMPLETE; creationTime=1744055721513} @{taskId=DD940E9F42504A0EB0B360CD5CFFEE25; taskState=COMPLETE; creationTime=1744131767221} @{taskId=82224588DFDE4C9CAC68519CCFE92147; taskState=COMPLETE; creationTime=1744132233264} @{taskId=716279C90E674B0EAB14C6BAD3D25EA8; taskState=COMPLETE; creationTime=1744203570900}
Any thoughts on why the POST method results in error from Powershell but not in Postman? Thanks.
Answers
-
Your GET request on /tasks just returns a list of previously started tasks, so doesn't necessarily mean one has been started. Try using -InFile or piping the request body to Invoke-RestMethod instead of using -Body
0 -
Thanks for chiming in Ben. I did one issue with my request - should have used POST in quotes. The following command worked.
$response = Invoke-RestMethod $exportUrl -Method 'POST' -Headers $headers -Body $body
0