[AccessD] Calling API's from VBA

Stuart McLachlan stuart at lexacorp.com.pg
Wed Sep 9 02:00:45 CDT 2020


"The HTTP 415 Unsupported Media Type client error response code indicates that the server 
refuses to accept the request because the payload format is in an unsupported format. The 
format problem might be due to the request's indicated Content-Type or Content-Encoding , 
or as a result of inspecting the data directly"

Note the last nine words.

Apparently the server looked at the data and said "You've told me this is XML, but it's not 
valid XML, I don't know how to handle it".

(Your example string is JSON encoded, not XML.)


On 9 Sep 2020 at 18:29, newsgrps at dalyn.co.nz wrote:

> 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
> 
> -- 
> 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