COQL for SUM and COUNT

COQL for SUM and COUNT

I just can't get the syntax correct on this and could do with some help. I've looked through all the posts and dcumentation I can find, however a lot of it is contradictory.

I am wanting to essentially duplicate this Analytics agregate formula in a CRM function:
  1. count_if(("Opportunities"."Stage" = 'Committed, not Signed') OR ("Opportunities"."Stage" = 'In Quotation (Awaiting Proposal)') OR ("Opportunities"."Stage" = 'In Quotation (Awaiting Response)') OR ("Opportunities"."Stage" = 'In Quotation (Clarify Requirements)'))

I have set up a connection in the CRM for OAuth in Developer Space > Connections


This function works as I would expect :
  1. payload = {"select_query":"SELECT Total_Amount FROM Deals WHERE ((Stage = 'Committed, not Signed') or (Stage = 'In Quotation (Awaiting Proposal)')) or ((Stage = 'In Quotation (Awaiting Response)') or (Stage = 'In Quotation (Clarify Requirements)'))"};
  2. response = invokeurl
  3. [
  4.     url :"https://www.zohoapis.eu/crm/v2/coql"
  5.     type :POST
  6.     parameters:payload.toString()
  7.     connection:"zohocrmcoql"
  8. ];
  9. info response;
  10. return response;
However I can't seem to count the records no matter how I format. I'm also looking to sum a field called Total_Amount as well...

Even trying a simpler query doesn't seem to work :
  1. payload = {"select_query":"select SUM(Total_Amount), Stage from Deals where Stage = 'Committed, not Signed' group by Stage"};
  2. response = invokeurl
  3. [
  4.     url :"https://www.zohoapis.eu/crm/v2/coql"
  5.     type :POST
  6.     parameters:payload.toString()
  7.     connection:"zohocrmcoql"
  8. ];
  9. info response;
  10. return response;
Gives me this
Function executed successfully
{"code":"INVALID_QUERY","details":{"clause":"group by","column_name":"SUM(Total_Amount)"},"message":"select column should be given in group by clause","status":"error"}