Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Customize response for Import Set API?

valerybondarchi
Kilo Contributor

Hello all,

I wanted to add an array of errors to the response of import set API by using response object (like response.errors = [])

It works fine for strings, but if I try to add an array, it returns:

{

  "import_set": "ISET0031955",

  "staging_table": "imp_create_request",

  "result": [

      {

          "transform_map": "Imp Create Request",

          "table": "u_catalog_request_via_api",

          "status": "error",

          "error_message": "'u_requested_for'='valery.bondarchik1@wolterskluwer.com': User record not found; Target record not found",

        "errors": "org.mozilla.javascript.NativeArray@12432d1"

      }

  ]

}

Am I out of luck?

1 ACCEPTED SOLUTION

As long as it's a properly formatted JSON String they should be able to parse it.   The ImportSetAPI is returning a string for errors, and I don't believe you can modify it.



On their end they'll just do the equivalent of...



var errorObj = new JSON().decode(response.errors);


View solution in original post

6 REPLIES 6

Alikutty A
Tera Sage

Hi,



Can't you send the response as a JSON Array?



response.errors = {"root": {"A": "Value"},{"B": "Value"},{"C": "Value"} };



Thanks


Please Hit like, Helpful or Correct depending on the impact of the response


Hello Alikutty,



Unfortunately, this way I get:


{


  "import_set": "ISET0031955",


  "staging_table": "imp_create_request",


  "result": [


      {


          "transform_map": "Imp Create Request",


          "table": "u_catalog_request_via_api",


          "status": "error",


          "error_message": " User record not found; Target record not found",


          "errors": "[object Object]"


      }


  ]


}


Hi Valery,



Please convert the object to a string, I believe the same should work for your array.



Thanks


Please Hit like, Helpful or Correct depending on the impact of the response


Hello,



If object is converted to a string it will be represented as string. It will complicate things for integration partner and won't look pretty.



Best regards,


Valery