From_email parameter not working when replying via API

Hello,

I am having trouble getting the from_email parameter to work when using the the Freshdesk reply API from here: Freshdesk

When I use just the body parameter by itself, it goes through perfectly fine, but when I use the body parameter in conjunction with the from_email parameter, it doesn’t go through at all.

Below is my code so far, can anyone help me and see where I am going wrong?

import base64 from 'base-64'

const reply = async ( req, res) => {

  let reply = req.query.reply;
  let id = req.query.id;
  let data = {
    "from_email": "matthew.gadd@email.com", 
    "body": reply,
   }

    try {
      const response = await fetch(
        "https://website.freshdesk.com/api/v2/tickets/" + id + "/reply",
        {
          body: JSON.stringify(data),
          headers: {
            'Authorization': 'Basic ' + base64.encode("apikey:X"),
            "Content-Type": "application/json; charset=utf8"
          },
          method: 'POST'   
        }

      );

      console.log(response.headers)

      if (response.status >= 400) {
        return res.status(400).json({
          error: 'There was an error'
        });
      }

      return res.status(200).json({ status: 'ok' });
    } catch (error) {
      return res.status(500).json({
        error: 'There was an error'
      });
    }
  };

  export default reply;

@kloneman,
Good Day!

can you check the from_email which you are sending is available in the contacts?

Thanks

This should one of the emails from the list of email configs.
API: Freshdesk

Hi Santhosh,

Yes, I can confirm that the email address I am sending the reply from is in our contacts list, I have also tried other contact emails as well but no luck.

Thanks

Hi Thanashyam,

If I used this method, would I have to create an email config for every contact in my contact list? That seems a bit counter productive really to achieve what I want to do.

With the create ticket api, it simply just lets you enter the email address of the person you want to create the ticket with, why is this not the case for the reply ticket api?

Thanks

I’ve encountered the same issue today. How did you proceed?

Hi Yuri, in the end I had to use user_id. What I did was I made a GET request to the contacts API “https://company.freshdesk.com/api/v2/contacts?email=XXXX” where XXXX equals the email address you want to send the reply from. Then in the body of the response, it gives you the contacts id, which you can then pass to a reply POST request. I’m using react but the below code might help you:

const [contact, setContact] = useState(“”)
async function fetchContact() {
const res = await fetch(‘https://company.freshdesk.com/api/v2/contacts?email=’ + lowerUser, { method: “GET”, headers: { ‘Authorization’: 'Basic ’ + base64.encode(“apikey:X”) } })
const data = await res.json()
if (data[0]){
setContact(data[0].id);
}
console.log(contact)
}

const formData = new FormData();
formData.append(“user_id”, contact);
fetch(
https://company.freshdesk.com/api/v2/tickets/’ + id + ‘/reply’,
{
method: ‘POST’,
body: formData,
headers: {
“Authorization”: "Basic " + base64.encode(“apikey:X”)
}
}
)

1 Like

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