【问题标题】:Pipedrive: PUT to update filter from vba?Pipedrive:PUT从vba更新过滤器?
【发布时间】:2020-07-13 16:45:40
【问题描述】:

我正在尝试更新 Pipedrive CRM 中的过滤器; Pipedrive API Ref

使用;

strURL = strURL & “/filters/{25}?api_token=” & strToken
'https://xx.pipedrive.com/v1/filters/{25}?api_token=xx

'Set filter 
With CreateObject(“MSXML2.XMLHTTP”) 
.Open “PUT”, strURL, False 
.setRequestHeader “Content-Type”, “application/json” 
.Send (strSql) 
txt = .responseText 
End With'

返回;

{“status”:false,“error”:“Unknown method .”}

Pipedrive API 非常新,以前从未 PUT!

过滤器 JSON 是;

strSql = "{" & Chr(34) & "glue" & Chr(34) & ":" & Chr(34) & "and" & Chr(34) & "," & Chr(34) & "conditions" & Chr(34) & ":[{" & Chr(34) & "glue" & Chr(34) & ":" & Chr(34) _ & "and" & Chr(34) & "," & Chr(34) & "conditions" & Chr(34) & ": [{" & Chr(34) & "object" & Chr(34) & ":" & Chr(34) & "organization" & Chr(34) & "," & Chr(34) _ & "field_id" & Chr(34) & ":" & Chr(34) & "3997" & Chr(34) & "," & Chr(34) & "operator" & Chr(34) & ":" & Chr(34) & "<" & Chr(34) & "," & Chr(34) & "value" & Chr(34) _ & ":" & Chr(34) & VarCreated & Chr(34) & "},{" & Chr(34) & "object" & Chr(34) & ":" & Chr(34) & "organization" & Chr(34) & "," & Chr(34) & "field_id" & Chr(34) & ":" & Chr(34) _ & "3998" & Chr(34) & "," & Chr(34) & "operator" & Chr(34) & ":" & Chr(34) & ">" & Chr(34) & "," & Chr(34) & "value" & Chr(34) & ":" & Chr(34) & VarUpdated & Chr(34) _ & "}]},{" & Chr(34) & "glue" & Chr(34) & ":" & Chr(34) & "or" & Chr(34) & "," & Chr(34) & "conditions" & Chr(34) & ":[]}]}"

【问题讨论】:

标签: ms-access vba pipedrive-api


【解决方案1】:

亲爱的读者,答案是;您必须发送整个过滤器 JSON - 不仅仅是条件。 我看不到任何地方都记录了这一点!

这是从Stackoverflow.com/questions/43493333 创建/更新过滤器的语法

{ “name”:“OrgUpdated”, “type”:“org”, “visible_to”:1, “conditions”:{ “glue”: “and”, “conditions”:[ { “glue”: “ and”, “conditions”: [ { “object”: “organization”, “field_id”: “3997”, “operator”: “”, “value”: “18/08/2018”, “extra_value”: null } ] }, { “胶水”:“或”,“条件”:[] } ] } }

在vba中;

'added
‘strJSON = "{ ‘name’:‘OrgCreated’, ‘type’:‘org’, ‘visible_to’:1, ‘conditions’:{ ‘glue’: ‘and’, ‘conditions’:[ { ‘glue’: ‘and’, ‘conditions’: [ { " _
’ & “‘object’: ‘organization’, ‘field_id’: ‘3997’, ‘operator’: ‘>’, ‘value’: '” & dteCreated & "’, ‘extra_value’: null } ] }, { ‘glue’: ‘or’," _
’ & “‘conditions’: [] } ] } }”

