500 Error for Ticket Creation using Request Method in Freshservice

Hello,

I am currently working on a custom application that using a button click fires off a post request for ticket creation in freshservice but I am running into a 500 error with a response of “We’re sorry but something went wrong”.

image

Tested ticket creation using postman and it worked without issue.

Here is the code snippet that I am using for the post request.

Even if I remove the parseFloat and enter a valid value I get the same response. Any help would be greatly appreciated.

Thank you,

Zach

I believe you missed = at headers Authorization

Authorization: "Basic <%= encode(iparam.freshservice_api_key) %>"

If this didn’t work, can you also try the below

Authorization: "Basic <%= iparam.freshservice_api_key %>"

1 Like

Hi @ManiDeepak_Vandrangi,

In the screenshot that I attached to this you can see that I incorporated the Authorization in the headers. I’m not sure if you were indicating that it was incorrect or if you noticed something else wrong with the code snippet. Appreciate you taking a look at this. I did try removing “encode” and the parenthesis around iparam.freshservice_api_key as you mentioned but got the same error when attempting the post request.

Thanks,
Zach

@ManiDeepak_Vandrangi,

Wow you were right after I sent the last message I took a closer look at my code and I did in fact type out the line of code for the authorization incorrectly. I was missing the “%” in the first iparam tag. Silly mistake but thank you for making me double check!!!

This worked correctly after fixing that mistyped error. :slight_smile:

Take care,
Zach

1 Like

A post was split to a new topic: Issue with Local app testing in Freshservice Sandbox

I have ran into another issue regarding this custom app.

It appears that after making the above mentioned changes, it would allow the post request to be made successfully. After validating the app and packaging it to install, I installed the application in my sandbox environment. Now I am back to getting a 500 error.

If I run the application locally and use ?dev=true on a ticket, then execute the application it functions just fine. Is anyone aware of limitations to app behavior when installed through the developer portal in a freshservice sandbox environment?

Since this app needs to be throughly tested before installing into my production environment I was hoping to be able to see it function as intended in our sandbox environment beforehand.

In this screen shot you can see the application installed (top), and it also installed locally using the fdk test environment (bottom). Successful using locally ran app (first group of console logs), fails using installed application (last group of console logs).

I would really like to test the installation and use in the sandbox before installing our production environment as to minimize the risk of agents using the application inadvertently prior to its full release.

Thank you for any help provided.

-Zach

The app should work in same way in sandbox environment as in production environment. Can you please check if the code has proper <%= %>

Hello @ManiDeepak_Vandrangi,

That was my understanding as well. I took the working code that was fixed by your first suggestion. All tags, <%= %>, are correct. I then validated the application, packaged the application, and installed the application in the sandbox as a custom app through the developer portal. Once the app became available I installed it into the sandbox environment entering the correct freshservice sub-domain and API key for my sandbox environment as instructed by the installation parameters that I designed. The code runs and works until the POST request where it fails and I get the 500 Error that you see in the above screenshot. So I am not sure what is causing the issue.

We can validate that the code is correct because when I run “fdk run” and append ?dev=true to a ticket in the sandbox, the code runs and the post request is successful using the exact same code that was packaged for the app.

Here is the link to the app in the developer portal https://www.freshdev.io/custom_apps/38735-clone_tickets/edit if that helps.

Thank you,

Zach

1 Like

Can you please remove space between encode and ( in
Basic <%= encode(iparam.freshservice_api_key) %>

@ManiDeepak_Vandrangi,

Removing the space did in fact fix the issue. Could you elaborate as to why this simple type error would allow the application to run locally without issue but prevent it from working when packaged and installed?

Appreciate your advice and help in solving this issue. :slight_smile:

Take care,

Zach

It should not work even in local testing. Can you please enable debug logs and check if it is really working.

I ran the debug logs and the application did run correctly. There was one line that I saw raised a flag:

The application functions, the post request is successful and creates a ticket that I can see inside the freshservice sandbox. I can share with you the debug logs if that helps but there is sensitive information (sub-domain, api keys) that I would like to not expose.

Thank you,

Zach

Can you please share with me ( either here or privately ) the app code which you is working only in local testing?

To conclude, @Zach had cleared local cache and tried again and it caused error in local testing.

1 Like