Problems trying to create an eBay API call through the File Transfer API

Hi,

I'm in the process of developing an eBay application in Microsoft Access 2016. So far my project has been fine and the API calls I have made have been successful but I have now come to a stumbling block that I need some help with.

The API calls I have used so far are all for single listings so this is easy and I just pass the XML through an HTTP request. I want to make this much more efficient and use eBay's File Transfer API where I can send more than 1 call at a time but I'm really struggling on trying to understand how to build the call.

The data has to be sent as Binary Base64 which I have a converter to do this. I can build the XML that needs to be sent but I just don't understand how to send the XML from a string as apposed to a physical file.

I've read loads on the internet about having to create it as a multipart request with boundaries but really not sure how to start building that. I can provide code if need be so you can see where I am at.

I hope this makes sense.
Simon HammillApplication AnalystAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

 
ITguy565Commented:
@simon

I might suggest turning this into a gig as it is most likely going to be detailed.
0
 
Simon HammillApplication AnalystAuthor Commented:
How do I turn this into a gig?
0
 
ITguy565Commented:
Click on Products -- > Live --> Create New Request
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
"Gigs" are no longer available on the site.  But Experts here can try and help solve this for you here or you can contact an Expert directly if you like.

Which language are you using?  vba? .NET? etc  Which api are you working with now that works and can you share your code making sure to obfuscate passwords and other personal information.  Next, which api are you having troubles with, what code have you tried and what errors did you encounter?  

Please make sure to include the links to the api  you are using such as https://developer.ebay.com/api-docs/sell/inventory/resources/listing/methods/bulkMigrateListing

If your question can be broken down to steps (asking about one error per question thread), it will be easier to get Experts to help.
0
 
Simon HammillApplication AnalystAuthor Commented:
Hi Scott,

Thanks for the reply. I'll try my best to supply as much info as I can as i've spent ours on this trying to use example from all over the internet but nothing seems to be working.

I'm using VBA in MS Access as this is something i've used quite alot.

Links to the API info, the API I am using is eBays File Transfer API through the Large Merchant Services
Large Merchant Services
upLoadFile - File Transfer API

I have created a job through the Bulk Data Exchange API so I have my Job and Reference ID
I'm not just stuck on this File Transfer API

