Click here to Skip to main content
15,867,488 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,
Please I need your help. I try to communicate with a site using their API
the site explains explicitly how to do it: NFIB[^]

I always get error message "error:context null, No application name header or parameter value in request, code 400."


I think i may have problem with set request header or the body.

below is my code

What I have tried:

Option Explicit
Sub testAPI()

Dim Body, line1, line2, line3, line4, line5, line6, line7, line8, line9, line10 As String

Dim request As New MSXML2.ServerXMLHTTP60

request.Open "POST", "http://open.api.nfib-sbet.org/rest/sbetdb/_proc/getIndicators", False

request.SetRequestHeader "Content-type", "application/json"
request.SetRequestHeader "Accept", "application/json"

line1 = "{"
line2 = """app_name"": ""sbet"","
line3 = """params"": ["
line4 = "{ ""name"": ""minYear"", ""param_type"": ""IN"", ""value"": 2010 },"
line5 = "{ ""name"": ""minMonth"", ""param_type"": ""IN"", ""value"": 6 },"
line6 = "{ ""name"": ""maxYear"", ""param_type"": ""IN"", ""value"": 2010 },"
line7 = "{ ""name"": ""maxMonth"", ""param_type"": ""IN"", ""value"": 12 },"
line8 = "{ ""name"": ""indicator"", ""param_type"": ""IN"", ""value"": ""OPT_INDEX"" }"
line9 = "]"
line10 = "}"

<pre>Body = line1 & line2 & line3 & line4 & line5 & line6 & line7 & line8 & line9 & line10



request.Send Body

If request.Status <> 200 Then
MsgBox request.ResponseText
Exit Sub
End If

End Sub
Posted
Updated 17-Sep-22 23:49pm
v2
Comments
Richard MacCutchan 17-Sep-22 9:52am    
You should check the complete request that is being sent to the web page.
Member 14270589 18-Sep-22 5:50am    
Thanks Richard, I checked the code line by line, the request sent to the web but still i missing something.
Richard MacCutchan 18-Sep-22 8:46am    
Looking at your code and the sample at the NFIB website I cannot see what is wrong either; sorry.
Richard MacCutchan 18-Sep-22 10:00am    
I just noticed the following notes on the NFIB website:

Please note that a POST should always be used to call an SBET stored procedure and the required parameters should be added in the HTTP Header.

The outgoing request should consist of the following HEADER parameters:

I have tried this a number of times, but always receive: HTTP Error 400: Bad Request
Member 14270589 19-Sep-22 2:18am    
I looked at what you mentioned for the HTTP header, so it might be the problem is with setRequestHeader; I tried to add more of setRequestHeader options but still issue not solved, thanks much Richard for your notes.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900