" /> RESTfull webservice data retrieved - Genesys CTI User Forum

Author Topic: RESTfull webservice data retrieved  (Read 14194 times)

anoredis

  • Guest
RESTfull webservice data retrieved
« on: October 04, 2013, 07:07:22 AM »
Advertisement
Hello, this is my first attempt to create an application that utilizes Web Services. Does anybody know how to access the data retrieved from a web Request Block? I have the Web Request block in which I have assigned the URI, the method to POST, the authentication method to basic with my credentials filled in, the encoding type to urlencoding and the output variable to dataRetrieved.
When I try to log AppState.dataRetrieved it logs [object Object]
How can I check what comes back? 

Offline René

  • Administrator
  • Hero Member
  • *****
  • Posts: 1832
  • Karma: 62
Re: RESTfull webservice data retrieved
« Reply #1 on: October 04, 2013, 08:15:54 AM »
  • Best Answer
  • Hi,

    Could you post here snippet of URS HTTP log to see what is coming back from your web service?

    R.

    anoredis

    • Guest
    Re: RESTfull webservice data retrieved
    « Reply #2 on: October 04, 2013, 08:31:54 AM »
  • Best Answer
  • Hello Rene, thank you for your immediate response. I don't think it has something to do with the URS. I just do not know how to access the data returned. My web request is done correctly because i can see in the MPC logs that I get back [code] var WebRequest1Response = {"result":"jY8UteuGBjTbANyJFE5Y+99cFcbNNMkYwCWRAnmHul+hLtkR26xGJo+J30jimY6nfakIEM66ixk="};] [/code]

    How do I access that? I am trying to access it like AppState.dataRetrieved.result but it gives me a scemantic error. In the mcp logs I see that [code] exec_error TypeError: AppState.dataRetrieved has no properties [/code]

    Offline René

    • Administrator
    • Hero Member
    • *****
    • Posts: 1832
    • Karma: 62
    Re: RESTfull webservice data retrieved
    « Reply #3 on: October 04, 2013, 08:40:58 AM »
  • Best Answer
  • Hi,

    Sorry, I thought you're talking about calling web service from URS... Do I understand you correctly that dataRetrieved variable is configured as output parameter of the Web Request block?

    R.


    anoredis

    • Guest
    Re: RESTfull webservice data retrieved
    « Reply #4 on: October 04, 2013, 08:45:16 AM »
  • Best Answer
  • Exactly Rene! You can find my complete configuration for my Web Request Block in my first post.
    My problem is that I get the correct response from the service but I do not know how to access the data retrieved

    Offline René

    • Administrator
    • Hero Member
    • *****
    • Posts: 1832
    • Karma: 62
    Re: RESTfull webservice data retrieved
    « Reply #5 on: October 04, 2013, 08:56:51 AM »
  • Best Answer
  • Do you see in MPC log that web request output has been assigned to the dataRetrieved variable?

    R.

    anoredis

    • Guest
    Re: RESTfull webservice data retrieved
    « Reply #6 on: October 04, 2013, 09:00:13 AM »
  • Best Answer
  • Yes, MCP logs states that
    [code]AssignRuntime.cxx:48 Execute(): Script [AppState.dataRetrieved;AppState.dataRetrieved=WebRequest1Response;][/code]

    anoredis

    • Guest
    Re: RESTfull webservice data retrieved
    « Reply #7 on: October 04, 2013, 12:07:43 PM »
  • Best Answer
  • Ok, got it!

    From MCP logs I saw that
    [code]Runtime.cxx:424 EvaluateExpression(): Expression [var webReqResponse = {"result":"jY85k="};]}[/code]

    which is a json object. So I got the value by
    [code]AppState.dataRetrieved.result[/code]

    anoredis

    • Guest
    Re: RESTfull webservice data retrieved
    « Reply #8 on: October 10, 2013, 10:48:25 AM »
  • Best Answer
  • Can anyone please tell me how can I check for the response? I want to access the response headers and check if it is a 200 OK to proceed or anything else to provide different scenarios.

    Offline cavagnaro

    • Administrator
    • Hero Member
    • *****
    • Posts: 7641
    • Karma: 56330
    Re: RESTfull webservice data retrieved
    « Reply #9 on: October 10, 2013, 11:16:58 PM »
  • Best Answer
  • Enable the logs on your app so it will save them on MCP tmp folder.
    I think the name is com.genesyslab.savetempfiles or like that. It is on the GVP help file under Logs section.
    You can set it as ALL, PAGES, etc. Set it as PAGES so it will save requests and responses from MCP to the HTTP servers. Also helpful to see WS responses for example.

    anoredis

    • Guest
    Re: RESTfull webservice data retrieved
    « Reply #10 on: October 11, 2013, 07:11:23 AM »
  • Best Answer
  • Thank you cavagnaro for the quick response!  :)
    I am really new to CTI and composer so I am not sure I understand you. I see in my MCP logs that
    [code]2013-10-11 09:56:03.233 DBUG 00D10125-100268AC-003574D5 2436 01F00000 FMThreadQueue.cxx:661 Request successful: uri=http://10.x.x.xxx/IVR_sales/include/getWebRequestData.aspx
    2013-10-11 09:56:03.233 DBUG 00D10125-100268AC-003574D5 2436 01F00000 FMThreadQueue.cxx:777 HTTP request completed
    2013-10-11 09:56:03.233 DBUG 00000000-00000000 2436 01F00000 FMResponseData.cxx:421 Received fetch completed, response code=200
    2013-10-11 09:56:03.233 DBUG 00D10125-100268AC-003574D5 2436 01F00000 FMThreadQueue.cxx:1438 Response is not cacheable
    2013-10-11 09:56:03.233 DBUG 00D10125-100268AC-003574D5 2436 01F00000 FMUserRequest.cxx:497 Request completed, sending RequestCompleteNotify.
    2013-10-11 09:56:03.233 DBUG 00000000-00000000 2436 08500000 VXMLDocumentManager.cxx:163 Fetched Length: 283, type: data
    2013-10-11 09:56:03.233 DBUG 00000000-00000000 2436 08500500 VGDocumentManager.cxx:1090 Document has modified/newly fetched, uri: http://10.x.x.xxx/IVR_sales/include/getWebRequestData.aspx?AuthenAccess=false&CustomHeaders=%5Bobject%5D&Enctype=application%2Fx-www-form-urlencoded&Protocol=get&Timeout=-1&WebUrl=http%3A%2F%2Ftestsrvtest.testdom.com%2Fec2%2Fapi%2Frest%2Ftest%2Fods%2Frecs%2Fsum%2F7034063%2F0000430328
    2013-10-11 09:56:03.233 DBUG 00D10125-100268AC 3928 0C000000 VXMLSession.cxx:1889 ProcessEvents() Started
    2013-10-11 09:56:03.233 DBUG 00D10125-100268AC 3928 0C000000 VXMLSession.cxx:1906 ProcessEvents() Event type [1], session id: [00D10125-100268AC]
    2013-10-11 09:56:03.233 DBUG 00D10125-100268AC 3928 0C000000 VXMLSession.cxx:1320 HandleFetchEvent(): Process state: 2, response code: 200, error: , uri: http://10.x.x.xxx/IVR_sales/include/getWebRequestData.aspx[/code]
    so I was hoping to get something from it because I see a lot of 200 OKs there.
    I was hoping that I would get the response on the object of the Request and check it in my program with something like [code]WebRequest2.StatusCode == '200' [/code] or with the use of .getAllResponseHeaders()
    Some lines below I see (I guess) the savetmpfiles that you mentioned(?)
    [code]2013-10-11 09:56:03.233 DBUG 00D10125-100268AC 3928 0C000000 Runtime.cxx:923 RuntimeHelper::GetStringProperty() Name [__.savetmpfiles], value [none]
    2013-10-11 09:56:03.233 DBUG 00D10125-100268AC 3928 0C000000 Runtime.cxx:923 RuntimeHelper::GetStringProperty() Name [__.savetmpfilesmode], value [immediate][/code]
    « Last Edit: October 11, 2013, 07:14:58 AM by anoredis »

    Offline René

    • Administrator
    • Hero Member
    • *****
    • Posts: 1832
    • Karma: 62
    Re: RESTfull webservice data retrieved
    « Reply #11 on: October 11, 2013, 09:19:13 AM »
  • Best Answer
  • Hi,

    I did quick test and returned JSON object contains key 'errorMsg' where you can find text description of thrown HTTP error e.g. Internal Server Error, Not found etc. It is possible to return more details about HTTP errors but that would require modification of getWebRequestData.jsp file (or getWebRequestData.aspx for .NET) provided by Composer.

    R.

    anoredis

    • Guest
    Re: RESTfull webservice data retrieved
    « Reply #12 on: October 11, 2013, 10:10:35 AM »
  • Best Answer
  • Thank you Rene! I was able to to a check in a Branching Block if(WebResult.errorMsg.indexOf('404')) which serves me well but I am not able to do the same for a 204 because it is not an Error...

    Offline cavagnaro

    • Administrator
    • Hero Member
    • *****
    • Posts: 7641
    • Karma: 56330
    Re: RESTfull webservice data retrieved
    « Reply #13 on: October 11, 2013, 04:05:42 PM »
  • Best Answer
  • No content...mean the WS? If so I'd see the JSon object properties and maybe length.

    anoredis

    • Guest
    Re: RESTfull webservice data retrieved
    « Reply #14 on: October 18, 2013, 01:10:17 PM »
  • Best Answer
  • I tried messing with the WebRequest.aspx but no lack. I have managed to return the key-value pair in my JSON object but with a fixed value like [code]"headers" : "returnedHeaders"[/code]
    I have tried webresponse.Headers but no luck. How should I get the values that I want into my variable? I  am really new to C#.
    I could post my WebRequest.aspx but it's really long. However, I think that it's a pretty standard page for all projects.
    « Last Edit: October 18, 2013, 01:15:43 PM by anoredis »