user2165379
user2165379

Reputation: 479

How can I read a HTTP-header while making an API call from Excel VBA using JSON?

I am making API-calls to a server from Excel VBA by using this JsonConverter:

*) https://github.com/VBA-tools/VBA-JSON/blob/master/JsonConverter.bas

I use this commands which works fine:

http.Open "GET", APIString, False
http.send    
Set JSON = ParseJson(http.responseText)

Although in some cases the received JSON-string is corrupt and my code stops with an error.

If I am correct, there should be a 'http-header' containing a number which indicates the JSON-string is corrupt.

Do you know where and how I can import this 'http-header' from Excel VBA. In that case I could cancel my API-call in those cases the number in the header indicates the content is corrupt.

Thanks!

Upvotes: 0

Views: 1032

Answers (1)

FunThomas
FunThomas

Reputation: 29296

Check the status of your http-request:

if http.Status = 200 Then
    Set JSON = ParseJson(http.responseText)
else
    ' ... (error handling)
end if

Upvotes: 2

Related Questions