View Single Post
  #1  
Old 10-29-2020, 01:43 AM
Robert Hadfield's Avatar
Robert Hadfield Robert Hadfield is offline
 
Join Date: Oct 2020
Posts: 2
Default Powershell 7 JSON handling

Trying to update a product using powershell 7

I can get the product and convert it from JSON into an object in PS that I can work with:

Code:
$myproduct = ConvertFrom-Json (invoke-webrequest -uri https://app.ecwid.com/api/v3/xxxxxxxx/products/xxxxxxx?token=secret_xxxxxxxxxx).Content
I can update an attribute:
Code:
$myproduct.name = "Test Product 1.3"
I can convert it back to JSON:
Code:
$myJSON = ConvertTo-Json $myproduct -compress
But it fails on update:
Code:
$myJSON | Invoke-WebRequest -uri https://app.ecwid.com/api/v3/xxxxxx/products/xxxxxx?token=secret_xxxxxxxx -method PUT -ContentType 'application/json'
With the following message:
Quote:
InvalidOperation: The regular expression pattern media":{"images":["@{ is not valid.
The conversion of the media object one way or the other is messed up.

Comparing the Original:
Code:
"media":{"images":[{"id":"0","isMain":true,"orderBy":0,"image160pxUrl":"https://d2j6dbq0eux0bg.cloudfront.net/images/36906115/1729548913.jpg","image400pxUrl":"https://d2j6dbq0eux0bg.cloudfront.net/images/36906115/1729548916.jpg","image800pxUrl":"https://d2j6dbq0eux0bg.cloudfront.net/images/36906115/1729548915.jpg","image1500pxUrl":"https://d2j6dbq0eux0bg.cloudfront.net/images/36906115/1729548914.jpg","imageOriginalUrl":"https://d2j6dbq0eux0bg.cloudfront.net/images/36906115/1729548912.jpg"}]}
to the Converted:
Code:
"media":{"images":["@{id=0; isMain=True; orderBy=0; image160pxUrl=https://d2j6dbq0eux0bg.cloudfront.net/images/36906115/1729548913.jpg; image400pxUrl=https://d2j6dbq0eux0bg.cloudfront.net/images/36906115/1729548916.jpg; image800pxUrl=https://d2j6dbq0eux0bg.cloudfront.net/images/36906115/1729548915.jpg; image1500pxUrl=https://d2j6dbq0eux0bg.cloudfront.net/images/36906115/1729548914.jpg; imageOriginalUrl=https://d2j6dbq0eux0bg.cloudfront.net/images/36906115/1729548912.jpg}"]}
You can see how different it is.

So I am trying to work out how to get around this.