【问题标题】:Excel VBA rest API connection to SuiteCRMExcel VBA REST API 连接到 SuiteCRM
【发布时间】:2018-09-10 21:32:57
【问题描述】:

我有一个要连接到 SuiteCRM 的 Excel 文件。该文件已经通过 REST 通过 msxml2.serverxmlhttp 连接到其他几个应用程序,但我无法弄清楚这一点。

我已经尝试了一百种不同的配置,但我总是得到rest.php的描述、无效的登录错误或错误的数据传递错误,而不是会话ID。

我在 VBA 和 SuiteCRM 之间几乎没有在网上找到任何东西,但这适用于其他其他 API,所以我希望我也可以让它与 SuiteCRM 一起使用。我认为登录凭据是问题的很大一部分,但我现在的用户名和密码只是“admin”和“s”。我已将密码转换为 MD5(我尝试了 2 种不同的方法并获得了 2 种不同的哈希值,但均未成功)。

错误描述太模糊了,我似乎无法缩小问题范围以找出问题所在。任何帮助将不胜感激。

这是我的代码:

Function SuiteCRMInitialRequest() As String
Dim oXH As Object
Dim url As String
    url = "http://192.168.1.1/suitecrm/service/v4_1/rest.php?"
    Set oXH = CreateObject("msxml2.serverxmlhttp")
    With oXH
        .Open "POST", url, False
        .SetRequestHeader "Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"
        .SetRequestHeader "Accept", "application/json"
        .SetRequestHeader "Host", "192.168.1.1"
        .SetRequestHeader "Content-Length", "180"
        .SetRequestHeader "Expect", "100-continue"
        .SetRequestHeader "Connection", "Keep-Alive"
        .SetRequestHeader "method", "login"
        .SetRequestHeader "input_type", "JSON"
        .SetRequestHeader "response_type", "JSON"
        .Send (SuiteCRMJSONBuild4)
        SuiteCRMInitialRequest = .GetAllResponseHeaders
    End With
    Set oXH = Nothing
End Function

Function SuiteCRMJSONBuild4() As String
Dim strOut As String
        strOut = "{"
        strOut = strOut & """user_auth"":"
        strOut = strOut & "{"
        strOut = strOut & """user_name"":" & """" & "admin" & """" & ","
        'strOut = strOut & """password"":" & """" & SHA1HASH("s") & """" & ","
        strOut = strOut & """password"":" & """" & "03c7c0ace395d80182db07ae2c30f034" & """" & ","
        strOut = strOut & """version"":" & """" & "1" & """" & ""
        strOut = strOut & "},"
        strOut = strOut & """application_name"":" & """" & "test" & """" & ","
        strOut = strOut & """name_value_list"":[]" & ""
        strOut = strOut & "}"
ExitProc:
    SuiteCRMJSONBuild4 = strOut
    Debug.Print strOut
    Exit Function
End Function

上面的代码产生: 传入的错误数据; Return to Home 返回主页链接到 192.168.1.31。我不知道那个ip来自哪里,但它不是suitecrm的服务器地址。不知道这是我的问题的一部分还是无关的。

创建的 json 字符串是: {"user_auth":{"user_name":"admin","password":"03c7c0ace395d80182db07ae2c30f034","version":"1"},"application_name":"test","name_value_list":[]}

【问题讨论】:

  • 请针对生成它的代码提供错误描述

标签: excel vba rest api suitecrm


【解决方案1】:

呃。我想通了(偶然)。其他尝试使用 VBA 的人可能会觉得这很有帮助,因为我在网上能找到的东西很少。这最终起作用了(将方法、input_type 和 response_type 作为字符串而不是在标题中发布)。现在我将不得不看看我是否可以得到一个后续请求。非常感谢您查看此内容。

Function SuiteCRMInitialRequest2() As String
Dim oXH As Object
Dim url As String
Dim strAll As String
    url = "http://192.168.1.1/suitecrm/service/v4_1/rest.php?"
    Set oXH = CreateObject("msxml2.serverxmlhttp")
    With oXH
        .Open "POST", url, False
        .SetRequestHeader "Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"
        .SetRequestHeader "Accept", "application/json"
        .SetRequestHeader "Host", "192.168.1.1"
        .SetRequestHeader "Content-Length", "180"
        .SetRequestHeader "Expect", "100-continue"
        .SetRequestHeader "Connection", "Keep-Alive"
        strAll = "method=login&input_type=JSON&response_type=JSON&rest_data=" & SuiteCRMJSONBuild4
        .Send (strAll)
        SuiteCRMInitialRequest2 = .GetAllResponseHeaders
    End With
    Set oXH = Nothing
End Function

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-08-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多