首页 > 解决方案 > Url In Get 请求更新,但从 get 请求返回不更新

问题描述

我有一个获取请求,它调用使用 API 密钥获取 json 数据。当我在浏览器中测试 url 时,它可以很好地处理来自 api 密钥的所有更新数据。当我从 VBA 函数中的 API 密钥返回数据时,它仍然显示以前的数据。

url 更新,但是由于某种原因,保存从 url 调用的 json 数据的变量没有更新,因此仍然包含旧数据。

当我关闭 excel 工作表并重新打开它时,变量会更新为最新数据。我已经被困了一天半了,任何帮助将不胜感激。

这是相关代码:

Public Function getHTTP(ByVal url As String) As String
  Dim xmlhttp As New MSXML2.XMLHTTP60
  With xmlhttp
    .Open "GET", url, False: .send
    getHTTP = StrConv(.responseBody, vbUnicode)
  End With
End Function

Function callingGetReq()
     Dim stage1 As String
     stage1 = "x"
    callingGetReq = " "
    Worksheets("Hub Api Data Sheet").Range("B4", "B2").Clear
    
    Dim email As String
    email = Worksheets("Dom. Inputs").Range("B28").Value
    Dim url As String
    Dim api_key As String
    api_key = "?hapikey=#####################################"
    Dim count As String
    count = "&count=1"
    Dim property As String
    property = "&property=customer_number&property=salutation&property=firstname&property=lastname&property=email&property=zip&property=address&property=city&property=state&property=address_line_2&property=hs_searchable_calculated_phone_number"
    Dim propertyMode As String
    propertyMode = "&propertyMode=value_only"
    Dim formSub As String
    formSub = "&formSubmissionMode=newest"
    Dim listMem As String
    listMem = "&showListMemberships=true"
    url = "https://api.hubapi.com/contacts/v1/contact/email/" + email + "/profile" + api_key + propertyMode + property + formSub + listMem
   
    MsgBox
    
    stage1 = getHTTP(url)
    callingGetReq = stage1
    Worksheets("Hub Api Data Sheet").Range("B4") = callingGetReq

    Worksheets("Hub Api Data Sheet").Range("B2") = url
    ' ActiveCell = " " + callingGetReq + " "
End Function

在其他解决方案中,我试图清除变量,但这无济于事......

任何想法将不胜感激。

标签: jsonexcelvbagetrequest

解决方案


推荐阅读