Hi,
We are new to Auth0 and investigation post registration actions. Ive set up an action to send a slack notification when a new user signs up. However, is it possible to send a freshdesk ticket also?
I have my Freshdesk API Key and here is the documentation
https://developers.freshdesk.com/api/#create_ticket
Really appreciate any ‘idiots guide’ tips if possible
Many thanks,
Fiorano
Hi @Senor_Fiorano ,
Thanks for reaching out to the Auth0 Community!
Yes, absolutely. After scanning through the Freshdesk API docs, you can send a Freshdesk ticket in Actions.
I have not personally tried it myself but would be more than happy to walk you through the implementation.
Please let me know.
Thanks.
1 Like
hi @rueben.tiow ,
Thanks for the reply and absolutely YES! If you’d be so kind to walk me through it that would be amazing.
What would be the best way to proceed?
Kind regards,
Fiorano
Hi @Senor_Fiorano ,
Thank you for your response.
Sure, that’s not a problem. You could use an Axios POST request within the Post Registration Action to create the FreshDesk ticket.
Here is a skeleton you can start with and adapt with the FreshDesk API and corresponding endpoints and data.
exports.onExecutePostUserRegistration = async (event, api) => {
const axios = require('axios');
const qs = require('querystring');
const url = 'https://domain.freshdesk.com/api/v2/tickets';
const options = {
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': event.secrets.token
}
};
const data = {
email: event.user.email,
//other data here
};
var response = await axios.post(url, qs.stringify(data), options);
console.log(response.data);
};
Please note that the events.secrets.token
is a secret key stored in the Secrets section of your action script. The Secrets section is located on the left column with a key icon.
Please let me know how this works for you.
Thanks!
HI @rueben.tiow
Thanks so much for your help.
Ive tried your solution and getting the following error:
Test Results
Error:
{
"message": "Request failed with status code 415",
"name": "Error"
}
ive added a secret of freshdeskapikey …
Am I missing something?
Many thanks,
Fiorano
Hi @rueben.tiow ,
Just wondering if you any thoughts on the error Im getting?
Many thanks,
Fiorano
Hi @Senor_Fiorano ,
Thank you for your response.
The error you are getting seems to have to do with the FreshDesk server refusing to accept the request because the payload format is in an unsupported format.
In this case, could you try using 'Content-Type': 'application/json'
instead and see how that works?
I believe you will also need to pass the data as JSON object var response = await axios.post(url, JSON.stringify(data), options);
Lastly, you may find this Create FreshDesk ticket code snippet example helpful.
Looking forward to your updates on how this goes.
Thank you.
Hi @rueben.tiow
Thanks again for your response and your suggestion
I now have the following and Im still getting a 401 error
exports.onExecutePostUserRegistration = async (event, api) => {
const axios = require('axios');
const qs = require('querystring');
const url2 = 'https://ourdomain.freshdesk.com/api/v2/tickets';
const options = {
headers: {
'Content-Type': 'application/json',
'Authorization': event.secrets.freshdeskapikey
}
};
const data = {
email: event.user.email,
//other data here
};
var response = await axios.post(url2, JSON.stringify(data), options);
console.log(response.data);
};
Appreciate any thoughts you may have?
Many thanks again,
Fiorano
1 Like
Hi @Senor_Fiorano ,
Thank you for your update.
I have gone ahead and signed up for a free trial with FreshDesk and used their NPM module with the Action script to accomplish creating a new ticket.
I have tested and managed to create tickets. This approach should be more maintainable.
First, add the freshdesk-api
module version 2.14.1
in your Action script.
Then in the script, use the following example to create a ticket:
exports.onExecutePostLogin = async (event, api) => {
var Freshdesk = require("freshdesk-api");
var freshdesk = new Freshdesk("https://adviseinc.freshdesk.com", event.secret. freshdeskapikey);
freshdesk.createTicket(
{
name: "test ticket",
email: "test@test.com",
subject: "test sub",
description: "test description",
status: 2,
priority: 1,
},
function (err, data) {
console.log(err || data);
}
);
Here is the Fresh Desk NPM module for your reference.
Once this is complete, you can check your Freshdesk Dashboard to see the newly created Ticket.
Thank you.
system
Closed
February 8, 2022, 5:13pm
11
This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.