difficulty running Import Set insertMultiple REST API

Dave Oshinsky
Tera Expert

I'm trying to write a program that imports multiple JSON records to a target table with one REST API call. The documentation for the insertMultiple API is focused on running this manually (via the web UI), rather than attempting to use REST API calls from a program. It does not explain that the Transform Map is stored in sys_transform_map, and the Field Map is stored in sys_transform_entry. The documentation also doesn't explain essential prerequisites for running insertMultiple, such as how to create the Staging Table.

 

There's a really excellent post that adds a lot of detail to Service Now's Import Set API documentation, such as how to run insertMultiple synchronously and observe the resulting statistics:

https://www.servicenow.com/community/architect-forum/insertmultiple-import-set-api/m-p/2442022

 

I tried posting this query initially as a reply to the above, but that silently disappeared.  So, here I am with a new Question.

 

If I simply create a Staging Table with fields matching the fields in the JSON to import, insertMultiple fails like this:

Response code 400 value '{"error":{"message":"Invalid staging table","detail":"Specified table does not extend 'sys_import_set_row'"},"status":"failure"}'

 

I then re-created the Staging Table to extend sys_import_set_row, and manually added the same fields as in the JSON to import.  I also added a Transform Map for the source_table and target_table to sys_transform_map, and a Field Map mapping JSON fields to the same field names in sys_transform_entry. The sys_transform_entry table (not documented anywhere that I've seen, but it's used for pre-existing Transform Maps) names source and target tables and fields, and has a "map" field pointing to the sys_transform_map row. In other words, multiple Field Map items in sys_transform_entry refer to the Transform Map row in sys_transform_map.

 

The import now succeeds, and sys_import_set_run shows multiple inserts. I see the inserted rows in both Staging and Target tables. But, none of the JSON fields that the Transform and Field Maps cover were set in either Staging or Target table.

 

Does anyone have ideas what I'm doing wrong?  The Transform Map seems correct, but somehow all of the input JSON to insertMultiple POST is getting lost.  Reverse engineering how this whole process works will take a while longer.  I'd appreciate if anybody has useful hints regarding requirements for Staging and Target tables, as well as sys_transform_map and sys_transform_entry (Transform and Field Map) rows.

 

 

 

0 REPLIES 0