# Call opt record from javascript

**URL:** <https://forum.dfinity.org/t/call-opt-record-from-javascript/9923>\
**Category:** Developers\
**Tags:** Frontend\
**Created:** [December 26, 2021, 10:36am UTC](https://forum.dfinity.org/t/call-opt-record-from-javascript/9923 "2021-12-26T10:36:48Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![rbole](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/rbole/32/1334_2.png) [@rbole](https://forum.dfinity.org/u/rbole)\
**Post date:** [December 26, 2021, 10:36am UTC](https://forum.dfinity.org/t/call-opt-record-from-javascript/9923/1 "2021-12-26T10:36:48Z")

</div>

Hi,  
I try to call a motoko function from Javascript. On the console I can do that with:

> dfx canister call store01 list ‘(opt record {contains=opt “text01”; startsWith=null})’

How can I do that with from the Javascript site: I have tried different variants e.g.:

> const a = await store01.list({contains:“”, startsWith:“”});

But I receive the following error:

> Error: Invalid opt record {contains:opt text; startsWith:opt text} argument: {“contains”:“”,“startsWith”:“”}

Thanks for some help.

---

<div class="post-metadata">

**Author:** ![Ori](https://avatars.discourse-cdn.com/v4/letter/o/ecae2f/32.png) [@Ori](https://forum.dfinity.org/u/Ori)\
**Post date:** [December 26, 2021, 1:04pm UTC](https://forum.dfinity.org/t/call-opt-record-from-javascript/9923/2 "2021-12-26T13:04:20Z")

</div>

The Javascript binding for optional types is `[] | [T]` , where an empty array represents null.  
This may be what you want to pass in for that example (untested):  
`[{contains: ["text01"], startsWith: []}]`

There’s a reference for the bindings here that can help (look for “Corresponding Javascript values” under each entry):  
[https://smartcontracts.org/docs/candid-guide/candid-types.html#type-opt](https://smartcontracts.org/docs/candid-guide/candid-types.html#type-opt)

---

<div class="post-metadata">

**Author:** ![rbole](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/rbole/32/1334_2.png) [@rbole](https://forum.dfinity.org/u/rbole)\
**Post date:** [December 27, 2021, 10:20am UTC](https://forum.dfinity.org/t/call-opt-record-from-javascript/9923/3 "2021-12-27T10:20:10Z")

</div>

Hi, thank you very much, the JavaScript binding is working now.

---

<div class="post-metadata">

**Author:** ![Stephen-Kimoi](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/stephen-kimoi/32/28729_2.png) [@Stephen-Kimoi](https://forum.dfinity.org/u/Stephen-Kimoi)\
**Post date:** [August 23, 2024, 1:53pm UTC](https://forum.dfinity.org/t/call-opt-record-from-javascript/9923/4 "2024-08-23T13:53:09Z")

</div>

Is this link still working? It seems to have some irrelevant content.

---

<div class="post-metadata">

**Author:** ![sea-snake](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/sea-snake/32/7243_2.png) [@sea-snake](https://forum.dfinity.org/u/sea-snake)\
**Post date:** [August 23, 2024, 3:45pm UTC](https://forum.dfinity.org/t/call-opt-record-from-javascript/9923/5 "2024-08-23T15:45:35Z")

</div>

Here’s a valid link [Candid reference | Internet Computer](https://internetcomputer.org/docs/current/references/candid-ref)

---

<div class="post-metadata">

**Author:** ![Ori](https://avatars.discourse-cdn.com/v4/letter/o/ecae2f/32.png) [@Ori](https://forum.dfinity.org/u/Ori)\
**Post date:** [August 23, 2024, 4:44pm UTC](https://forum.dfinity.org/t/call-opt-record-from-javascript/9923/6 "2024-08-23T16:44:50Z")

</div>

Thanks sea-snake! 🤙🏻
