# callFunction JS SDK

**URL:** <https://community.particle.io/t/callfunction-js-sdk/24160>\
**Category:** Troubleshooting\
**Created:** [July 6, 2016, 9:25am UTC](https://community.particle.io/t/callfunction-js-sdk/24160 "2016-07-06T09:25:02Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mario](https://avatars.discourse-cdn.com/v4/letter/m/8e7dd6/32.png) [@Mario](https://community.particle.io/u/Mario)\
**Post date:** [July 6, 2016, 9:25am UTC](https://community.particle.io/t/callfunction-js-sdk/24160/1 "2016-07-06T09:25:02Z")

</div>

Hello.  
I am developing a web app with node.js.  
I am having a problem calling function. When I call a function in the cloud, which just turns on led D7, in the cmd it is said that the fucntion was called properly, but the led does not turn on.

Here is my code with jade.js using express as framewrok:

![](https://us1.discourse-cdn.com/flex026/uploads/particle/original/2X/9/994bbd1534fdd172048c46e2c18f7c2f9dd76be2.png)

And the sketch in the particle device:

![](https://us1.discourse-cdn.com/flex026/uploads/particle/original/2X/c/c072c6f6191851febade1c6662759ef77401b52f.png)

---

<div class="post-metadata">

**Author:** ![rickkas7](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/rickkas7/32/8681_2.png) [@rickkas7](https://community.particle.io/u/rickkas7)\
**Post date:** [July 6, 2016, 11:39am UTC](https://community.particle.io/t/callfunction-js-sdk/24160/2 "2016-07-06T11:39:13Z")

</div>

I may be misunderstanding your environment, but when I call a function using the particle-api-js from node.js, I use a `particle.callFunction` which takes an object containing the device ID, function, arguments and authentication token and returns a promise.  
[https://docs.particle.io/reference/javascript/#callfunction](https://docs.particle.io/reference/javascript/#callfunction)

---

<div class="post-metadata">

**Author:** ![Mario](https://avatars.discourse-cdn.com/v4/letter/m/8e7dd6/32.png) [@Mario](https://community.particle.io/u/Mario)\
**Post date:** [July 6, 2016, 12:30pm UTC](https://community.particle.io/t/callfunction-js-sdk/24160/3 "2016-07-06T12:30:57Z")

</div>

Thanks,  
I use `var on = particle.callFunction(...)` as you’ve said but when need to call the function I use `on.then(...)`.

Or at least I undertand that this is the way it should be done from the example in the reference page:

![](https://us1.discourse-cdn.com/flex026/uploads/particle/original/2X/f/f6f1393926eca3784a7523fdb4de27815598e5a6.png)

The only think I am doing in a different way is leaving tha argument empty, since the cloud function does not use it.

---

<div class="post-metadata">

**Author:** ![rickkas7](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/rickkas7/32/8681_2.png) [@rickkas7](https://community.particle.io/u/rickkas7)\
**Post date:** [July 6, 2016, 12:59pm UTC](https://community.particle.io/t/callfunction-js-sdk/24160/4 "2016-07-06T12:59:52Z")

</div>

I don’t think you can use it like that. The particle.callFunction() returns a Promise. The code actually starts the operation at the point you call particle.callFunction(), not when you execute the then(). The example is misleading because fnPr makes it seem like a C function pointer, but it doesn’t really work like that.

Instead of using the variable `on`, try moving the actual particle.callFunction() call where the `then` is.

---

<div class="post-metadata">

**Author:** ![Mario](https://avatars.discourse-cdn.com/v4/letter/m/8e7dd6/32.png) [@Mario](https://community.particle.io/u/Mario)\
**Post date:** [July 6, 2016, 1:31pm UTC](https://community.particle.io/t/callfunction-js-sdk/24160/5 "2016-07-06T13:31:15Z")

</div>

Many thanks.  
Now it is working.

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [July 6, 2016, 3:29pm UTC](https://community.particle.io/t/callfunction-js-sdk/24160/6 "2016-07-06T15:29:04Z")

</div>

Just for coding style:  
Your functions are declared to return an `int` so you _should_ add a `return` statement that actually does return an `int`.
