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

**URL:** https://community.zammad.org/t/issue-with-setting-preferences-and-channel-using-zammad-api-with-x-on-behalf-of/15552
**Category:** Development
**Created:** [September 23, 2024, 9:05am UTC](https://community.zammad.org/t/issue-with-setting-preferences-and-channel-using-zammad-api-with-x-on-behalf-of/15552 "2024-09-23T09:05:43Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![cc1998](https://community.zammad.org/user_avatar/community.zammad.org/cc1998/32/9878_2.png) [@cc1998](https://community.zammad.org/u/cc1998)
#### Post date: [September 23, 2024, 9:05am UTC](https://community.zammad.org/t/issue-with-setting-preferences-and-channel-using-zammad-api-with-x-on-behalf-of/15552/1 "2024-09-23T09:05:43Z")

</div>

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:

```auto

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!

---

<div class="post-metadata">

### Author: ![rolfschmidt](https://community.zammad.org/user_avatar/community.zammad.org/rolfschmidt/32/3368_2.png) [@rolfschmidt](https://community.zammad.org/u/rolfschmidt)
#### Post date: [September 27, 2024, 12:46pm UTC](https://community.zammad.org/t/issue-with-setting-preferences-and-channel-using-zammad-api-with-x-on-behalf-of/15552/2 "2024-09-27T12:46:38Z")

</div>

Hi @cc1998 ,

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

> <https://github.com/zammad/zammad/blob/777958519961fd93524dc6577a8f1a016f2b6871/app/controllers/concerns/creates_ticket_articles.rb#L47-L49>

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:

```auto
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"
    }
  }
}'

```

---

<div class="post-metadata">

### Author: ![system](https://community.zammad.org/uploads/default/original/1X/5c5afaea2d23f811dbec33cd4edb02fa29d3262f.png) [@system](https://community.zammad.org/u/system)
#### Post date: [September 18, 2025, 9:05am UTC](https://community.zammad.org/t/issue-with-setting-preferences-and-channel-using-zammad-api-with-x-on-behalf-of/15552/3 "2025-09-18T09:05:58Z")

</div>

This topic was automatically closed after 360 days. New replies are no longer allowed.