Please excuse my code, I write it so I can read it and so far, that has worked for me :)

 Set xhr = CreateObject("Microsoft.XMLHTTP")
 
   'Production
  webServiceURL = "https://storage.ebay.com/FileTransferService"
  
  'Sandbox
  'webServiceURL = "https://storage.sandbox.ebay.com/FileTransferService"

 xhr.Open "POST", webServiceURL, False
 
 xhr.setRequestHeader "CONTENT-TYPE", "text/xml"
 xhr.setRequestHeader "X-EBAY-SOA-OPERATION-NAME", "uploadFile"
 xhr.setRequestHeader "X-EBAY-SOA-SECURITY-TOKEN", DLookup("[eBay_Token]", "Clients", "[Select_Client] = TRUE")
 xhr.setRequestHeader "X-EBAY-SOA-SERVICE-NAME", "FileTransferService"
 xhr.setRequestHeader "X-EBAY-SOA-SERVICE-VERSION", "1.0.0"
 xhr.setRequestHeader "X-EBAY-API-APP-Name", APPID
 xhr.setRequestHeader "X-EBAY-API-DEV-NAME", DEVID
 xhr.setRequestHeader "X-EBAY-API-CERT-NAME", CERTID
 
 

 bodydetails = "<?xml version=" & """" & "1.0" & """" & " encoding=" & """" & "utf-8" & """" & "?>"
 bodydetails = bodydetails & "<uploadFileRequest xmlns=" & """" & "http://www.ebay.com/marketplace/services" & """" & ">"
 bodydetails = bodydetails & "<fileAttachment>"
 bodydetails = bodydetails & "<Data><xop:Include xmlns:xop=" & """" & "http://www.w3.org/2004/08/xop/include" & """" & " href=" & """" & "cid:urn:uuid:" & CONTUUID & "/></Data></Data>"
 bodydetails = bodydetails & "<Size>" & XMLLen & "</Size>"
 bodydetails = bodydetails & "</fileAttachment>"
 bodydetails = bodydetails & "<fileFormat>zip</fileFormat>"
 bodydetails = bodydetails & "<fileReferenceId>" & DLookup("[RefID]", "UploadJobs", "[Client_Email] = " & """" & DLookup("[Email_Address]", "Clients", "[Select_Client] = TRUE") & """") & "</fileReferenceId>"
 bodydetails = bodydetails & "<taskReferenceId>" & DLookup("[JobID]", "UploadJobs", "[Client_Email] = " & """" & DLookup("[Email_Address]", "Clients", "[Select_Client] = TRUE") & """") & "</taskReferenceId>"
 bodydetails = bodydetails & "</uploadFileRequest>"
 
 Debug.Print bodydetails
 
 xhr.send (bodydetails)


 If xhr.status = 200 Then
   Debug.Print xhr.responseText

 Else
   Debug.Print xhr.responseText
   Debug.Print xhr.status & ": " & xhr.statusText
   Exit Sub
 End If

Open in new window


Cheers guys, I wish I could tell you what I have tried but I've lost count on what I have and haven't. At this point I'm open to Ideas.

Thanks,
0
 
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
Is the above code the api call that you said is working?  If not, can you post that, please?  If it is the code that is not working, do you have a detailed error message/line number?
0
 
Simon HammillApplication AnalystAuthor Commented:
This is the call that is not working.

This is the error i'm currently getting

<?xml version='1.0' encoding='UTF-8'?><errorMessage xmlns="http://www.ebay.com/marketplace/services"><error><errorId>5014</errorId><domain>CoreRuntime</domain><severity>Error</severity><category>System</category><message>Error reading from XML stream: Unexpected '&lt;'  in attribute value
 at javax.xml.stream.SerializableLocation@78177817</message><subdomain>Comm_Recv</subdomain><parameter name="Param1">Unexpected '&lt;'  in attribute value
 at javax.xml.stream.SerializableLocation@78177817</parameter></error></errorMessage>

Open in new window


I'm guessing this maybe the case because I haven't supplied the XML but I have no Idea how to and where I am suppose to add in the XML.
I've read that it need to be encoded into Binary Base64 Zip file. Again, not sure how to do this. I am willing to learn.
0
 
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
Thank you.

Can you post the code that does work along with the link to the api doc that you used.
0
 
Simon HammillApplication AnalystAuthor Commented:
The other eBay API's that I have used are completely different to this one. I don't really have any code that works at the moment for this API.

API Documentation

Large Merchant Services

File Transfer API
0
 
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
How do you know if it works if there is no code?  What I am trying to do is build on what you already have.  It is still a SOAP call and let's make sure that the issue is not in how you are doing this and perhaps just the data you are posting or how you are posting it.

Although your current error is, "Unexpected '&lt;'" and that looks like a good clue.
0
 
Simon HammillApplication AnalystAuthor Commented:
Hi,

I'll post my whole working and try to explain what I have going, that may make a bit more sense.

Public Sub bulk_revise_items()

Dim rs As DAO.Recordset
Set rs = CurrentDb.OpenRecordset("UploadJobs")

uuid = Replace(Left(DLookup("[Company_Name]", "Clients", "[Select_Client] = TRUE"), 10), " ", "-") & Format(Now, "number")

'Order of calls (Bulk Data Exchange API)
'Create Upload Job (Bulk Data Exchange API)
'Build File (Merchant Data API
'Upload File (File Transfer API)
'Start Upload Job (Bulk Data Exchange API)
'Get Job Status (Bulk Data Exchange API)
 
 Call devcreds
  
 'Create Upload Job
 
  Set xhr = CreateObject("Microsoft.XMLHTTP")
 
  'Production
  webServiceURL = "https://webservices.ebay.com/BulkDataExchangeService"
  
  'Sandbox
  'webServiceURL = "https://webservices.sandbox.ebay.com/BulkDataExchangeService"

 xhr.Open "POST", webServiceURL, False
 
 xhr.setRequestHeader "X-EBAY-SOA-SERVICE-VERSION", "1.4.1"
 xhr.setRequestHeader "X-EBAY-SOA-SERVICE-NAME", "BulkDataExchangeService"
 xhr.setRequestHeader "X-EBAY-SOA-OPERATION-NAME", "createUploadJob"
 xhr.setRequestHeader "CONTENT-TYPE", "XML"
 xhr.setRequestHeader "X-EBAY-SOA-SECURITY-TOKEN", DLookup("[eBay_Token]", "Clients", "[Select_Client] = TRUE")
 xhr.setRequestHeader "X-EBAY-API-APP-Name", APPID
 xhr.setRequestHeader "X-EBAY-API-DEV-NAME", DEVID
 xhr.setRequestHeader "X-EBAY-API-CERT-NAME", CERTID
 
 
 
 'Build Request Body
 bodydetails = "<?xml version=" & """" & "1.0" & """" & " encoding=" & """" & "utf-8" & """" & "?>"
 bodydetails = bodydetails & "<createUploadJobRequest xmlns=" & """" & "http://www.ebay.com/marketplace/services" & """" & ">"
 bodydetails = bodydetails & "<fileType>XML</fileType>"
 bodydetails = bodydetails & "<uploadJobType>ReviseFixedPriceItem</uploadJobType>"
 bodydetails = bodydetails & "<UUID>" & uuid & "</UUID>"
 bodydetails = bodydetails & "</createUploadJobRequest>"
 Debug.Print bodydetails
 
 xhr.send (bodydetails)


 If xhr.status = 200 Then
   Debug.Print xhr.responseText
   
     'Extract Job ID
    Dim xmlDoc As DOMDocument
    Dim myItem As IXMLDOMElement
    Set xmlDoc = New DOMDocument
    
    xmlDoc.LoadXML xhr.responseText
    For Each myItem In xmlDoc.getElementsByTagName("jobId")
    rs.AddNew
    rs!Client_Email = Forms!Main_Screen.clientlist
    rs!JobID = myItem.text
    rs!JobStatus = "In Progress"
    rs!JobCreated = Now
    rs!uuid = uuid
    Next
    
    xmlDoc.LoadXML xhr.responseText
    For Each myItem In xmlDoc.getElementsByTagName("fileReferenceId")
    rs!RefID = myItem.text
    Next
    
    xmlDoc.LoadXML xhr.responseText
    For Each myItem In xmlDoc.getElementsByTagName("MaxFileSize")
    rs!MaxFileSize = myItem.text
    rs.Update
    rs.Close
    Next


 Else
   Debug.Print xhr.status & ": " & xhr.statusText
   Exit Sub
 End If
 
 '----------------------------------------------------------------------------------------------------------------------
 
 'Create Merchant Data File
 
 Dim XMLstr As String

