Array in Import Mapping

0
Hi! I have a REST call with a response like this: {“status”:{“Project”: Reported”, "Samples”:"Created”}, results:{"id”: "12345”, "state”:"Reported”}} It is also possible that there are more than one results. In that case the response is like this: {“status”:{“Project”: Reported”, "Samples”:"Created”}, results:[{"id”: "12345”, "state”:"Reported”}, {"id”: "54321”, "state”:"Reported”}]} My problem is: If I make an import mapping based on the first JSON, I have no results if I have a response like the second JSON. If I make my import mapping based on the second JSON, I have no result for the first JSON. How can I make a correct import mapping for this situations? Is it possible to have one import mapping for this two scenarios?
asked
2 answers
1

Well not sure if there is a better way to do it. But in the past i have solved this by creating both import mappings. Then i call the rest service without the import mapping but the response in a string. In the string you could check for the ‘results:[‘ and depending on if this is in the string or not use the correct import mapping.

answered
1

I think you need to create two import mappings and check the JSON string first to see which one you have to use for your import.

Seems to me the publishing service swagger needs to be consistent in returning a single object or 1-* object(s) in an array :)

edit: Maarten was ahead of me there

answered