[AccessD] Calling API's from VBA

newsgrps at dalyn.co.nz newsgrps at dalyn.co.nz
Wed Sep 9 01:19:19 CDT 2020


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






More information about the AccessD mailing list