[AccessD] Calling API's from VBA
newsgrps at dalyn.co.nz
newsgrps at dalyn.co.nz
Wed Sep 9 01:29:01 CDT 2020
Solved it. "text/json" worked. The error was because the record had
already been uploaded previously.
-----Original Message-----
From: AccessD <accessd-bounces at databaseadvisors.com> On Behalf Of
newsgrps at dalyn.co.nz
Sent: Wednesday, 9 September 2020 6:19 pm
To: 'Access Developers discussion and problem solving'
<accessd at databaseadvisors.com>
Subject: Re: [AccessD] Calling API's from VBA
I have tried to adapt Gustav's code but I am getting an error 415 -
Unsupported Media Type
It seems to be related to the Content-Type setting. I have tried multiple
options with the error codes below. Here is my code:
Dim XmlHttp As New ServerXMLHTTP60
XmlHttp.Open "POST", "https://dispatch.exd.nz/API/CreateOrders",
False
XmlHttp.setRequestHeader "Content-Type", "application/xml" 'Error
415 - Unsupported Media Type
' XmlHttp.setRequestHeader "Content-Type",
"application/x-www-form-urlencoded" 'Error 415
' XmlHttp.setRequestHeader "Content-Type", "text/xml" 'Error 415
' XmlHttp.setRequestHeader "Content-Type", "text/html" 'Error 415
' XmlHttp.setRequestHeader "Content-Type", "text/json" 'Error 500 -
Internal server Error
' XmlHttp.setRequestHeader "Content-Type", "application/json"
'Error 500
XmlHttp.Send strRequestBody
strResponseText = XmlHttp.responseText
MsgBox XmlHttp.Status
Here is an example of the strRequestBody:
{"orders": [{"order_number": "TestGS16193","reference":
"CoRef","destination": {"name": "Bob Builder","email":
"bob at gmail.com","company": "HV Services","building": "","street": "66 Natu
Street","suburb": "Stoke","city": "Wherever","post_code": "9999","country":
"New Zealand"}}]}
Any pointers to what I need to check?
Regards
David Emerson
Dalyn Software Ltd
Wellington, New Zealand
From: AccessD <accessd-bounces at databaseadvisors.com> On Behalf Of Stuart
McLachlan
Sent: Monday, 10 August 2020 4:14 pm
To: Access Developers discussion and problem solving
<accessd at databaseadvisors.com>
Subject: Re: [AccessD] Calling API's from VBA
There are several ways to do it.
Gustav posted a method of getting data a few days ago using XMLHTTP
https://github.com/GustavBrock/VBA.Random
The actual module code is at
https://github.com/GustavBrock/VBA.Random/blob/master/Random.bas
The relevant part of that code for your purposes is the function:
Private Function RetrieveDataResponse( _
ByVal ServiceUrl As String, _
ByRef ResponseText As String) _
As Boolean
A variation of that using
XmlHttp.Open "PUT", ServiceUrl, Async
instead of
XmlHttp.Open "GET", ServiceUrl, Async
should work the other way.
' Required reference:
' Microsoft XML, v6.0
--
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com
More information about the AccessD
mailing list