Skip to main content

Hey all,

I am trying to build a connection to Front to interact with the conversations, so we can assign the assignees to the conversations through the API. Using the example of the API documentation keeps giving me errors and I can’t figure out what is going wrong. I’m using the Update conversation assignee with the NodeJS example, but I keep getting an error:
{"_error":{"status":400,"title":"Bad request","message":"Body did not satisfy requirements","details":i"body.assignee_id: missing"]}}

I’ve tried it with JSON and FormData, but the error stays the same, my latest example code is the following
 

const frontUpdateAssignee = async ({ conversation, assignee, token }) => {

 

  const options = {

    method: "PUT",

    headers: {

      accept: "multipart/form-data",

      authorization: `Bearer ${token}`,

    },

    body: JSON.stringify({ assignee_id: "tea_hjdlj" }),

  };

  const updateAssignee = await fetch(

    `https://api2.frontapp.com/conversations/${conversation}/assignee`,

    options

  )

    .then((res) => res.json())

    .then((res) => console.log(res))

    .catch((err) => console.error(err));

 

  return {

    result: updateAssignee,

  };

};

 

I can’t figure out what is going wrong after a few hours. Hope you guys can get me on track.

Hi, 

Looks like you’re sending a JSON payload, but sending a default multipart/form-data request by not specifying a Content-Type, so Front is not parsing the request body as JSON. 

To resolve, just add a Content-Type: “application/json” header.
You also probably want to remove or edit the Accept header, and Front will never return a multipart/form-data response body. 


Hey, yeah sorry. Just changed this one to reflect my JSON one instead of my multipart/form-data one. Changed it to Content-Type: “application/json”, but sadly it made no change.


 Can you confirm your code looks something like this?

There was a minor issue with your expected return type, but that should not have impacted the “assignee_id not found” issue. 

const frontUpdateAssignee = async ({ conversation, assignee_id, token }) => {
const options = {
method: "PUT",
headers: {
accept: "application/json",
authorization: `Bearer ${token}`,
"Content-Type": "application/json",
},
body: JSON.stringify({ assignee_id }),
};

try {
const response = await fetch(
`https://api2.frontapp.com/conversations/${conversation}/assignee`,
options
)

// The endpoint returns an HTTP 204 on success (no content)
// @see https://dev.frontapp.com/reference/update-conversation-assignee
return {
success: response.ok()
}
} catch (error) {
console.error(err);
}
};


// So you would call this following, and result would be {success: true} or {success: false}
const result = await frontUpdateAssignee({
conversation: "cnv_123",
assignee_id: "tea_123",
token: "MY_API_TOKEN",
})

I have a real working example of somewhat similar code available here if you want to compare;
https://github.com/dugjason/ollama-generate-helpdesk-data/blob/36e2438010a51234aba8442d75e46556a98a23e0/lib/helpdesks/front.ts#L78-L133 


Seems the problem was in the platform I was using, not in my code. But thanks for the help and the examples!


Reply