‘Updated
strJSON = "{ ‘name’:‘OrgUpdated’, ‘type’:‘org’, ‘visible_to’:1, ‘conditions’:{ ‘glue’: ‘and’, ‘conditions’:[ { ‘glue’: ‘and’, ‘conditions’: [ " _
& “{ ‘object’: ‘organization’, ‘field_id’: ‘3997’, ‘operator’: ‘<’, ‘value’: '” & dteCreated & "’, ‘extra_value’: null }," _
& “{ ‘object’: ‘organization’, ‘field_id’: ‘3998’, ‘operator’: ‘>’, ‘value’: '” & dteUpdated & “’, ‘extra_value’: null } ] }, { ‘glue’: ‘or’,” _
& “‘conditions’: [] } ] } }”

strJSON = Replace(strJSON, "'", """")

Debug.Print strJSON

请注意,Pipedrive 使用相对时间,因此日期变量来自可用列表;今天、昨天、上周等。

这里有一组函数可以用来做过滤器;

Public Function CreateFilter(FilterJSON As String) As String
’ Returns Filter ID if created or error if not
Dim strURL As String, strToken As String, txt As String
Dim strSql As String, s As String
Dim i As Long, j As Long

strURL = DLookup("[URL]", "tblCRMDetails")
strToken = DLookup("[Token]", "tblCRMDetails")

strURL = strURL & "/filters?api_token=" & strToken
’ Debug.Print strURL

With CreateObject("WinHttp.WinHttpRequest.5.1")
    .Open "POST", URL, False
    .SetRequestHeader "Accept", "application/json"
    .SetRequestHeader "Content-Type", "application/json"
    .Send (FilterJSON)
    txt = .ResponseText
End With
 Debug.Print txt

CreateFilter = txt

i = InStr(txt, "id")
If i > 0 Then
    s = "0"
    j = 0
    Do Until Not IsNumeric(s)
        j = j + 1
        s = Mid(txt, i + 3 + j, 1)
    Loop
    s = Mid(txt, i + 4, j - 1)
    CreateFilter = s
End If
End Function

Public Function DeleteFilter(ID As Long) As Boolean
’ Returns True if Filter Deleted
Dim strURL As String, strToken As String, txt As String
Dim strSql As String, s As String
Dim i As Long, j As Long

strURL = DLookup("[URL]", "tblCRMDetails")
strToken = DLookup("[Token]", "tblCRMDetails")

strURL = strURL & "/filters/" & ID & "?api_token=" & strToken

With CreateObject("WinHttp.WinHttpRequest.5.1") 'WinHttp.WinHttpRequest.5.1
    .Open "DELETE", URL, False
    .SetRequestHeader "Accept", "application/json"
    .SetRequestHeader "Content-Type", "application/json"
    .Send
    txt = .ResponseText
End With
’ Debug.Print txt

    'check success
If InStr(txt, "success"":true") > 0 Then
    DeleteFilter = True
End If
End Function

Public Function UpdateFilter(ID As Long, FilterJSON As String) As String
’ Returns Filter ID if created or error if not
’ txt = UpdateFilter(40, strSql)
Dim strURL As String, strToken As String, txt As String
Dim strSql As String, s As String
Dim i As Long, j As Long

strURL = DLookup("[URL]", "tblCRMDetails")
strToken = DLookup("[Token]", "tblCRMDetails")

strURL = strURL & "/filters/" & ID & "?api_token=" & strToken

With CreateObject("WinHttp.WinHttpRequest.5.1")
    .Open "PUT", strURL, False
    .SetRequestHeader "Accept", "application/json"
    .SetRequestHeader "Content-Type", "application/json"
    .Send (FilterJSON)
    txt = .ResponseText
End With
Debug.Print txt

UpdateFilter = txt

i = InStr(txt, "id")
If i > 0 Then
    s = "0"
    j = 0
    Do Until Not IsNumeric(s)
        j = j + 1
        s = Mid(txt, i + 3 + j, 1)
    Loop
    s = Mid(txt, i + 4, j - 1)
    UpdateFilter = s
End If
End Function

【讨论】:

    猜你喜欢
    • 2017-09-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-26
    • 2017-11-10
    • 2011-01-31
    相关资源
    最近更新 更多