Json 获取请求更新中的Url,但从获取请求返回不';t更新
我有一个get请求,它调用获取带有API键的json数据。当我在浏览器中测试url时,它可以很好地处理来自api键的所有更新数据。当我从VBA函数中的API键返回数据时,它仍然显示以前的数据 url会更新,但是由于某种原因,保存从url调用的json数据的变量不会更新,因此仍然包含旧数据 当我关闭excel工作表并重新打开它时,变量将更新为最新数据。我已经被困一天半了,任何帮助都将不胜感激 以下是相关代码:Json 获取请求更新中的Url,但从获取请求返回不';t更新,json,excel,vba,get,request,Json,Excel,Vba,Get,Request,我有一个get请求,它调用获取带有API键的json数据。当我在浏览器中测试url时,它可以很好地处理来自api键的所有更新数据。当我从VBA函数中的API键返回数据时,它仍然显示以前的数据 url会更新,但是由于某种原因,保存从url调用的json数据的变量不会更新,因此仍然包含旧数据 当我关闭excel工作表并重新打开它时,变量将更新为最新数据。我已经被困一天半了,任何帮助都将不胜感激 以下是相关代码: Public Function getHTTP(ByVal url As String)
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
在其他解决方案中,我试图清除变量,但这无助于
如果您有任何想法,我们将不胜感激。vba对字符串concat使用“&”,而不是“+”。为什么Msgbox是单独购买的?这是一个检验价值的测试。我忘了评论了。我不确定我是否理解。如何调用
callingGetReq()
函数?调用API时唯一可以更改的参数似乎是email
变量。其他一切都是硬编码的。您似乎总是使用与email
相同的值来调用API。除非此工作表(“Dom.Inputs”).Range(“B28”).Value
正在以某种方式更新。始终使用相同的参数调用API将返回相同的结果。除非与特定电子邮件
对应的数据正在动态更新。是这样吗?@StavrosJon。电子邮件是数据库中每个客户的数据的特定id。当我在浏览器中调用url时,数据是最新的。当我在excel get请求中调用相同的URL时,返回的数据是旧的。我认为这与Excel缓存有关?