API post return a list, doesn't work with create record when binding data var

Hello, i have an POST API that takes 2 param “start date” and “end date” and returns a list of objects, i added the API in DATA section and generated the schema, everything seemed fine !



but when i create a DATA VARIABLE and tries to bind it with the POST API result schema, it doesn’t let me chose the DATA VAR because it’s not a list u can repeat on



Hey,

As your data variable is a New data record type variable, it is only an empty object and not a list. For repeat with you’ll need a Collection of data records, but since you are able to access you data only with a Create Record (instead of Get Collection) then here’s what I suggest you do:

  • Enable Get Collection in GetAllSeancesStudent data resource

  • Manually set the response schema as identical to the Create Record schema so the data var gets the correct schema in the next step

  • Create a new Collection of data records type data variable for GetAllSeancesStudent

  • On the data variable page, open the logic canvas and replace the Get Collection flow function with a HTTP Request flow function

  • Configure the HTTP Request to POST, with the header, payload data, etc

  • Make sure to change the Set data variable flow function’s Record collection property to the output of HTTP Request

Then you should be able to use the data variable in the repeat!

Hey, thanks for your response ! i wonder, if i was gonna the variables manually, wouldn’t it be better to create a page variable instead and map the values ? otherwise, is there anyway to not do it manually ? because i have almost 50+ property and it would take a lot of time to do that every time for each POST request with a return list. is this a BUG or is it just designed like that ?

You wouldn’t have to do it more than once if you manually set the schema to the Get Collection response schema in the Data Resource configurator, then all of the collection type data variables for that resource would have the same schema. But yes, I understand that with that many properties it would be a hassle even once :confused: I’m not sure what you mean by map the values, wouldn’t you have to set the schema for the page var too? This is not a bug per say, the data resource configurator has been built with some assumptions that do not apply to every case (such as this one) for more ease of use, it could definitely be more flexible.

One way to avoid manually setting the properties would to just create a variable that is a list of objects without specifying the object properties. Only downside is that the binding options will not recognize the schema of the list items, but you would be able to use a formula to set e.g. item.centreName to a text component or something like that and it should work.

Hey again Cecilia, i hope you doing well !
Regarding our last conversation, i did follow the instructions ( your first comment ).
i did create manually the variables in the GET COLLECTION section of the API.
the HTTP request is working fine and getting the data as intended ,
unfortunately i wasn’t able to to bind the result of the HTTP request to the data variable
should i use formula or output of another node value as a binding type?


what do you think?
Best regards, thanks

1 Like

Hey,

Yes a formula should be used, sorry forgot to mention that! It’s something like outputs["HTTP Request"].responseBody or something similar to that. The formula editor might complain that same “data is not compatible” but you should be able to ignore that.

Hey thanks it did WORK, thank you so much for your help and time.

1 Like

Just to add to the solution: the data collection might come with a ‘response key path’, which requires to modify the collection with MAP().

For instance, when using Firestore:
MAP(outputs["HTTP request"].resBodyParsed, item.document)