Dim rsm As DAO.Recordset
Set rsm = CurrentDb.OpenRecordset("Template")

XMLstr = XMLstr & "<?xml version=" & """" & "1.0" & """" & " encoding=" & """" & "utf-8" & """" & "?>"
XMLstr = XMLstr & "<BulkDataExchangeRequests>"
XMLstr = XMLstr & "<Header>"
XMLstr = XMLstr & "<SiteID>" & ebaysite & "</SiteID>"
XMLstr = XMLstr & "<Version>583</Version>"
XMLstr = XMLstr & "</Header>"

If Not (rsm.EOF And rsm.BOF) Then
    rsm.MoveFirst
    Do Until rsm.EOF = True
  
XMLstr = XMLstr & "<ReviseFixedPriceItemRequest xmlns=" & """" & "urn:ebay:apis:eBLBaseComponents" & """" & ">"
XMLstr = XMLstr & "<Item>"
XMLstr = XMLstr & "<ItemID>" & rsm!eBayItemID & "</ItemID>"
XMLstr = XMLstr & "<SKU>" & rsm!SKU & "</SKU>"
XMLstr = XMLstr & "<Description><![CDATA[" & rsm!HTMLListingDescription & "]]></Description>"
XMLstr = XMLstr & "</Item>"
XMLstr = XMLstr & "<Version>967</Version>"
XMLstr = XMLstr & "<ErrorLanguage>en_GB</ErrorLanguage>"
XMLstr = XMLstr & "<WarningLevel>Low</WarningLevel>"
XMLstr = XMLstr & "</ReviseFixedPriceItemRequest>"

rsm.MoveNext
Loop

XMLstr = XMLstr & "</BulkDataExchangeRequests>"
XMLLen = LenB(XMLstr)

Debug.Print XMLstr

XMLstr = Stream_StringToBinary(XMLstr)



rsm.Close

End If

