Help ! Custom Function : Searching Client Company

Help ! Custom Function : Searching Client Company

I'm trying to run a custom function in Zoho Flow that looks up a Client Company using the Client Name. I want it to return only the matching record or an error; at the moment it's defaulting to the first reponse (I think)

Can someone help tweak this function as I feel I'm very close :

  1. string ZP_getClientID(string varClientName)
  2. {
  3. payload = Map();
  4. payload.put("name",varClientName);
  5. response = invokeurl
  6. [
  7.     url :"https://projectsapi.zoho.eu/restapi/portal/XXXXXXXXX/clients/"
  8.     type :GET
  9.     parameters:payload
  10.     connection:"devteam_zoho_projects"
  11. ];
  12. //Change the response to a map to extract specific information
  13. responseMap = response.toMap();
  14. for each  varRecord in responseMap
  15. {
  16.     //Something here    
  17. }
  18. varFoundID = responseMap.get("clients").getJSON("id");
  19. return varRecord;
  20. }