eBay API - UploadSiteHostedPictures

I’ve been trying to successfully submit a transaction to the ebay trading api using the call UploadSiteHostedPictures. However, I’m getting the following error:
XML Parse error.
XML Error Text: “{0}”.

I’ve tried both using Xojo URL Connection call and via postman. I get the same issue.

Has anyone worked the the eBay trading API in Xojo? If so, if you managed to have a working transaction of UploadSiteHostedPictures, would you been able to share what you have done please?

Here is the reference doc: UploadSiteHostedPictures

If you need to see what I did, I posted on the ebay developer forum here: my eBay forum post

Thanks

According to the docs, you’re missing some entries…

<?xml version="1.0" encoding="utf-8"?>
<UploadSiteHostedPicturesRequest xmlns="urn:ebay:apis:eBLBaseComponents">
    <RequesterCredentials>
        <ebl:eBayAuthToken xmlns:ebl="urn:ebay:apis:eBLBaseComponents">TOKEN</ebl:eBayAuthToken>
    </RequesterCredentials>
    <PictureName>Gall-Peters projection map</PictureName>
    <PictureSet>Standard</PictureSet>
    <ExtensionInDays>20</ExtensionInDays>
</UploadSiteHostedPicturesRequest>

Specifically the RequesterCredentials

Welcome to the Xojo Forum :raised_hand:

1 Like

Hi Greg. Thanks, but the request credentials were recently changes to allow to put them in the headers instead of the body : X-EBAY-API-IAF-TOKEN header

However, I did try exactly the call that you quoted and it didn’t work

I managed to make it work in Postman. the issue was the order the form data (XML Payload has to be before the photo). However, that was not the issue in Xojo. Now that I have a working transaction in Postman, I’ll should be able to fix it in Xojo. I’ll share the outcome later.

After many hours of debugging, I finally found the proper way to send it to their Image Server

dim ebay_connect as new URLConnection
dim Boundary as string  = "bOuNdArY-EmPoRiUm"

Static CRLF As String = Endofline.Windows

// Set Headers
ebay_connect.RequestHeader("X-EBAY-API-APP-NAME") = App.EbayAppName
ebay_connect.RequestHeader("X-EBAY-API-DEV-NAME") = App.EbayDevName
ebay_connect.RequestHeader("X-EBAY-API-CERT-NAME") = App.EbayCertNane
ebay_connect.RequestHeader("Content-Type") = "multipart/form-data; boundary="+boundary
ebay_connect.RequestHeader("X-EBAY-API-COMPATIBILITY-LEVEL") = "1227"
ebay_connect.RequestHeader("X-EBAY-API-CALL-NAME") = "UploadSiteHostedPictures"
ebay_connect.RequestHeader("X-EBAY-API-SITEID") = "2"
ebay_connect.RequestHeader("X-EBAY-API-IAF-TOKEN") = App.UserToken

//Build XML Payload
dim xmlPayload as string 
xmlPayload = xmlPayload + "<?xml version=""1.0"" encoding=""UTF-8""?>" + CRLF
xmlPayload = xmlPayload + "<UploadSiteHostedPicturesRequest xmls=""urn:ebay:apis:eBLBaseComponents"">" + CRLF
xmlPayload = xmlPayload + "<PictureName>image</PictureName>" + CRLF
xmlPayload = xmlPayload + "</UploadSiteHostedPicturesRequest>" + CRLF
xmlPayload = DefineEncoding(xmlPayload,Encodings.UTF8)

// For the next 3 lines, you can replace with whatever way to get the image file. Easier to put it in a temporary jpg file and work wit that in the mime attachment
Dim img As Picture = ImageViewer1.Image
Dim tempFile As FolderItem = SpecialFolder.Temporary.Child("image.jpg")
img.Save(tempFile, Picture.Formats.JPEG)



Dim data As New MemoryBlock(0)
Dim output as string
output = "--" + Boundary + CRLF
output = output + "Content-Disposition: form-data; name=""XML Payload""" + CRLF + CRLF
output = output + xmlPayload + CRLF
output = output + "--" + Boundary + CRLF
output = output + "Content-Disposition: form-data; name=""image""; filename=""image.jpg""" + CRLF
output = output + "Content-Type: image/jpeg" + CRLF + CRLF

data = DefineEncoding(output,Encodings.UTF8)

Dim bs As BinaryStream = BinaryStream.Open(tempFile)
data = data + bs.Read(bs.Length) + CRLF
bs.Close
data = data + "--" + Boundary + "--" + CRLF


ebay_connect.SetRequestContent(data, "multipart/form-data; boundary=" + boundary)

dim response as string = ebay_connect.SendSync("POST",App.EbayURLEndPoint)
1 Like

Thanks so much for sharing your solution with the Xojo community!

p.s. you might want to mark the question as solved by marking your most recent post as the solution.