How to get array of objects in REST API response for Script API?

I'm using Script API function to get an array of data, but I'm getting an error in status code (520).

https://community.telligent.com/community/12/w/api-documentation/68677/core_5f00_v2_5f00_http-script-api#Get

Code sample:

var headers = { 'Content-Type': 'application/json', 'Accept': 'application/json' };
var url = 'http://universities.hipolabs.com/search?country=United+States';
var response = core_v2_http.Get(url, { Headers: headers });
return response;

Result in sandbox:

Apparently this function can only handle an object.

Is there an alternative way?

Verint version: 12.0.3

Parents
  • When you run that, the Headers array is empty.

    You are passing in a json array as header, however i believe that needs  to be a IDictornay or QueryString.

    Also, when you call this URL; it generates the following error: 

    System.InvalidCastException: Unable to cast object of type 'System.Collections.Generic.List`1[System.Object]' to type 'System.Dynamic.ExpandoObject'.
       at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonConverter[] converters)
       at Telligent.Evolution.Extensibility.Api.Version1.Http.<MakeRequest>d__17.MoveNext()


    The issue could also be the data its returning is difficulty for .NET to parse.

  • Hi  , 

    I'm not sure if this exception is related to the request headers or the complexity of the response content

    To simplify, two cases can be considered, where headers are not explicitly set:

    1. The response contains a simple object

    var url = 'https://gorest.co.in/public/v2/users/19';
    var response = core_v2_http.Get(url, { });
    return response;

    2. The response contains an array with simple objects

    var url = 'https://gorest.co.in/public/v2/users';
    var response = core_v2_http.Get(url, { });
    return response;

    As a result, the first code fragment will return the response data, the second will throw an exception.

    Based on the exception message, I believe that the function is trying to cast the list (System.Collections.Generic.List) to an object (System.Dynamic.ExpandoObject), which is what causes the error during creation of HttpResponse (HttpResponse Script API Type)

    As a result, no response headers are set

  • Interesting results on your two cases. I would assume its Verint's ability to parse JSON. I wonder if you can force Verint to not parse, and parse after the http call has been set to response.

Reply Children
No Data