我想为我的 ServiceNow 实例 API 创建 POST
请求。但我不知道如何使用库 VBA-Web .
我想在 ServiceNow 的表中创建一行。
我的代码:
Sub ToRequestSN()
Dim Body As New Dictionary
Body.Add "u_any_string", "test"
Body.Add "u_any_numeral", 12
Dim Client As New WebClient
Dim Response As WebResponse
Set Response = Client.PostJson("https://instance.sn.ru/api/now/table/u_table_test", Body)
Debug.Print Response.Content
End Sub
但是我收到了这个消息-
{"error":{"message":"User Not Authenticated","detail":"Required to provide Auth information"},"status":"failure"}
如何使用 VBA-Web 登录?
最佳答案
我找到了解决方案。我确实发送了选定的邮件(发件人的电子邮件)并传递给 Service Now。
Sub RequestToSN()
Dim Client As New WebClient
Dim Response As WebResponse
Dim Auth As New HttpBasicAuthenticator
Dim Body As New Dictionary
Dim myOlSel As Outlook.Selection
Dim oMail As Outlook.MailItem
Dim myOlExp As Outlook.Explorer
MsgTxt = ""
Set myOlExp = Application.ActiveExplorer
Set myOlSel = myOlExp.Selection
For x = 1 To myOlSel.Count
If myOlSel.Item(x).Class = OlObjectClass.olMail Then
Set oMail = myOlSel.Item(x)
MsgTxt = MsgTxt & oMail.SenderName
''Date = Date & oMail.CreationTime
End If
Next x
Body.Add "u_any_string", MsgTxt
Body.Add "u_any_numeral", 123
Auth.Setup _
Username:="user", _
Password:="user"
Set Client.Authenticator = Auth
Set Response = Client.PostJson("https://service.sn.com/api/now/table/u_table_test", Body)
End Sub
关于vba - HTTPS POST 请求 VBA,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55097097/