dan
dan

Reputation: 15

How to make REST call to Content-Type="application/json" via VBA in Excel?

I'm using Google Chrome REST API to get information from my web server. I use: Content-Type = "application/json" and a Post command that includes groovy code inside the Payload (the header remains empty):

{ "aaa": "dan", "bbb": "my_data", "ccc": "my_type" }

or sometimes the Post is empty also in the Payload

This works just fine (I'm getting the response in json format)

I want to post this command with VBA from excel so the response would get into a VBA variable, which I can then print into some cell in the worksheet. How do I do it?

Do I need to download some library for that?

I tried (without success):

Set objHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")

URL = "[my_URL]"

objHTTP.Open "POST", URL, False

objHTTP.setRequestHeader "Content-type", "application/json"

Worksheets("sheet1").Cells(1, 1)=objHTTP

Please advise,

Upvotes: 0

Views: 2679

Answers (1)

dan
dan

Reputation: 15

Needed to add: objHTTP.setTimeouts 30000, 60000, 30000, 120000

Upvotes: 0

Related Questions