【发布时间】:2021-03-15 07:24:52
【问题描述】:
我正在尝试将 Web API 与 Excel VBA 一起使用。
在 API 说明中是这样写的:
使用 cURL
curl https://{subdomain}.zendesk.com/api/v2/users/create_or_update.json \
-d '{"user": {"name": "Roger Wilco", "email": "roge@example.org"}}' \
-H "Content-Type: application/json" -X POST \
-v -u {email_address}:{password}
链接到 API 本身(创建或更新用户)https://developer.zendesk.com/rest_api/docs/support/users#create-or-update-user
这是我的代码:
Public Function PostJsonRequest() As String
Dim strURL As String
Dim strParse() As String
Dim jsonStr As String
Dim hreq As Object
Dim tixScript As Object
On Error GoTo Er
Set hreq = CreateObject("MSXML2.XMLHTTP")
strURL = "https://subdomain.zendesk.com/api/v2/users/create_or_update"
hreq.Open "POST", strURL, 0, "username/token", "token"
hreq.setRequestHeader "User-Agent", "Chrome"
hreq.setRequestHeader "Content-Type", "application/json"
hreq.setRequestHeader "Accept", "application/json"
hreq.setRequestHeader "-v -u {MyEmail}:{MyPassword}"
jsonStr = "-d '{""user"": {""name"": ""Roger Wilco"", ""email"": ""roge@example.org""}}'"
hreq.Send jsonStr
MsgBox hreq.responseText
Exit Function
Er:
MsgBox "Error - " & Err.Number & " - " & Err.Description
End Function
在电子邮件和密码行我收到此错误:
错误 - 450 - 参数数量错误或属性分配无效
【问题讨论】:
标签: json excel vba api zendesk-api