return new Promise((resolve) => {

    const URL = `https://${getDomain(payload)}.freshservice.com/api/v2/tickets`;

    const headers = {
      'Authorization': 'Basic ' + getToken(payload),
      "Content-Type": "multipart/form-data",
    };

    const options = {
      method: "POST",
      url: URL,
      headers: headers,
    };

    // console.log("options------->", options);

    const req = request(options, async function (err, res, body) {

      if (!err && (res.statusCode === 200 || res.statusCode === 201)) {

        console.log("Ticket Created in Vendor Instance Status Code :", res.statusCode);

        const secondCreatedTicket = JSON.parse(body);

        console.log("------------------------ >Ticket Data :\n ", secondCreatedTicket);

        await updateOriginalTicketCustomField(payload, secondCreatedTicket, iparamvalues);

        resolve(JSON.parse(body));

      } else {
        
        console.log("Full Response Error :", res.body);
        console.log("Status Code :", res.statusCode);

        // let errorMessage = res.body;

        let errorMessage = "Error in createTicketIn2ndInstance: ";

        // if (error.status) {
        if (!err && (res.statusCode)) {
          switch (res.statusCode) {
            case 400:
              errorMessage += "Client or Validation Error: The request body/query string is not in the correct format. " +
                "For example, missing required fields or sending deprecated/invalid attributes.";
              break;
            case 401:
              errorMessage += "Authentication Failure: The Authorization header is either missing or incorrect.";
              break;
            case 403:
              errorMessage += "Access Denied: Agent is not authorized for this API call or lacks necessary permissions.";
              break;
            case 404:
              errorMessage += "Requested Resource Not Found: Invalid ID/domain in the URL or incorrect URL.";
              break;
            case 405:
              errorMessage += "Method Not Allowed: Incorrect HTTP verb/method used for the request.";
              break;
            case 406:
              errorMessage += "Unsupported Accept Header: Only application/json and */* are supported.";
              break;
            case 409:
              errorMessage += "Inconsistent/Conflicting State: Resource is in a conflicting or inconsistent state.";
              break;
            case 415:
              errorMessage += "Unsupported Content-type: Only application/json is supported, not application/xml.";
              break;
            case 429:
              errorMessage += "Rate Limit Exceeded: API rate limit for your Freshservice domain has been exhausted.";
              break;
            case 500:
              errorMessage += "Unexpected Server Error: An issue occurred on Freshservice's side.";
              break;
            default:
              errorMessage += `Unexpected API Error with status ${error.response.status}.`;
          }
        } else if (error.request) {
          errorMessage += "No response received from the API. Please check your network connection.";
        } else {
          errorMessage += `Unknown error: ${error.message}`;
        }

        console.error("The Error is : ", errorMessage);

        // console.log(ticketid);

        addNoteDuringTicketCreateError(ticketid, errorMessage, payload);

        await sendEmail(payload, errorMessage);


      }

    });

    const form = req.form();

    for (const key in ticketObj) {
      if (ticketObj.hasOwnProperty(key)) {
        
        const p_value = ticketObj[key];

        if (typeof p_value === "string") {
          form.append(key, p_value);
        } else if (Array.isArray(p_value)) {
          for (let i = 0; i < p_value.length; i++) {
            form.append(`${key}[]`, p_value[i]);
          }
        } else if (typeof p_value === "object") {
          for (const cust_key in p_value) {
            const cust_value = p_value[cust_key];
            if (typeof cust_value === "boolean") {
              form.append(`${key}[${cust_key}]`, cust_value.toString());
            } else if (Array.isArray(cust_value)) {
              cust_value.forEach(value => {
                form.append(`${key}[${cust_key}][]`, value);
              });
            } else {
              form.append(`${key}[${cust_key}]`, cust_value);
            }
          }
        } else {
          form.append(key, JSON.stringify(p_value));
        }
      }
    }

    // Add attachments
    // const attachments = payload.data.ticket.attachments || [];
    // for (let i = 0; i < attachments.length; i++) {
    //   console.log("attachments[i]", attachments[i]);

    //   form.append("attachments[]", request.get(attachments[i].url), {
    //     filename: attachments[i].filename,
    //     contentType: attachments[i].type,
    //   });
    // }


    for (let i = 0; i < attachments.length; i++) {
      form.append('attachments[]', request.get(attachments[i].attachment_url), { filename: attachments[i].name, contentType: attachments[i].content_type });
    }


    // console.log("*** form ***", form);
  });



⚠ server\server.js::146: Function 'evaluateRules' has a complexity of 11. Maximum allowed is 7.
⚠ server\server.js::248: Arrow function has a complexity of 11. Maximum allowed is 7.   
⚠ server\server.js::264: 'req' is never reassigned. Use 'const' instead.
⚠ server\server.js::264: Async function has a complexity of 17. Maximum allowed is 7.   
⚠ server\server.js::346: Do not access Object.prototype method 'hasOwnProperty' from target object.

fix this issues