翻译“ -d”在执行HTTP请求时在VBA中

发布于 2025-02-12 00:48:48 字数 1246 浏览 2 评论 0 原文

我尝试通过发送带有VBA的HTTP请求来获取由“ Template_ID”过滤的IAUDITOR的列表。目前,我有此代码返回所有操作的列表:

Sub Get_Data()
Dim hReq As Object
Dim sht As Worksheet
Dim authKey As String
Dim response As String

authKey = "d8a0df7d7e1XXXXXXXXXXXXXXXXXXXXXXXXff3c765cf2fcf"

Set sht = Sheets(1)

Dim strUrl As String
    strUrl = "https://api.safetyculture.io/tasks/v1/actions/list"
Set hReq = CreateObject("MSXML2.XMLHTTP")
    With hReq
        .Open "POST", strUrl, False
        .SetRequestHeader "Authorization", "Bearer " & authKey
        .SetRequestHeader "Content-Type", "application/json"
        .Send
    End With


    response = hReq.ResponseText
    'MsgBox Len(response)
    sht.Range("A1") = response
End Sub

现在我想将过滤器“翻译”到VBA,但我不知道该怎么做。

这是我有关网站的API文档: https://developer.safether.safetyculture.io/#actions

因此,我想在VBA中翻译的内容在HTTP代码中看起来像这样:

curl -X POST "https://api.safetyculture.io/tasks/v1/actions/list" \
-H "Authorization: Bearer {api_token}" \
-d {
  "template_id": {
    "operator": 7,
    "value": ["fc2e53f6-4712-4ca5-b681-aba3ac954217"]
  }
}

我非常感谢您提供的任何帮助。

问候, 加宾

I try to get a list of actions from iAuditor filtered by "template_id" by sending an HTTP Request with VBA. For the moment I have this code that return the list of all actions:

Sub Get_Data()
Dim hReq As Object
Dim sht As Worksheet
Dim authKey As String
Dim response As String

authKey = "d8a0df7d7e1XXXXXXXXXXXXXXXXXXXXXXXXff3c765cf2fcf"

Set sht = Sheets(1)

Dim strUrl As String
    strUrl = "https://api.safetyculture.io/tasks/v1/actions/list"
Set hReq = CreateObject("MSXML2.XMLHTTP")
    With hReq
        .Open "POST", strUrl, False
        .SetRequestHeader "Authorization", "Bearer " & authKey
        .SetRequestHeader "Content-Type", "application/json"
        .Send
    End With


    response = hReq.ResponseText
    'MsgBox Len(response)
    sht.Range("A1") = response
End Sub

Now I want to "translate" a filter to VBA but I have no idea how to do it.

Here is my API Documentation about the website : https://developer.safetyculture.io/#actions

So what i want to translate in VBA looks like this in HTTP code i guess :

curl -X POST "https://api.safetyculture.io/tasks/v1/actions/list" \
-H "Authorization: Bearer {api_token}" \
-d {
  "template_id": {
    "operator": 7,
    "value": ["fc2e53f6-4712-4ca5-b681-aba3ac954217"]
  }
}

I thank You a lot for any help you can offer me.

Regards,
Gabin

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

话少心凉 2025-02-19 00:48:48

根据此线程:

您可以通过将其作为发送函数中的值传递给帖子请求,将数据添加到帖子请求中:

hReq.send "'template_id': {'operator': 7,'value': ['fc2e53f6-4712-4ca5-b681-aba3ac954217']}"

值由A&字符串中的符号。

According to this thread:
https://www.vbforums.com/showthread.php?592624-Posting-data-using-XMLHttpRequest

you can add Data to a POST Request by passing it as a value in the send function:

hReq.send "'template_id': {'operator': 7,'value': ['fc2e53f6-4712-4ca5-b681-aba3ac954217']}"

Values are differentiated by a & Symbol inside the string.

度的依靠╰つ 2025-02-19 00:48:48

我做到了!!! :d

这是我的最终代码:

Sub Get_Data()
Dim hReq As Object
Dim sht As Worksheet
Dim authKey As String
Dim response As String
Dim response_objet As Object
Dim Body As String

authKey = "d8a0df7d7e19XXXXXXXXXXXXXXXXc65ec9eff3c765cf2fcf"

Body = "{ ""filters"": [ { ""template_id"": { ""value"": [""884b95df35104f4792a3c1fdfed63f0e""]}}]}"
Set sht = Sheets(1)
sht.Range("A3") = Body
Dim strUrl As String
    strUrl = "https://api.safetyculture.io/tasks/v1/actions/list"
Set hReq = CreateObject("MSXML2.XMLHTTP")
    With hReq
        .Open "POST", strUrl, False
        .SetRequestHeader "Authorization", "Bearer " & authKey
        .SetRequestHeader "Content-Type", "application/json"
        .Send Body
    End With


    response = hReq.ResponseText
    'MsgBox Len(response)
    sht.Range("A1") = response
    Set response_objet = JsonConverter.ParseJson(response)
    For Each Item In response_objet
        a = a + 1
        Sheets("Biblio").Range("B" & a) = Item
    Next Item
End Sub

非常感谢@codingwolf,他把我朝着正确的方向。

祝您有美好的互联网。
加宾,

I've did it !!! :D

Here is my final code:

Sub Get_Data()
Dim hReq As Object
Dim sht As Worksheet
Dim authKey As String
Dim response As String
Dim response_objet As Object
Dim Body As String

authKey = "d8a0df7d7e19XXXXXXXXXXXXXXXXc65ec9eff3c765cf2fcf"

Body = "{ ""filters"": [ { ""template_id"": { ""value"": [""884b95df35104f4792a3c1fdfed63f0e""]}}]}"
Set sht = Sheets(1)
sht.Range("A3") = Body
Dim strUrl As String
    strUrl = "https://api.safetyculture.io/tasks/v1/actions/list"
Set hReq = CreateObject("MSXML2.XMLHTTP")
    With hReq
        .Open "POST", strUrl, False
        .SetRequestHeader "Authorization", "Bearer " & authKey
        .SetRequestHeader "Content-Type", "application/json"
        .Send Body
    End With


    response = hReq.ResponseText
    'MsgBox Len(response)
    sht.Range("A1") = response
    Set response_objet = JsonConverter.ParseJson(response)
    For Each Item In response_objet
        a = a + 1
        Sheets("Biblio").Range("B" & a) = Item
    Next Item
End Sub

Huge thanks to @CodingWolf , he put me on the right direction.

Have a nice day internet.
Gabin,

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文