Genesys Engage on-premises

 View Only
Discussion Thread View

GIA - error parsing JSON body in API call

  • 1.  GIA - error parsing JSON body in API call

    Posted 06-28-2021 21:52
    Edited by Oscar Alvarez 06-29-2021 01:16

    Hi, I am having issues sending an API call with parameters in JSON format.

    This is the response from the API (this implies the JSON format is incorrect, but I have validated it separately):

    {"errorMessage":"Unexpected token p in JSON at position 0","errorCode":5000}

    Is anyone familiar with this issue? Should I be using a different method to make this API call, or to parse the JSON?


    This is my test code:

    sURL_p = "https://abc.com"
    sMethod_p = "POST"
    headers_p = ["Content-Type:application/json","Authorization: Bearer abc123"]
    parameters_p = ["v":"2.0"]
    body_JSON = "{}"
    body_JSON = context.parseJSON(body_JSON)
    body_JSON.put("phoneNumber","+610123456")
    body_JSON.put("callId","H1234")
    body_JSON.put("skill","general")
    iTimeoutMillis_p = 5000
    
    sResponse = context.http(sURL_p,
    sMethod_p,
    headers_p,
    body_JSON,
    iTimeoutMillis_p).getResponseJson()

    These are the variables shown in iHub:

    Current Variables:        body_JSON = (JSONObject object): {"phoneNumber":"+610123456","callId":"H1234","skill":"general"}
        headers_p = [ 'Content-Type:application/json', 'Authorization: Bearer abc123' ]
        iTimeoutMillis_p = 5000
        parameters_p = (LinkedHashMap object): {v=2.0}
        sMethod_p = 'POST'
        sResponse = (JSONObject object): {"errorMessage":"Unexpected token p in JSON at position 0","errorCode":5000}
        sURL_p = 'https://abc.com'


    #Integrations

    Edit - I have run a Wireshark trace and found the content is being sent as "Line-based text data: application/json (1 lines)" instead of "JavaScript Object Notation: application/json"

    Wireshark extract

    The JSON formatting is being lost, hence the error. I believe a different method is required to parse the info, but I have gone over all the documentation and cannot find any other method.

    ------------------------------
    Oscar Alvarez
    Link Group
    ------------------------------



Need Help finding something?

Check out the Genesys Knowledge Network - your all-in-one access point for Genesys resources