Avaya Support Forums

Avaya Support Forums (http://support.avaya.com/forums/index.php)
-   Avaya Breeze™ Collaboratory (http://support.avaya.com/forums/forumdisplay.php?f=77)
-   -   REST JSON return to Variables (http://support.avaya.com/forums/showthread.php?t=11746)

wilso448 07-04-2016 04:29 PM

REST JSON return to Variables
 
I am working with a weather web service api and want to turn the JSON return into variables to use in my flow. I am working with Andrew on this. Here is my return:

{'responseCode':200,'responsePayload':'{\'coord\': {\'lon\':-81.76,\'lat\':27.98},\'weather\':[{\'id\':801,\'main\':\'Clouds\',\'description\':\' few clouds\',\'icon\':\'02d\'}],\'base\':\'stations\',\'main\':{\'temp\':305.59,\ 'pressure\':1020,\'humidity\':70,\'temp_min\':303. 15,\'temp_max\':308.15},\'visibility\':16093,\'win d\':{\'speed\':3.6,\'deg\':210},\'clouds\':{\'all\ ':20},\'dt\':1467670298,\'sys\':{\'type\':1,\'id\' :639,\'message\':0.0457,\'country\':\'US\',\'sunri se\':1467628564,\'sunset\':1467678436},\'id\':4153 884,\'name\':\'Eagle Lake\',\'cod\':200}','responsePayloadType':'applic ation/json; charset=utf-8'}

How do i turn this into multiple variables or a variable with sub variables for use in my flow.

Tom
Arrow SI

wilso448 07-04-2016 04:36 PM

here is the response without all the added overhead.

{"coord":{"lon":-81.76,"lat":27.98},"weather":[{"id":801,"main":"Clouds","description":"few clouds","icon":"02d"}],"base":"stations","main":{"temp":305.49,"pressure ":1020,"humidity":70,"temp_min":303.15,"temp_max": 308.15},"visibility":16093,"wind":{"speed":3.6,"de g":210},"clouds":{"all":20},"dt":1467671719,"sys": {"type":1,"id":639,"message":0.0505,"country":"US" ,"sunrise":1467628564,"sunset":1467678436},"id":41 53884,"name":"Eagle Lake","cod":200}

ander548 07-05-2016 07:19 AM

Have you tried using the JSON Schema editor in the EDP Administrator Console / Event Catalog? It seems you can build complex JSON like this for your custom events but I'm curious as well whether it will work. The problem I'm having that you may have as well is that it appears the incoming response needs to have a very rigid formatting with your events family, type, version and eventBody form variables where "eventBody" contains the payload. Even if you figure out how to consume the more complicated JSON payload, I think this is going to be a big problem when trying to use 3rd party web services like yours that can't alter their response to match this rigid format. I've asked a question about this on my thread (https://support.avaya.com/forums/showthread.php?t=11740) and suggested it would be more flexible if the callback URL had an ID at the end to identify the event and direct it to the correct workflow so that the incoming response doesn't require special formatting. Good luck!

wilso448 07-06-2016 09:52 AM

I haven't tried that but will look at that. My problem is mapping the response to variables.

vishals 07-06-2016 11:23 AM

There is an option to build the variable to match the return schema. In Output Mapping of the "REST Service Task", you can click on the green "+" symbol to create the same schema.

wilso448 07-06-2016 11:32 AM

the schema is in the payload string, that only allows you to duplicate the output schema. I need to take the return that is in the payload and turn it into variables.

wilso448 07-06-2016 11:51 AM

I found a generator that will return my schema from the output. But it seems like Breeze doesn't recognize Interger as a json type.

Here is the schema:

{"$schema":"http://json-schema.org/draft-04/schema#","type":"object","properties":{"coord":{"t ype":"object","properties":{"lon":{"type":"number" },"lat":{"type":"number"}}},"weather":{"type":"arr ay","items":{}},"base":{"type":"string"},"main":{" type":"object","properties":{"temp":{"type":"numbe r"},"pressure":{"type":"integer"},"humidity":{"typ e":"integer"},"temp_min":{"type":"number"},"temp_m ax":{"type":"number"}}},"wind":{"type":"object","p roperties":{"speed":{"type":"number"},"deg":{"type ":"integer"}}},"clouds":{"type":"object","properti es":{"all":{"type":"integer"}}},"dt":{"type":"inte ger"},"sys":{"type":"object","properties":{"type": {"type":"integer"},"id":{"type":"integer"},"messag e":{"type":"number"},"country":{"type":"string"}," sunrise":{"type":"integer"},"sunset":{"type":"inte ger"}}},"id":{"type":"integer"},"name":{"type":"st ring"},"cod":{"type":"integer"}}}

here are the errors i am getting from breeze.

Output Schema: Integer is not a valid JSON data type at 'id'.
Output Schema: Integer is not a valid JSON data type at 'dt'.
Output Schema: Integer is not a valid JSON data type at 'cod'.
Output Schema: Integer is not a valid JSON data type at 'all'.
Output Schema: Integer is not a valid JSON data type at 'deg'.
Output Schema: Integer is not a valid JSON data type at 'id'.
Output Schema: Integer is not a valid JSON data type at 'sunset'.
Output Schema: Integer is not a valid JSON data type at 'sunrise'.
Output Schema: Integer is not a valid JSON data type at 'type'.
Output Schema: Integer is not a valid JSON data type at 'id'.
Output Schema: Integer is not a valid JSON data type at 'humidity'.
Output Schema: Integer is not a valid JSON data type at 'pressure'.

wilso448 07-06-2016 12:39 PM

Solution as of right now.
 
If I replace Integer with String, everything works. I believe we are good for now.

joele 07-20-2016 04:15 PM

If you do run into problems like this in the future, you might look into creating a Dynamic Task Type to invoke your web service. A DTT would be able to take a response in any format whatsoever and then turn it into a form that Engagement Designer would be able to handle.

Andrew, I wanted to address your comment too. The Eventing Framework structure that you mentioned doesn't apply to responses to web service invocations. It only applies to asynchronous events that are being published. I commented on the thread that you referenced: https://support.avaya.com/forums/showthread.php?t=11740.

Please let me know if you have questions on any of this.

Joel


All times are GMT -7. The time now is 08:41 PM.