I am developing a tool to assist my sales team in the quotation process.
Majority of our quotation is done in Excel, as part of when the quote is generated it saves the quote as a PDF and I would like it to automatically upload all the quote data and a copy of the PDF to our CRM package using it's API.
I have done this using a VBA script and have managed to get everything to work except the file upload (so it creates a new quote, fills in the customer, items etc).
The upload is done in two parts, first I must retrieve an attachment key, secondly I use that key to upload the file.
The code I am using is as follows, the [ ]'s are where I've removed stuff:
Using plain text I can upload a .txt file and that works fine (get success message and can access the file from the CRM).
However I want to be uploading PDF files.
When I try any of the methods I have been able to find online for converting the data, the upload 'is successful' yet the data when I access the file from the CRM package is corrupt (and a lot larger than the original file (20kbs become around 80kbs)).
Using Postman I am able to upload the file so I know the API and process works. (If anyone knows what Postman does and convert that to VBA!)
How / what am I meant to do to the file to get it into a form I can send the data via XMLHTTP??
I have no idea what I am doing and everything I have managed to get working so far is already due to people online so thank you in advanced!
Majority of our quotation is done in Excel, as part of when the quote is generated it saves the quote as a PDF and I would like it to automatically upload all the quote data and a copy of the PDF to our CRM package using it's API.
I have done this using a VBA script and have managed to get everything to work except the file upload (so it creates a new quote, fills in the customer, items etc).
The upload is done in two parts, first I must retrieve an attachment key, secondly I use that key to upload the file.
The code I am using is as follows, the [ ]'s are where I've removed stuff:
Code:
Public Function UploadQuote()
Dim Req As New XMLHTTP
' retrieve attachment key
Req.Open "POST", [url], False, [username], [password]
Req.setRequestHeader "Content-Type", "text/xml"
Req.send ("<methodCall><methodName>QuoteRetrieveAttachmentKey</methodName>" & _
"<params><param>" & [stuff here] & "</param></params></methodCall>")
Dim AttachmentKey As String
AttachmentKey = Req.responseXML.ChildNodes.Item(1).[few more].Text
Dim FileName As String
FileName = "C:\pdf-test.pdf" 'this is for my testing purposes
' upload the file
Req.Open "POST", [url], False, [username], [password]
Req.setRequestHeader "Content-Type", "multipart/form-data; boundary=[boundary]"
Req.send ("--[boundary]" & vbCrLf & _
"Content-Disposition: form-data; name=""File""; filename=""" & FileName & """" & vbCrLf & _
"Content-Type: application/pdf" & _
vbCrLf & vbCrLf & _
[B][COLOR="#FF0000"][DATA NEEDS TO GO HERE][/COLOR][/B] & _
vbCrLf & "[boundary]" & vbCrLf & _
"Content-Disposition: form-data; name=""AttachmentKey""" & _
vbCrLf & vbCrLf & AttachmentKey & vbCrLf & "[boundary]--")
MsgBox Req.responseText
End Function
Using plain text I can upload a .txt file and that works fine (get success message and can access the file from the CRM).
However I want to be uploading PDF files.
When I try any of the methods I have been able to find online for converting the data, the upload 'is successful' yet the data when I access the file from the CRM package is corrupt (and a lot larger than the original file (20kbs become around 80kbs)).
Using Postman I am able to upload the file so I know the API and process works. (If anyone knows what Postman does and convert that to VBA!)
How / what am I meant to do to the file to get it into a form I can send the data via XMLHTTP??
I have no idea what I am doing and everything I have managed to get working so far is already due to people online so thank you in advanced!