I am trying to upload a file to an existing invoice and running into nothing but problems using the API. I can GET the files OK so my authentication is all OK. Below is my test code and result just saying there is a problem processing my request.
Is this a VBA code or a XERO API issue.
This is my test code to try an upload a very basic TXT file.
Dim URL As String
Dim http As Object
Dim invfilepath As String
Dim bdy As String
Set http = CreateObject("MSXML2.XMLHTTP")
guidtarget = "995f6b3e-085b-4ec7-82e5-f8b78235f8e3" 'GUID of the invoice
URL = "https://api.xero.com/api.xro/2.0/Invoices/" & guidtarget & "/Attachments/test.txt"
bdy = "This is a test"
toke = Trim(DLookup("\[Access_token\]", "Xero_Tokens")) 'Gets the current token
tid = get_registry("Tennant_ID", "") ' Gets the Tenant ID
http.Open "POST", URL, False
http.setRequestHeader "Authorization: ", "Bearer " & toke
http.setRequestHeader "xero-tenant-id: ", tid
http.setRequestHeader "Content Type:", "text/plain"
http.Send bdy
responsedata = http.responseText
Me!resp = responsedata`
*****************************************************************************
When I run the code I get this
*****************************************************************************
An error occurred while processing your request.
Reference #253.95b92917.1711691972.45a51cbe
https://errors.edgesuite.net/253.95b92917.1711691972.45a51cbe
*****************************************************************************
For anybody that comes across this, I ended up solving it. The Xero API documents are wrong in the CONTENT-TYPE to send as a header (and yes I had a syntax error for the content-type) Here is my code that finally worked