Genesys CTI User Forum

Genesys CTI User Forum => Genesys CTI Technical Discussion => Topic started by: anoredis on October 04, 2013, 07:07:22 AM

Title: RESTfull webservice data retrieved
Post by: anoredis on October 04, 2013, 07:07:22 AM
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? 
Title: Re: RESTfull webservice data retrieved
Post by: René on October 04, 2013, 08:15:54 AM
Hi,

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

R.
Title: Re: RESTfull webservice data retrieved
Post by: anoredis on October 04, 2013, 08:31:54 AM
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]
Title: Re: RESTfull webservice data retrieved
Post by: René on October 04, 2013, 08:40:58 AM
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.

Title: Re: RESTfull webservice data retrieved
Post by: anoredis on October 04, 2013, 08:45:16 AM
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
Title: Re: RESTfull webservice data retrieved
Post by: René on October 04, 2013, 08:56:51 AM
Do you see in MPC log that web request output has been assigned to the dataRetrieved variable?

R.
Title: Re: RESTfull webservice data retrieved
Post by: anoredis on October 04, 2013, 09:00:13 AM
Yes, MCP logs states that
[code]AssignRuntime.cxx:48 Execute(): Script [AppState.dataRetrieved;AppState.dataRetrieved=WebRequest1Response;][/code]
Title: Re: RESTfull webservice data retrieved
Post by: anoredis on October 04, 2013, 12:07:43 PM
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]
Title: Re: RESTfull webservice data retrieved
Post by: anoredis on October 10, 2013, 10:48:25 AM
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.
Title: Re: RESTfull webservice data retrieved
Post by: cavagnaro on October 10, 2013, 11:16:58 PM
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.
Title: Re: RESTfull webservice data retrieved
Post by: anoredis on October 11, 2013, 07:11:23 AM
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]
Title: Re: RESTfull webservice data retrieved
Post by: René on October 11, 2013, 09:19:13 AM
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.
Title: Re: RESTfull webservice data retrieved
Post by: anoredis on October 11, 2013, 10:10:35 AM
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...
Title: Re: RESTfull webservice data retrieved
Post by: cavagnaro on October 11, 2013, 04:05:42 PM
No content...mean the WS? If so I'd see the JSon object properties and maybe length.
Title: Re: RESTfull webservice data retrieved
Post by: anoredis on October 18, 2013, 01:10:17 PM
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.
Title: Re: RESTfull webservice data retrieved
Post by: René on October 22, 2013, 06:30:45 PM
Hi,

Are you trying to read HTTP headers and return selected ones as part of output JSON object?

R.
Title: Re: RESTfull webservice data retrieved
Post by: anoredis on October 23, 2013, 07:07:30 AM
Yes Rene, I only need the status code of the response header because I need to branch the outcome. If it is 200, it follows the default path but in case of 204, 300, 4xx and 5xx different ones.
Title: RESTfull webservice -webrequest common block issue
Post by: welcdp on December 27, 2016, 05:31:46 AM
I'm getting a missing required parmeter for POST rest service call using web request common block.
created a JSON object that is passed as JSON content. Can you please provide me an example of how to call a rest post service using web request commin block?