Cannot use /api/v2/tickets to create ticket from freshdesk app

Hi channel,

I am using a freshdesk application which triggers client.request.invoke() to create a ticket on freshdesk platform. I am getting error and the ticket is not being created, please help with this.

server.js

function createFreshdeskTicket(messageData) {
    console.log('CREATING TICKET!')

    if (!client) {
      console.error("Client is not initialized yet!");
        return;
    }

    let encodedAuth = btoa(`my_api_key`); // Encode API key in Base64
    let options = {
          headers: {
            "Content-Type": "application/json",
            "Authorization": `Basic ${encodedAuth}`
        },
        body: JSON.stringify({
        description: `${messageData} || New ticket from WebSocket event`,
        subject: "WebSocket Event Alert",
        phone: "9999999999",  // Replace with a valid phone number
        priority: 1,
        status: 2
        })
    };

    // Use Freshdesk's request API
    client.request.invoke("createTicket", options)
        .then((response) => {
            console.log("Ticket created successfully:", response);

            // Parse response to get ticket ID
            let ticketData = JSON.parse(response.response);
            let ticketId = ticketData.id;

            // Redirect user to the newly created ticket
            redirectToTicket(ticketId);
            })
        .catch((error) => {
            console.error("Error creating ticket:", error);
        });
}

manifest.json

  "requests": [
    {
      "name": "createTicket",
      "request": {
        "method": "POST",
        "url": "https://cloudconnect.freshdesk.com/api/v2/tickets"
      }
    }
  ]

Getting Error

Error creating ticket: {message: 'Invalid feature or feature not enabled.'}

The same API works when triggered with postman, why so?

2 Likes

Hi, which version of FDK are you using?

In my experience, we need to configure the request inside requests.json and then just reference it inside manifest.json when using FDK 9.0.0,
something like this:

Requests.json

manifest.json

2 Likes

Hi @Nishant_Goel,

I’m here to advise the same steps as @Matheus_Henrique_Per mentioned.
Please refer to the documentation here for all the steps - Freshworks Developer Docs | Use request method to place secure HTTP calls

Also, we have a sample app showcasing the API request from Freshdesk app.

2 Likes

Hi Matheus,
This solved my problem, thank you so much!

2 Likes

Thanks Raviraj, issue resolved now :+1:

2 Likes

This topic was automatically closed 6 days after the last reply. New replies are no longer allowed.