List Tickets - You have to be logged in to perform this action

As part of a custom installation, I want to update the all existing tickets, so I am starting by attempting to list all existing tickets, using the invokeTemplate method. However, I get an invalid credential error if I include the query string ?updated_since=2015-02-19T02:00:00Z as per example. If I omit this query, I do not get any error, and I can make the call using the standard API and other calls with the
same authorization string.

Call

        THIS.client.request.invokeTemplate("getTickets",{
            context:{
              domain: THIS.domain,
              api_key: THIS.apikey,
              per_page: freshdesk_page_size,
              page: page,
              query:query
            }
          }
        ).then(

Relevant section from requests.json

    "getTickets":{
        "schema":{
            "protocol":"https",
            "method":"GET",
            "host":"<%= context.domain %>",
            "path":"/api/v2/tickets?per_page=<%= context.per_page %>&page=<%= context.page %>&<%= context.query %>",  
            "headers": {
                "Authorization": "Basic <%= encode(context.api_key) %>",
                "Content-Type": "application/json"
              }
        }
    },

I’ve attached screen shots of the request send to the server and the response received.


If I remember correctly the API key can only be used at runtime from the secure params. It cannot be passed in the context. Exception for that is on the installation page I believe

Sorry, my previous comment was wrong. You can actually use API key from the context it seems. Your problem might be connected to the query. You need to pass that as a separate parameter in the schema. Here is an example how I used it with agents:

"getAgents": {
    "schema": {
      "protocol": "https",
      "method": "GET",
      "host": "<%= iparam.freshdeskDomain %>.freshdesk.com",
      "path": "/api/v2/agents",
      "query": {
        "page": "<%= context.page %>",
        "per_page": "100"
      },
      "headers": {
        "Authorization": "Basic <%= encode(iparam.apiKey) %>",
        "Content-Type": "application/json"
      }
    }
  }

Hey @DaveWP,

The ISO datetime strings work in production, so if you fdk pack and then publish as a custom app it should work as expected. We noticed a small fix on fdk, thanks for bringing this to our notice.

Im validating api key and domain when installing:

requests.json

 "validateKey": {
    "schema": {
      "protocol": "https",
      "method": "GET",
      "host": "<%= context.domain %>.freshdesk.com",
      "path": "/api/v2/tickets",
      "headers": {
        "Authorization": "Basic <%= context.apiKey %>",
        "Content-Type": "application/json"
      }
    }
  }

iparams.js

client.request.invokeTemplate('validateKey', {
                context: {
                    apiKey: utils.get("apiKey"),
                    domain: utils.get("domain")
                },
            }).then(
                function (data) {
                    console.log(data)
                    resolve();
                },
                function (error) {
                    console.log(error)
                    // Upon failure - send an appropriate validation error message
                    reject("This key/domain is invalid. Please enter the right one");
                }
            );

I console log the data in iparams.js and I got the right data, but I got the error same as this article title

Hey @Van_Hung_Hoang,
Do you see this error when installing the app for the first time? utils.get() would be able to fetch the values only when it’s installed, you would have to fetch the values from HTML DOM.

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