Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-17-2025, 04:23 AM
Pf@nne Pf@nne is offline VBA HTTP Post - Problem with JSON Payload Windows 11 VBA HTTP Post - Problem with JSON Payload Office 2021
Novice
VBA HTTP Post - Problem with JSON Payload
 
Join Date: Aug 2025
Posts: 1
Pf@nne is on a distinguished road
Default VBA HTTP Post - Problem with JSON Payload

Moin,

I want to send an HTTP post using VBA.
It works quite well when sent WITHOUT a payload.

Code:
Private Function http_post(url As String, payload As String) As String
  Dim req As MSXML2.ServerXMLHTTP60
  Set req = New MSXML2.ServerXMLHTTP60

  With req
    .Open "POST", url, False
    .setRequestHeader "Accept:", "application/json"
    .setRequestHeader "Content-Type:", "application/json"
    .setRequestHeader "X-Api-Key:", "---"
    .send
    http_post = .responseText
  End With
End Function
The HTTP API can also be further specified via a JSON payload.
The working PYTHON code for this looks like this:

Code:
import requests

url = "https://api.bavest.co/v0/quote"

payload = { "isin": "US02079K3059" }

headers = {
"accept": "application/json",
"content-type": "application/json",
"x-api-key": "---"
}

response = requests.post(url, json=payload, headers=headers)
print(response.text)



For this I extended my code as follows:

Code:
Private Function http_post(url As String, payload As String) As String
  Dim req As MSXML2.ServerXMLHTTP60
  Set req = New MSXML2.ServerXMLHTTP60

  payload = "{ ""isin"": ""US02079K3059"" }"

  With req
    .Open "POST", url, False
    .setRequestHeader "Accept:", "application/json"
    .setRequestHeader "Content-Type:", "application/json"
    .setRequestHeader "X-Api-Key:", "---"
    .send payload
    http_post = .responseText
  End With
End Function
For this I extended my code as follows:
Quote:
{"message": "Symbol does not exist.", "status": "ERROR"}
With this String:
Code:
payload = "{ 'isin': 'US02079K3059' }"
The API returns:
Quote:
{"message": "Internal server error"}

Code:
payload = "{ ""isin"": ""US02079K3059"" }"
Seems to be accepted by the API, but cannot fully interpret the content.

Code:
payload = "{ 'isin': 'US02079K3059' }"
It doesn't even seem to be recognized as valid JSON.
What am I doing wrong here?


Greetings
Pf@nne
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with a post in the Word forum - goes to a static page Charles Kenyon Forum Support 1 12-06-2023 08:53 AM
Get Zip code detail via JSON in VBA. Mangesh1212 Excel Programming 1 12-18-2018 07:26 PM
http/1.0 404 not found Powerpoint User PowerPoint 2 11-20-2016 11:10 PM
How to Work with JSON in word-vba PRA007 Word VBA 1 05-01-2016 02:53 PM
Outlook http server joelwelford Outlook 0 09-07-2015 10:00 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:54 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft