Populating a data object with multiple entries returned through an API call

Hi All

I’m new to Liberty Create, so please bear with me.

I’m trying to populate a list of addresses, returned from the the Ordnance Survey which match a specific postcode.

I have created a data object for the API call, one to store the search criteria, and a separate one for the list of addresses, an API connection, an API call and a rule.

When the rule fires the API call, it populates the list of addresses object, but only with one record (the first record returned), where as I need all addresses adding. I’ve checked the API Response Payload in the API call Object, and all addresses matching the postcode are returned.

How do I get all the addresses into the object and not one?

TIA

Stephen

Hi Stephen,

I was just about to respond to your earlier forum post.

If you are getting only a singular response it is likely because you are not using a template or using it incorrectly. Make sure there is a to-many relationship between the base object of your API request and the template containing the placeholder for your responses.

HI Adam

Thanks for the response.

Yes, there is a to-many relationship between my API request Data Object and the Object I plan to store the list of addresses in.

Yes, I’m using a template, although I’ve no idea if I’ve set it up correctly. In summary, I ran the API call in SoapUI, copied/pasted the results into a template adjusted it to add the placeholders as you suggest.

My current API Call config is as below. I don’t think it’s correct for my needs (it’s pretty much as per the “Introduction to API’s” training video). I’ve tried experimenting with the “Request Selection” and “Action” fields, but haven’t been able to get it to work as required.

Any further advice much appreciated.

Thanks

1 Like

For any future forum readers having similar difficulties:

Within your payload response, you will always have a static, non-repeating set of elements at the top of the response, even if that is just a simple container.

Most APIs will respond with some metadata regarding your query, if not a repeat of your query, a unique reference, and often a timestamp and/or status message.

JSON is made up of objects {} and arrays [].

Arrays [] (lists) contain repeating objects {} (records).

Consider this typical API response for an employee lookup:

   {
        "employeeID": "619435",
        "firstName": "Rack",
        "lastName": "Jackon",
        "gender": "man",
        "age": 24,
        "address": {
            "streetAddress": "126",
            "city": "San Jone",
            "state": "CA",
            "postalCode": "394221"
        },
        "phoneNumbers": [
            { "type": "home", "number": "7383627627" },
            { "type": "work", "number": "7384428928" }
        ]
    }

If we want to capture this response in Create, we need to break this response down into static and repeating elements.

Our top-level, static object goes into our response as raw JSON. We are copying everything including the square brackets for the array “[” but excluding the contents. The contents, a single object or record within the array will form a template of the data we wish to capture inside of the array.

Our response will look like this:

   {
        "employeeID": "619435",
        "firstName": "Rack",
        "lastName": "Jackon",
        "gender": "man",
        "age": 24,
        "address": {
            "streetAddress": "126",
            "city": "San Jone",
            "state": "CA",
            "postalCode": "394221"
        },
        "phoneNumbers": [<PHONE NUMBER TEMPLATE HERE>]
    }

Next, we will take steps towards creating a template to capture the Phone Numbers inside the “phoneNumbers” array [].

Before we can create the template we need a receiving object that is related to our base object in a to-many relationship. e.g. Contact one-to-many Phone Numbers.

This must be in place before we can create our template as the template is created in the context of the relationship path.

Once you are ready to add your template, place your cursor between the array brackets in your response, “[I]”

Then select your relationship path from the relationship selector in the right-hand sidebar and click the + button to add a template.

image

image

Your template must only contain a single representation of a complete object in your array.

{ “type”: “home”, “number”: “7383627627” }

If some objects within the array contain additional keys, you may add them to the template to create an idealised version of an object’s response, showing all the keys that may possibly be returned so that you can link them out to properties in your object.

I hope this helps.

1 Like