Error in Deluge script, but all should be OK

Error in Deluge script, but all should be OK

I get an error when using the following deluge script (sensitive info changed with ***).

This script should parse a projectnumber out of the subject or body text and put it in a custom field of the ticket.

The error:
Validation failed for the condition : Syntax error. Expecting ']' or invokeurl parameter values. Found ','.. LineNumber : 10

The code:
  1. // Validate ticketId (numeric)
  2. if (ticketId == null) {
  3.     info "Error: ticketId is null"; 
  4.     return;
  5. }

  6. // Fetch ticket details
  7. try {
  8.     ticketDetails = invokeurl [
  9.         url: "https://***.nl/api/v1/tickets/" + ticketId,
  10.         type: GET,
  11.         connection: "myapi"
  12.     ];
  13. } catch (e) {
  14.     info "Fetch ticketDetails Error: " + e;
  15.     return;
  16. }

  17. // Fetch latest thread
  18. try {
  19.     threadDetails = invokeurl [
  20.         url: "https://***.nl/api/v1/tickets/" + ticketId + "/latestThread?include=plainText",
  21.         type: GET,
  22.         connection: "myapi"
  23.     ];
  24. } catch (e) {
  25.     info "Fetch threadDetails Error: " + e; 
  26.     return;
  27. }

  28. // Extract content and initialize
  29. ticketSubject = ticketDetails.get("subject"); 
  30. ticketBody = threadDetails.get("plainText"); 
  31. projectNumber = ""; 

  32. info "Subject/Body: " + ticketSubject + " | " + ticketBody;

  33. // Search in subject for B + 5 digits
  34. if (ticketSubject != null && ticketSubject != "" && ticketSubject.length() >= 6) {
  35.     len = ticketSubject.length();
  36.     maxStart = len - 6;
  37.     for idx = 0; idx <= maxStart; idx = idx + 1 {
  38.         candidate = ticketSubject.substring(idx, idx + 6);
  39.         if (candidate.substring(0,1).toUpperCase() == "B" && candidate.substring(1,6).matches("\\d{5}")) {
  40.             projectNumber = candidate;
  41.             break;
  42.         }
  43.     }
  44. }

  45. // If not found in subject, search in body
  46. if (projectNumber == "" && ticketBody != null && ticketBody != "" && ticketBody.length() >= 6) {
  47.     len = ticketBody.length();
  48.     maxStart = len - 6;
  49.     for idx = 0; idx <= maxStart; idx = idx + 1 {
  50.         candidate = ticketBody.substring(idx, idx + 6);
  51.         if (candidate.substring(0,1).toUpperCase() == "B" && candidate.substring(1,6).matches("\\d{5}")) {
  52.             projectNumber = candidate;
  53.             break;
  54.         }
  55.     }
  56. }

  57. info "projectNumber: " + projectNumber;

  58. // Update custom field if found
  59. if (projectNumber != "") {
  60.     customFieldsMap = Map(); 
  61.     customFieldsMap.put("cf_b_nummer", projectNumber);
  62.     updateData = Map(); 
  63.     updateData.put("customFields", customFieldsMap);

  64.     try {
  65.         invokeurl [
  66.             url: "https://***.nl/api/v1/tickets/" + ticketId,
  67.             type: PATCH,
  68.             headers: {"Content-Type":"application/json"},
  69.             parameters: updateData,
  70.             connection: "myapi"
  71.         ];
  72.         info "Project number updated successfully";
  73.     } catch (e) {
  74.         info "Update Error: " + e;
  75.     }
  76. }
Somebody knows where to look? I really don't understand whats wrong with the script. The invokeurl is correctly formatted.