cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Using object datatypes

enable_services
Deputy Chef I
Deputy Chef I

Hello,

I am trying to perform a HTTP request with a JSON payload containing a subset of data but I cannot work out how to get this to work. In my scenario and example data structure to build would be as shown below with the "email" data being what I am trying to build.

{
    "first_name": "John",
    "last_name": "Hancock",
    "email": [
        {
            "email_address": "test@test.co.uk",
            "primary_address": true,
        },
        {
            "email_address": "test2@test.co.uk",
            "primary_address": false,
        },
    ]
}

 I have a recipe that is given an email address string so in this example it would be "test@test.co.uk; test2@test.com" which splits by the semicolon. It then needs to build the array data to return to the primary recipe that calls this and that is where I have been having issues. I tried using a list variable which I added to in a loop but it doesn't allow me to select the data, it looks like it assumes I will be wanting to select each row of data.

I realise I probably haven't explained that brilliantly but if anybody can help that would be appreciated.

Many thanks,

Liam

1 ACCEPTED SOLUTION

Oh, i would recomment in the http connector -> body field to be type normal text which would allow you to actually use formula mode and in that formula mode you can directly put the array value 

View solution in original post

9 REPLIES 9

I managed to work out how to get the function recipe to return an actual correct array of object data, you have to manually edit the JSON schema to set the "properties" as sub fields which it doesn't support in the UI seemingly. Annoyingly it still won't let me use the returned response in my main recipe for the connector mapping as an array type field, though I know it has returned correctly as I can do a repeat loop on it.

Glad that you were able to work out. 

Annoyingly it still won't let me use the returned response

For correct mappings the schema need to be set. Have you set the output response schema for the function being called ? 

Yes I set the function return step to return an array type field with sub field properties of strings and boolean fields. When I run the primary recipe that calls it I can see I get a response and that response is an array with a row of object data as you would expect. If I try to use a repeat action it allows me to select that returned response to loop over however it won't let me select it in the connector HTTP request mapping where I have defined a request body field of type array. So either I am doing something wrong here or the SugarCRM Connector that I have been using doesn't support it for some reason.

Oh, i would recomment in the http connector -> body field to be type normal text which would allow you to actually use formula mode and in that formula mode you can directly put the array value 

Right OK that works though it is rather counter-intuitive to be able to define an return an array but to use it in an HTTP connector to have to put it into a string type field specifically in the formula section. For anybody that comes across this forum please be aware this will quote any boolean properties of the array as strings for example instead of 

 

[{"email_address": "myaddress@gmail.com", "primary_address": true}]

 

 you would get 

 

[{"email_address": "myaddress@gmail.com", "primary_address": "true"}]

So if you have any code that checks for those boolean types you will need to cater for this, in my instance I changed them to integer properties and sent across 0 and 1 as an equivalent value for when it goes into the SQL database the application is connected to.