REST API Post error
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2019 03:40 AM
I want to create a POST request to my instance, but I get error:
{"error":{"message":"Exception while reading request","detail":"Cannot decode: java.io.StringReader@11c4dca"},"status":"failure"}
I want to create a row in my custom table.
My data in GET request:
{
"result": [
{
"u_any_string": "fromREST",
"sys_id": "14235234523423423",
"u_any_numeral": "12345",
"sys_updated_by": "macros",
"sys_created_on": "2019-03-05 08:49:19",
"sys_mod_count": "0",
"sys_updated_on": "2019-03-05 08:49:19",
"sys_tags": "",
"sys_created_by": "macros"
},
{
"u_any_string": "test",
"sys_id": "23423423423423423",
"u_any_numeral": "666",
"sys_updated_by": "macros",
"sys_created_on": "2019-03-01 07:47:07",
"sys_mod_count": "0",
"sys_updated_on": "2019-03-01 07:47:07",
"sys_tags": "",
"sys_created_by": "macros"
}
]
}
I'm using VBA in Outlook. I want to create row with "u_any_string": "some" and "u_any_numeral": "123".
Check my code
Sub ToRequestSN()
snUser = "user"
snPass = "pass"
TargetURL = "https://instance.sn.com/api/now/table/u_test_import"
Const TIMEOUT& = 10
Dim Payload As String
Text = "a"
Payload = "u_any_string=test&u_any_numeral=12"
Dim WebClient As WinHttp.WinHttpRequest
Set WebClient = New WinHttp.WinHttpRequest
With WebClient
.Open "POST", TargetURL, False
.SetCredentials snUser, snPass, 0
.SetRequestHeader "Content-Type", "application/json"
.Send Payload
.WaitForResponse
Debug.Print .ResponseText
End With
End Sub
With this code, I wil get error Cannot decode: java.io.StringReader@11c4dca
How to fix this?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2019 08:59 AM
Hi Vyacheslav,
The payload should be of content-type application/json
{
"u_any_string":'test",
"u_any_numeral":"12"
}
I would recommend you to test this from any HTTP client like Postman first and once you get it to work, you can put in your code.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2019 09:06 AM
USe REST API explorer to get valid REST JSON payload and then you can build your code to send POST REQUEST.
https://www.youtube.com/watch?v=mIYYy6OewMU
Regards,
Sachin