Pipedrive:PUT是否要从vba更新过滤器?

时间:2018-08-14 02:26:50

标签: access-vba pipedrive-api

我正在尝试更新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来说是全新的,从来没有之前输入过!

过滤器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) & ":[]}]}"

1 个答案:

答案 0 :(得分:0)

  

亲爱的读者,答案是:您必须发送整个过滤器JSON-不仅仅是条件。   我看不到任何记录!

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

  

{“名称”:“ OrgUpdated”,“类型”:“ org”,“ visible_to”:1,“ conditions”:{“ glue”:“ and”,“ conditions”:[{“ glue”:“ and”,“ conditions”:[{“ object”:“ organization”,“ field_id”:“ 3997”,“ operator”:“ <”,“ value”:“ 18/08/2018”,“ extra_value”:null },{“ object”:“ organization”,“ field_id”:“ 3998”,“ 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使用相对时间,因此date变量来自可用列表;今天,昨天,最后一周等。

这是一组用于进行过滤的功能;

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