Image Upload JSON or XML.

We need the json/xml body, what should we do to upload images to Lightspeed? We get the error in bold below (at the end).
We tried the following with no luck:
JSON
endpoint:
https://api.merchantos.com/API/Account/XXXX/Item/1/Image.json
body:
{
"image":"ewogICAgImRlc2NyaXB0aW9uIjogIlRlc3QgSW1hZ2UiLAogICAgIm9yZGVyaW5nIjogMQp9",
"filename":"279127_01.jpg",
"data":{
"description":"279127_01",
"ordering":"1"
}
}
In image field I am encoding a URL where the image is stored, not sure if I can send the URL itself?
XML
endpoint:
https://api.merchantos.com/API/Account/XXXX/Item/1/Image.xml
body:
<?xml version="1.0"?>
<Image xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<filename>279127_01.jpeg</filename>
<description />
<itemID>1</itemID>
</Image>
No luck in any one (json and xml), I get an error..
{
"httpCode": "500",
"httpMessage": "Internal Server Error",
"message": "Argument 1 passed to pos\\image\\ImageStore::upload() must be of the type string, null given, called in /web/cloud/includes/controller/ItemImageBase.class.php on line 130",
"errorClass": "TypeError"
}
3 comments
Hi, addressing your JSON solution.
Are you using this in your headers?
Next you need to POST both Payloads:
Good luck! 🤖
https://maurisource.com / [email protected]
Magento 1 integration | Magento 2 integration | Custom integrations? Hire me
Hi @gfernandez,
Your URI is correct. The body should be multipart form data. The first part is called "data" and is an XML (or JSON) payload like this:
The second part is called "image" and contains the image itself.
See this page for more details and example code:
http://developers.lightspeedhq.com/retail/endpoints/Account-Item-Image/
Here's an example below. Should work fine!
POST https://api.merchantos.com/API/Account/{AccountId)/Image HTTP/1.1
Authorization: Bearer {Token}
Accept: application/xml
Content-Type: multipart/form-data; boundary=---------------------------8d5776e9cab293b
Host: api.merchantos.com
Content-Length: 36105
Expect: 100-continue
-----------------------------8d5776e9cab293b
Content-Disposition: form-data; name="data"
<?xml version="1.0"?>
<Image xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<filename>IMG_4606.jpg</filename>
<description />
<itemID>225</itemID>
</Image>
-----------------------------8d5776e9cab293b
Content-Disposition: form-data; name="image"; filename="IMG_4606.jpg"
Content-Type: image/jpeg
{the encoded JPEG data goes here}
-----------------------------8d5776e9cab293b--