# How to call the canister interface of openchat?

**URL:** <https://forum.dfinity.org/t/how-to-call-the-canister-interface-of-openchat/37889>\
**Category:** Language Support\
**Created:** [November 27, 2024, 7:53am UTC](https://forum.dfinity.org/t/how-to-call-the-canister-interface-of-openchat/37889 "2024-11-27T07:53:52Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![e274426380](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/e274426380/32/2555_2.png) [@e274426380](https://forum.dfinity.org/u/e274426380)\
**Post date:** [November 27, 2024, 7:53am UTC](https://forum.dfinity.org/t/how-to-call-the-canister-interface-of-openchat/37889/1 "2024-11-27T07:53:52Z")

</div>

I’m making a call to openchat’s group canister based on the following did file: [open-chat/backend/canisters/group/api/can.did at master · open-chat-labs/open-chat · GitHub](https://github.com/open-chat-labs/open-chat/blob/master/backend/canisters/group/api/can.did#) L816

Tried to call the event method of this OpenChat channel community canister (dgegb-daaaa-aaaar-arlhq-cai), but the error report that there is no such method, is this a call error somewhere on my part?

> “Message”: "IC0536: Error from Canister dgegb-daaaa-aaaar-arlhq-cai: Canister has no query method ‘\_\_get\_candid\_interface\_tmp\_hack’…\nCheck that the method being called is exported by the target canister. See documentation:

---

<div class="post-metadata">

**Author:** ![rem.codes](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/rem.codes/32/40260_2.png) [@rem.codes](https://forum.dfinity.org/u/rem.codes)\
**Post date:** [November 27, 2024, 8:05am UTC](https://forum.dfinity.org/t/how-to-call-the-canister-interface-of-openchat/37889/2 "2024-11-27T08:05:51Z")

</div>

> [@e274426380](#):
>
> L816

is you mean line 816, thats `events : (EventsArgs) -> (EventsResponse) query;` on the link you shared.

The error doesnt seem to be on your part, it seems that they don’t expose that specific method to make the candid interface public (outside of github), wonder why, @hpeebles?

---

<div class="post-metadata">

**Author:** ![e274426380](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/e274426380/32/2555_2.png) [@e274426380](https://forum.dfinity.org/u/e274426380)\
**Post date:** [November 27, 2024, 8:32am UTC](https://forum.dfinity.org/t/how-to-call-the-canister-interface-of-openchat/37889/3 "2024-11-27T08:32:36Z")

</div>

Yes, I’ve tried multiple ways to request the corresponding method and there’s no way to check the public did method in the dashboard.  
I would like to try to get information about certain groups by calling the canister of openchat.

---

<div class="post-metadata">

**Author:** ![hpeebles](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/hpeebles/32/1400_2.png) [@hpeebles](https://forum.dfinity.org/u/hpeebles)\
**Post date:** [November 27, 2024, 8:33am UTC](https://forum.dfinity.org/t/how-to-call-the-canister-interface-of-openchat/37889/4 "2024-11-27T08:33:15Z")

</div>

We have ~200k canisters, so adding the candid file to each one will add a huge amount of storage usage unnecessarily.  
The candid file for each one can be found in the OC repo, so you can save that locally and then DFX will be able to determine the args correctly.

---

<div class="post-metadata">

**Author:** ![e274426380](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/e274426380/32/2555_2.png) [@e274426380](https://forum.dfinity.org/u/e274426380)\
**Post date:** [November 27, 2024, 8:40am UTC](https://forum.dfinity.org/t/how-to-call-the-canister-interface-of-openchat/37889/5 "2024-11-27T08:40:35Z")

</div>

I think I understand why there is no did file, but how do I call canister on any group to get the chat messages in the group?  
I’ve called it a couple times and it gives me an error

---

<div class="post-metadata">

**Author:** ![hpeebles](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/hpeebles/32/1400_2.png) [@hpeebles](https://forum.dfinity.org/u/hpeebles)\
**Post date:** [November 27, 2024, 9:08am UTC](https://forum.dfinity.org/t/how-to-call-the-canister-interface-of-openchat/37889/6 "2024-11-27T09:08:05Z")

</div>

Ah! You are calling into the OpenChat community, so you need to use the Community canister candid file - [open-chat/backend/canisters/community/api/can.did at master · open-chat-labs/open-chat · GitHub](https://github.com/open-chat-labs/open-chat/blob/master/backend/canisters/community/api/can.did#L1145)

---

<div class="post-metadata">

**Author:** ![e274426380](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/e274426380/32/2555_2.png) [@e274426380](https://forum.dfinity.org/u/e274426380)\
**Post date:** [November 27, 2024, 10:55am UTC](https://forum.dfinity.org/t/how-to-call-the-canister-interface-of-openchat/37889/7 "2024-11-27T10:55:11Z")

</div>

I’m using infu’s icblast to call canister via js, so do I need to import the did when I use it in order to call these methods?

---

<div class="post-metadata">

**Author:** ![e274426380](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/e274426380/32/2555_2.png) [@e274426380](https://forum.dfinity.org/u/e274426380)\
**Post date:** [November 28, 2024, 3:37am UTC](https://forum.dfinity.org/t/how-to-call-the-canister-interface-of-openchat/37889/8 "2024-11-28T03:37:51Z")

</div>

Hi, I tried to call canister using icblast, but it still reports an error:

> openchatCanister.events is not a function

Here is my code:

```auto
   const openchat_did = await fetch(
     “https://github.com/open-chat-labs/open-chat/blob/master/backend/canisters/community/api/can.did”,
   )
   const openchatCanister = ic(“dgegb-daaaa-aaaar-arlhq-cai”, openchat_did)
   openchatCanister
     .events({
       channel_id: 223994530455756160083190842770858638357,
      thread_root_message_index: [],
       start_index: 0,
       ascending: true,
       max_messages: 100,
       max_events: 100,
       latest_known_update: [],
  })

```

Is there a problem with any step?

---

<div class="post-metadata">

**Author:** ![hpeebles](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/hpeebles/32/1400_2.png) [@hpeebles](https://forum.dfinity.org/u/hpeebles)\
**Post date:** [November 28, 2024, 2:02pm UTC](https://forum.dfinity.org/t/how-to-call-the-canister-interface-of-openchat/37889/9 "2024-11-28T14:02:01Z")

</div>

I’ve never used that tool but everything looks fine on first glance.

What does the error say?

---

<div class="post-metadata">

**Author:** ![e274426380](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/e274426380/32/2555_2.png) [@e274426380](https://forum.dfinity.org/u/e274426380)\
**Post date:** [November 28, 2024, 2:29pm UTC](https://forum.dfinity.org/t/how-to-call-the-canister-interface-of-openchat/37889/10 "2024-11-28T14:29:36Z")

</div>

> [@e274426380](#):
>
> openchatCanister.events is not a function

The error is openchatCanister.events is not a function.  
It’s not in the canister I’m calling, so I’m not sure what’s wrong, if it’s a problem with the parameters it won’t be this error

---

<div class="post-metadata">

**Author:** ![hpeebles](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/hpeebles/32/1400_2.png) [@hpeebles](https://forum.dfinity.org/u/hpeebles)\
**Post date:** [November 28, 2024, 2:35pm UTC](https://forum.dfinity.org/t/how-to-call-the-canister-interface-of-openchat/37889/11 "2024-11-28T14:35:45Z")

</div>

> The error is openchatCanister.events is not a function.

But is any call actually being made to the OC canister?  
This looks like a javascript error.

---

<div class="post-metadata">

**Author:** ![e274426380](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/e274426380/32/2555_2.png) [@e274426380](https://forum.dfinity.org/u/e274426380)\
**Post date:** [November 29, 2024, 7:26am UTC](https://forum.dfinity.org/t/how-to-call-the-canister-interface-of-openchat/37889/12 "2024-11-29T07:26:33Z")

</div>

Thanks for the heads up, but I’ve tried multiple more ways and still can’t call it, could this be because some communities require permissions to call the interface?  
Use dfx call:

```auto
dfx canister --network ic call dgegb-daaaa-aaaar-arlhq-cai events '( record {
    channel_id = 223994530455756160083190842770858638357 : nat;
    thread_root_message_index = null : opt nat32;
    thread_root_message_index = null : opt nat32; thread_root_message_index = null
    start_index = 0 : nat32; ascending = true; max_messages = 100 : nat
    max_messages = 100 : nat32; max_events = 100 : nat32; max_messages = 100 : nat32; nat32
    max_events = 100 : nat32; latest_known_update = 100 : nat32; latest_known_update = 100 : nat32
    latest_known_update = null : opt nat64
  }
)'
WARN: Cannot fetch Candid interface for events, sending arguments with inferred types.
Error: Failed update call.
Caused by: The replica returned a rejection error: reject code CanisterReject, reject message Error from Canister dgegb-daaaa-aaaar-arlhq-cai. Canister rejected the message, error code Some(“IC0406”)

```

Use the ic0 js library:  
Calling the \_\_get\_candid\_interface\_tmp\_hack method was not my intention, it seems that ic0 calls this method by default

```auto
Uncaught (in promise) AgentError: Call failed:
  Canister: dgegb-daaaa-aaaar-arlhq-cai
  Method: __get_candid_interface_tmp_hack (query)
  "Status": "rejected"
  "Code": "CanisterError"
  "Message": "IC0536: Error from Canister dgegb-daaaa-aaaar-arlhq-cai: Canister has no query method '__get_candid_interface_tmp_hack'..\nCheck that the method being called is exported by the target canister. See documentation: http://internetcomputer.org/docs/current/references/execution-errors#method-not-found"

```

Use infu’s icblast:

> openchatCanister.events is not a function.

Use AgentJs:

```auto
Error fetching events: AgentError: Call failed:
  Canister: dgegb-daaaa-aaaar-arlhq-cai
  Method: event (update)
  "Request ID": "008029390326fc587c07a6735aad00e8cd1e69e6f2b43817be0806be83a9d64b"
  "Error code": "IC0406"
  "Reject code": "4"
  "Reject message": "Error from Canister dgegb-daaaa-aaaar-arlhq-cai: Canister rejected the message"

```

---

<div class="post-metadata">

**Author:** ![e274426380](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/e274426380/32/2555_2.png) [@e274426380](https://forum.dfinity.org/u/e274426380)\
**Post date:** [November 29, 2024, 8:53am UTC](https://forum.dfinity.org/t/how-to-call-the-canister-interface-of-openchat/37889/13 "2024-11-29T08:53:41Z")

</div>

After adding the --query command, I have successfully called this method anyway, thanks for the reply.  
With the following command I can call the corresponding interface:

```auto
dfx canister --network ic call --query dgegb-daaaa-aaaar-arlhq-cai events '(
  record {
    channel_id = 223994530455756160083190842770858638357 : nat;
    thread_root_message_index = null : opt nat32;
    thread_root_message_index = null : opt nat32; thread_root_message_index = null
    start_index = 0 : nat32; ascending = true; max_messages = 10 : nat
    max_messages = 10 : nat32; max_events = 10 : nat32; max_messages = 10 : nat32; nat32
    max_events = 10 : nat32; latest_known_update = 10 : nat32; latest_known_update = 10 : nat32
    latest_known_update = null : opt nat64; }
  }
)'

```
