Issue with Setting Preferences and Channel using Zammad API with 'X-On-Behalf-Of'

Hello Zammad Community,

I’m currently working on integrating Zammad with Telegram via API, and I’m encountering an issue when trying to create tickets using the 'X-On-Behalf-Of' header. Here’s the situation:

I’m using the following function to create a ticket in Zammad:


async function createTicketInZammad(customerId, userData) {
    console.log(`Creating ticket for customer ID: ${customerId}`);
    console.log("userData", JSON.stringify(userData));
    try {
        const response = await axios.post(`${zammadUrl}/tickets`, {
            title: `Inquiry: ${userData.typeOfInquiry}`,
            group: 'Support',
            customer_id: customerId,
            category: userData.typeOfInquiry,
            contact_number: userData.email,
            article: {
                subject: `Issue: ${userData.priorityLevel} - ${userData.telegramUsername}`,
                body: `Name: ${userData.name}\n\nDescription: ${userData.issueDescription}\n\nPhone No.: ${userData.email}\nType Of Inquiry: ${userData.typeOfInquiry}\nPriority: ${userData.priorityLevel}`,
                type: "telegram personal-message",
                sender: 'Customer',
                internal: false
            },
            preferences: {
                channel: "telegram personal-message",
                telegram: {
                    bid: "xxxxxxxtelegram-id",
                    chat_id: userData.chatId
                }
            }
        }, {
            headers: {
                'Authorization': `Bearer ${zammadToken}`,
                'Content-Type': 'application/json',
                'X-On-Behalf-Of': userData.telegramUsername
            }
        });

        console.log('Ticket created:', response.data);
        return response.data.id;
    } catch (error) {
        console.error('Error creating ticket:', error.response ? error.response.data : error.message);
        return null;
    }
}

When I do not include the 'X-On-Behalf-Of' header, everything works as expected, and the preferences are applied correctly, including the channel being set to telegram personal-message.

However, when I include the 'X-On-Behalf-Of' header, the preferences are ignored, and the channel is set to "note" instead of "telegram personal-message".

I need to use the 'X-On-Behalf-Of' header because I want the username to appear in the Activity Stream notifications instead of my name. Is there a way to fix this so that the preferences (especially the channel) are still applied correctly while using the 'X-On-Behalf-Of' header?

Any help would be appreciated. Thanks in advance!

Hi @cc1998 ,

seems like because of the missing ticket.agent permissions you get forced into a note:

Looks a bit like that you have to patch that. You could also try to play around with the origin_by_id parameter of the article, maybe this gets you there as well:

curl -X POST "http://localhost:3000/api/v1/tickets" \
-H "Authorization: Bearer B0CkzmgED34OW90gZVrf1B8wtf5gd6RG5RK-xxxx" \
-H "Content-Type: application/json" \
-d '{
  "title": "Inquiry: test",
  "group": "Users",
  "customer_id": 2,
  "article": {
    "subject": "test",
    "body": "test",
    "type": "telegram personal-message",
    "sender": "Customer",
    "internal": false,
    "origin_by_id": 2
  },
  "preferences": {
    "channel": "telegram personal-message",
    "telegram": {
      "bid": "xxxxxxxtelegram-id",
      "chat_id": "123"
    }
  }
}'