The CreatorCon Call for Content is officially open! Get started here.

Data Source using REST Integration Hub

Aviram Elkayam
Tera Contributor

Hi

I am trying to import data from an external API (Rest), I have created the Data Source Request action.

 

I have tested the Request Action within the flow designer and it is working well and I can see the Data I need on the the response_body of the API call 

 

AviramElkayam_0-1705358801285.png

 

now when I am trying to run the "Test Load 20 Records" I am getting an error.

 

here is the Data Source I have set:

 

AviramElkayam_1-1705358968465.png

 

and this is the error I am getting :

 

AviramElkayam_2-1705359079504.png

the JSON file looks like this when I use PostMan to test the API connection :

 

 

AviramElkayam_4-1705359173850.png

 

Do you have any idea why I am getting this error ?

 

javax.json.JsonException: Cannot auto-detect encoding, not enough chars

 

please advice

 

Thanks 

Aviram 

 

 

 

 

6 REPLIES 6

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Aviram Elkayam 

 

May be helpful

 

https://www.servicenow.com/community/developer-forum/how-to-import-special-characters-from-a-json-fi...

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Thanks, I don't think I have an issue with special characters

Hi @Aviram Elkayam , 

That is because your response in the rest step is a json. It should be the sys_id of the attachment which SN creates internally.  Re create your Action and ensure you don't use the import REST message option in the REST step, instead configure it manually and your response will be sys_id instead of the actual JSON. 

The data source is expecting the sys_id of the attachment in the response_body instead of the actual json itself. 

Regards

Shiva

Hi, 

 

thanks, I will test that.

 

Recently I have solved the issue using Custom(Load by Script), see the javascript I have created 

 

(function loadData(import_set_table, data_source, import_log, last_success_import_time) {
    //call Get SolarWinds Devices Action
    var result = sn_fd.FlowAPI.getRunner().action('global.get_solarwinds_devices_action').inForeground().run();
    var outputs = result.getOutputs();

    // Get Outputs:
   
        var response = outputs['response']; // JSON

    var obj = new global.JSON().decode(outputs['response']);

    for (var i=0; i<obj['results'].length ; i++){

    var importRecord = {};

    importRecord.caption = obj['results'][i]['Caption'];
    importRecord.u_ip_address = obj['results'][i]['IP_Address'];
    importRecord.machinetype = obj['results'][i]['MachineType'];
    importRecord.version = obj['results'][i]['Version'];
    importRecord.cpucount = obj['results'][i]['CPUCount'];
    importRecord.u_device_serial= obj['results'][i]['Device Serial'];
    importRecord.u_node_category = obj['results'][i]['Node Category'];

    import_set_table.insert(importRecord);
    }



})(import_set_table, data_source, import_log, last_success_import_time);