'how to invoke api url in outlook userform

I have created userform and try to input parameters and invoke the api url to “create incident”

api url:https://***.com/incident/create

to create an incident http post a json payload to the url above,example as below

{

“state”:“**”
“caller_id”:“**”
.
.
.
“urgency”=“**”
}

outlook userfrom has been created for inputting parameters just to match the json,so how could user invoke the api url in the userform to “create incident” in the userform ui?



Solution 1:[1]

Here is an example which shows how you can use web calls from VBA (not only from user forms):

Sub listPokemons()
Dim json As String
Dim jsonObject As Object, item As Object
Dim i As Long
Dim ws As Worksheet
Dim objHTTP As Object
 
'We selected our results sheet
Set ws = Worksheets("results")
 
'We create our request object and send
Set objHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")
URL = "https://pokeapi.co/api/v2/pokemon"
objHTTP.Open "GET", URL, False
objHTTP.Send
strResult = objHTTP.responseText
json = strResult
 
Set objectJson = JsonConverter.ParseJson(json)
 
'We create the header cells
ws.Cells(1, 1) = "name"
ws.Cells(1, 2) = "link"
 
'We loop the results property of the API response
i = 2 'We will start the counter on line 2
For Each pokemon InJsonObject("results")
    ws.Cells(i, 1) = pokemon("name")
    ws.Cells(i, 2) = pokemon("url")
    i = i + 1
next
 
End Sub

It is possible to perform all types of requests - GET, POST, UPDATE.

Read more about that in the How to use Excel VBA to query REST JSON APIs article.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Eugene Astafiev