We are trying to automate to make use of the API to upload an image to Sphere. The API documents the image should be sent as a byte array, but it doesn't look like our script is successful in uploading, as the get async operation doesn't seem to return success.
Our code is:
$bitstream = @()
$bitstream = get-content $image -encoding byte
$body = ""$bitstream
""
$tempresult = invoke-restmethod -Method Post -uri "https://prod.core.sphere.azure.net/v2/tenants/$primarytenant/images" -Headers @{ 'Authorization' = "Bearer $bearertoken"; 'Content-Type' = 'application/json' } -Body $body
$tempresult
$opid = $tempresult.OperationId
sleep 5
invoke-restmethod -Method Get -uri "https://prod.core.sphere.azure.net/v2/tenants/$primarytenant/operations/$opid/" -Headers @{ 'Authorization' = "Bearer $bearertoken"; 'Content-Type' = 'application/json' }
The operation shows the following:
TenantId : x
OperationId : c2b6dedd-0313-4feb-81dc-96762231dd9c
CreatedDateUTC : 2020-12-08T08:52:44.59309Z
StartedDateUTC : 2020-12-08T08:52:44.8275573Z
CompletedDateUTC : 2020-12-08T08:52:45.0375127Z
OperationType : 7
State : 3
ResourceLocation :
DetailsLocation : v2/tenants/x/operationTypes/imageUpload/operations/c2b6dedd-0313-4feb-81dc-96762231dd9c
Error : @{Code=5; Message=}
But I can't understand why it doesn't work. I've tried passing the bitstream directly, instead of as a string, but to no impact.
Thanks for any ideas!