'Debug.Print XMLstr
 
 '----------------------------------------------------------------------------------------------------------------------
 
 'Upload File
 'Create UUID's
 XMLUUID = Replace(Left(DLookup("[Company_Name]", "Clients", "[Select_Client] = TRUE"), 10), " ", "-") & Format(Now, "number") & Format(Now, "number")
 CONTUUID = Replace(Left(DLookup("[Company_Name]", "Clients", "[Select_Client] = TRUE"), 10), " ", "-") & Format(Now, "number") & Format(Now, "number") & Format(Now, "number")
 ATTUUID = Replace(Left(DLookup("[Company_Name]", "Clients", "[Select_Client] = TRUE"), 10), " ", "-") & Format(Now, "number") & Format(Now, "number") & Format(Now, "number") & Format(Now, "number")
 
 Set xhr = CreateObject("Microsoft.XMLHTTP")
 
   'Production
  webServiceURL = "https://storage.ebay.com/FileTransferService"
  
  'Sandbox
  'webServiceURL = "https://storage.sandbox.ebay.com/FileTransferService"

 xhr.Open "POST", webServiceURL, False
 
 xhr.setRequestHeader "CONTENT-TYPE", "text/xml"
 xhr.setRequestHeader "X-EBAY-SOA-OPERATION-NAME", "uploadFile"
 xhr.setRequestHeader "X-EBAY-SOA-SECURITY-TOKEN", DLookup("[eBay_Token]", "Clients", "[Select_Client] = TRUE")
 xhr.setRequestHeader "X-EBAY-SOA-SERVICE-NAME", "FileTransferService"
 xhr.setRequestHeader "X-EBAY-SOA-SERVICE-VERSION", "1.0.0"
 xhr.setRequestHeader "X-EBAY-API-APP-Name", APPID
 xhr.setRequestHeader "X-EBAY-API-DEV-NAME", DEVID
 xhr.setRequestHeader "X-EBAY-API-CERT-NAME", CERTID
 
 

 bodydetails = "<?xml version=" & """" & "1.0" & """" & " encoding=" & """" & "utf-8" & """" & "?>"
 bodydetails = bodydetails & "<uploadFileRequest xmlns=" & """" & "http://www.ebay.com/marketplace/services" & """" & ">"
 bodydetails = bodydetails & "<fileAttachment>"
 bodydetails = bodydetails & "<Data><xop:Include xmlns:xop=" & """" & "http://www.w3.org/2004/08/xop/include" & """" & " href=" & """" & "cid:urn:uuid:" & CONTUUID & "/></Data>"
 bodydetails = bodydetails & "<Size>" & XMLLen & "</Size>"
 bodydetails = bodydetails & "</fileAttachment>"
 bodydetails = bodydetails & "<fileFormat>zip</fileFormat>"
 bodydetails = bodydetails & "<fileReferenceId>" & DLookup("[RefID]", "UploadJobs", "[Client_Email] = " & """" & DLookup("[Email_Address]", "Clients", "[Select_Client] = TRUE") & """") & "</fileReferenceId>"
 bodydetails = bodydetails & "<taskReferenceId>" & DLookup("[JobID]", "UploadJobs", "[Client_Email] = " & """" & DLookup("[Email_Address]", "Clients", "[Select_Client] = TRUE") & """") & "</taskReferenceId>"
 bodydetails = bodydetails & "</uploadFileRequest>"

 
 Debug.Print bodydetails
 
 xhr.send (bodydetails)


 If xhr.status = 200 Then
   Debug.Print xhr.responseText

 Else
   Debug.Print xhr.responseText
   Debug.Print xhr.status & ": " & xhr.statusText
   Exit Sub
 End If
 
 '---------------------------------------------------------------------------------------------------------------------------
 
 'Start Upload Job
 
Set xhr = CreateObject("Microsoft.XMLHTTP")

  'Production
  webServiceURL = "https://webservices.ebay.com/BulkDataExchangeService"
  
  'Sandbox
  'webServiceURL = "https://webservices.sandbox.ebay.com/BulkDataExchangeService"

 xhr.Open "POST", webServiceURL, False
 
 xhr.setRequestHeader "X-EBAY-SOA-SERVICE-VERSION", "1.0.0"
 xhr.setRequestHeader "X-EBAY-SOA-SERVICE-NAME", "BulkDataExchangeService"
 xhr.setRequestHeader "X-EBAY-SOA-OPERATION-NAME", "startUploadJob"
 xhr.setRequestHeader "CONTENT-TYPE", "XML"
 xhr.setRequestHeader "X-EBAY-SOA-SECURITY-TOKEN", DLookup("[eBay_Token]", "Clients", "[Select_Client] = TRUE")
 

 bodydetails = "<?xml version=" & """" & "1.0" & """" & " encoding=" & """" & "utf-8" & """" & "?>"
 bodydetails = bodydetails & "<startUploadJobRequest xmlns=" & """" & "http://www.ebay.com/marketplace/services" & """" & ">"
 bodydetails = bodydetails & "<jobId>" & DLookup("[JobID]", "UploadJobs", "[Client_Email] = " & """" & DLookup("[Email_Address]", "Clients", "[Select_Client] = TRUE") & """") & "</jobId>"
 bodydetails = bodydetails & "</startUploadJobRequest>"
 
 xhr.send (bodydetails)


 If xhr.status = 200 Then
   'Debug.Print xhr.responseText

 Else
   MsgBox xhr.status & ": " & xhr.statusText
   Exit Sub
 End If
 
 End Sub

Open in new window


This is my function for encoding Base64

Function Stream_StringToBinary(xmlText)

  'Create Stream object
  Dim BinaryStream 'As New Stream
  Set BinaryStream = CreateObject("ADODB.Stream")

  'Specify stream type - we want To save text/string data.
  BinaryStream.Type = 2

  'Specify charset For the source text (unicode) data.
  BinaryStream.Charset = "us-ascii"

  'Open the stream And write text/string data To the object
  BinaryStream.Open
  BinaryStream.WriteText xmlText

  'Change stream type To binary
  BinaryStream.position = 0
  BinaryStream.Type = 1

  'Ignore first two bytes - sign of
  BinaryStream.position = 0

  'Open the stream And get binary data from the object
  Stream_StringToBinary = BinaryStream.Read
  
  Debug.Print Stream_StringToBinary

  Set BinaryStream = Nothing
End Function

Open in new window


The XML that I build up is below

<?xml version="1.0" encoding="utf-8"?><BulkDataExchangeRequests><Header><SiteID>3</SiteID><Version>583</Version></Header><ReviseFixedPriceItemRequest xmlns="urn:ebay:apis:eBLBaseComponents"><Item><ItemID>132583887122</ItemID><SKU>Fuse1</SKU><Description><![CDATA[Test Description Fuse 1]]></Description></Item><Version>967</Version><ErrorLanguage>en_GB</ErrorLanguage><WarningLevel>Low</WarningLevel></ReviseFixedPriceItemRequest><ReviseFixedPriceItemRequest xmlns="urn:ebay:apis:eBLBaseComponents"><Item><ItemID>132583889690</ItemID><SKU>Repair1</SKU><Description><![CDATA[Test Description Fuse Repair 1]]></Description></Item><Version>967</Version><ErrorLanguage>en_GB</ErrorLanguage><WarningLevel>Low</WarningLevel></ReviseFixedPriceItemRequest></BulkDataExchangeRequests>

Open in new window


If you need any more info please just ask.
0
 
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
I can follow vbs very easily and do not use vba. I have asked a couple of others to help. In the meantime,
> The XML that I build up is below
<Description><![CDATA[Test Description Fuse Repair 1]]></Description>

Open in new window


What is the output of <![CDATA[Test Description Fuse Repair 1]]>?  

We just need to find out the &lt is getting inserted. That looks like something that may not have been supposed to be urlencoded.
0
 
Simon HammillApplication AnalystAuthor Commented:
This is <![CDATA[Test Description Fuse Repair 1]]> is a requirement from eBay so HTML can be sent up in the description.

If you need ID's, I can provide them so you can run the code live if that helps?
0
 
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
I think the CDATA may be causing the issue.

What is the output from rsm!HTMLListingDescription
XMLstr = XMLstr & "<Description><![CDATA[" & rsm!HTMLListingDescription & "]]></Description>"

Open in new window


https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/xml-literals/xml-cdata-literal
0
 
Simon HammillApplication AnalystAuthor Commented:
Hi Mate,

The output of this is just a basic text description but at times it can contain a lot of HTML, I use this for all my other eBay calls and it works fine. Without it, the call won't accept HTML as a description.
0
 
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
If I get a chance to try the code out next week I will. In the meantime what is the the output?  Does it fail with text as well as html output? or just html?  If it is just html that may be a clue.
0
All Courses

From novice to tech pro — start learning today.