Question

Web Service Parameters in Response Property Names

Hello,

I have a web service that I would like to use for geocoding addresses. The issue is that this web service uses one of the query values for a property in the response body. If I pass a zip code to this API to get geocoding values for that zip code, it uses that zip code as the property name in the response body.

For example: My request is for api/geocode?zip=55114

The response is:

 

{
    "results": [
        "55114": {
            "lat": "lat_here",
            "lon": "lon_here"
        }
    ]
}

 

The issue is that I'm not sure I can use the web services area in Creatio to handle this since it doesn't appear I can use a dynamic value or parameter for the response property names - in this case, the objects in the array of results has a property name that is based on the zip code parameter. Is there anyway to set up dynamic property names or use a query parameter value for a property name in the response body properties? Basically, is there anyway for this property to be dynamic in any way?

 

I realize I'll probably just have to switch to writing code to call the API, but I'd prefer to set it up as a web service if that is possible.

Thanks

Like 0

Like

4 comments

JSON is slightly broken

it should probably be like this

{
  "results": [
        {
            "55114": 
            {
                "lat": "lat_here",
                "lon": "lon_here"
            }
        }
    ]
}

and then $.results[0].*.lat and $.results[0].*.lon, this is assuming that the results array returns only one element

Kirill Krylov CPA,

 

Hi Kirill. I did type in the json incorrectly, however, I wasn't aware I could set it up using the index like you showed. Thanks for that! 

 

The actual json returned (copy/pasting this time to make sure it's correct) is like this:

 

{
   "results":{
      "85379":[
         {
            "postal_code":"85379",
            "country_code":"US",
            "latitude":"33.60210000",
            "longitude":"-112.37360000"
         }
      ]
   }
}

 

So that leaves me with the original issue since I can't use $.results.85379[0] since it's the 85379 property (the zip code) which would change based on the zip code requested. If I could do this $.results[{zip}][0] and reference a query parameter that would be great, but it's looking like I can't set it up that way and coding it will be the way to go.

Thanks again,

Ryan

if your response returns only one item in the array, then you can address it with the following expression $.results.[0].latitude. I use this https://jsonpath.com/ to build expressions. Your other options would be either getting the string response and parsing it in BP or building a custom process element (hint: there is a webinar for that on Sep 28)

Kirill Krylov CPA,

 

Thanks Kirill, looks like that will work. I wasn't thinking that I could reference the property (the zip code property) by index. In fact, I hadn't put together that I could use jsonpath expressions there (but makes sense since they're supported in json.net which I assume this is using). Guess I'll have to try playing around with some of those expressions that will be very useful. I'll look forward to your webinar. 

Thanks again!

Show all comments