Utah / insertMultiple - how established full records response
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2023 04:21 AM
hi
I have done json input data that contains many new rows to importset -table, till example.
{ "records" : [ { "short_description" : "this was inserted with python using JSON 1" , "priority" : "1 - Critical" , "impact" : "1" , "caller_id" : "Fred Luddy" } , { "short_description" : "this was inserted with python using JSON 2" , "priority" : "1 - Critical" , "impact" : "1" , "caller_id" : "Fred Luddy" } ] }
And fine, I can upload data with utf8 encoded binary format using url like that:
/api/now/import/{importSetTableName}.do?JSONv2&sysparm_action=insertMultiple&sysparm_transform_after_load=true
But is there some parameter that established json response to return all send records and record's columns back.
I think, that import set table name or sys id is fine to return.
Regards
Jouni
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2023 08:55 AM - edited 05-31-2023 08:56 AM
Hi Jouni,
A JSON response is always returned regardless of the parameters you provide (even in the case of a bad request, a JSON is returned with error information).
Using the REST API Explorer, I tested out the Insert Multiple Records POST in the Import Set API.
A successful request returned the following response:
{
"import_set_id": "ca54e30b47032110632082c2e36d43f1",
"multi_import_set_id": "0254e30b47032110632082c2e36d43f2"
}
A bad request returned the following response:
{
"error": {
"message": "Invalid JSON Object",
"detail": "There is no root array element with name records"
},
"status": "failure"
}
From here, you would need to send another API to get the specific records that were created, or create your own Multiple Records POST that is able to return the results you'd like.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2023 11:40 AM
Hi and many thanks your answer.
I test to send data by Rest Api Explorer and so I may link https://excaliburXXXXX.service-now.com/api/now/import/{my impot set table}
Then I set that link to my C# url and I have right parsed json string ,
My client has binary username and password too.
I will send my json data to servicenow like this:
byte[] utf8Bytes = Encoding.UTF8.GetBytes(json);
byte[] resp = client.UploadData(url, "POST", utf8Bytes);
stringResponse = Encoding.UTF8.GetString(resp);
And response gives import set knows .. juts fine.
But if my column till .example description has characters like \\ or some emoijs then my upload gives bad request .
If I send same json data by url /api/now/import/{importSetTableName}.do?JSONv2&sysparm_action=insertMultiple&sysparm_transform_after_load=true
then data uploads fine .. all characters end emoijs are accept.
May I set scripted rest api .. where I parse arrived Json to import set table .. and then there I can do own response too.
I like these above links, because they automatic parse input data to importset table.
br,
Jouni