VBA excel 是否可以调用 API DataRoboot? [英] is it possible VBA excel to call API DataRoboot?

查看:25
本文介绍了VBA excel 是否可以调用 API DataRoboot?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在VBA中,我们可以使用VBA excel从Prediction DataRobot调用API吗?

in VBA, could we use VBA excel to call API from Prediction DataRobot?

有人知道模板脚本吗?谢谢

Does anyone know about the template script? Thanks

推荐答案

是的,您可以使用 VBA 发送 API 请求!这是我用来执行简单 API 请求的非常基本的函数.它适用于大多数网站上的 GET 请求.对于 POST 或 PUT,您需要知道它们特定的 URL Scheme 和 Body 文本格式.

Yes, you can send API requests using VBA! Here is the very basic function that I use to do simple API requests. It works for me with GET requests on most websites. For POST or PUT, you will need to know their specific URL Scheme and Body text format.

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 excel 是否可以调用 API DataRoboot?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