是否可以 VBA excel 调用 API DataRoboot?
is it possible VBA excel to call API DataRoboot?
在 VBA 中,我们可以使用 VBA excel 从 Prediction DataRobot 调用 API 吗?
有人知道模板脚本吗?
谢谢
是的,您可以使用 VBA 发送 API 请求!这是我用来执行简单 API 请求的非常基本的功能。它适用于大多数网站上的 GET 请求。对于 POST 或 PUT,您需要了解它们特定的 URL 方案和正文文本格式。
Public Function API( _
ByVal URL As String, _
ByVal Action As String, _
Optional Body As String = "") As String
'Action is GET, POST, PUT or DELETE
Dim http As Object
Set http = CreateObject("WinHttp.WinHttpRequest.5.1")
http.Open Action, URL, False
If Action <> "GET" Then http.SetRequestHeader "Content-Type", "application/json"
If Body <> "" Then
http.Send Body
Else
http.Send
End If
If http.Status = 200 And Action <> "GET" Then
API = "Successfully Sent!"
Else
If http.Status <> 200 And http.responsetext = "" Then
API = http.statustext
Else
API = http.responsetext
End If
End If
End Function
在 VBA 中,我们可以使用 VBA excel 从 Prediction DataRobot 调用 API 吗?
有人知道模板脚本吗? 谢谢
是的,您可以使用 VBA 发送 API 请求!这是我用来执行简单 API 请求的非常基本的功能。它适用于大多数网站上的 GET 请求。对于 POST 或 PUT,您需要了解它们特定的 URL 方案和正文文本格式。
Public Function API( _
ByVal URL As String, _
ByVal Action As String, _
Optional Body As String = "") As String
'Action is GET, POST, PUT or DELETE
Dim http As Object
Set http = CreateObject("WinHttp.WinHttpRequest.5.1")
http.Open Action, URL, False
If Action <> "GET" Then http.SetRequestHeader "Content-Type", "application/json"
If Body <> "" Then
http.Send Body
Else
http.Send
End If
If http.Status = 200 And Action <> "GET" Then
API = "Successfully Sent!"
Else
If http.Status <> 200 And http.responsetext = "" Then
API = http.statustext
Else
API = http.responsetext
End If
End If
End Function