# JS API: 404 on callFunction when argument is used

**URL:** <https://community.particle.io/t/js-api-404-on-callfunction-when-argument-is-used/38579>\
**Category:** Troubleshooting\
**Created:** [January 8, 2018, 9:04pm UTC](https://community.particle.io/t/js-api-404-on-callfunction-when-argument-is-used/38579 "2018-01-08T21:04:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![xkortex](https://avatars.discourse-cdn.com/v4/letter/x/77aa72/32.png) [@xkortex](https://community.particle.io/u/xkortex)\
**Post date:** [January 8, 2018, 9:04pm UTC](https://community.particle.io/t/js-api-404-on-callfunction-when-argument-is-used/38579/1 "2018-01-08T21:04:54Z")

</div>

I’m using the npm particle-api-js v. 7.0.1. I have a function on my device, `set_tset`, which sets a temperature setpoint, and then returns the value if successfully set. I also have `get_tset` which returns that value from the device.

```auto
volatile double tset = 42; // default value, should be overridden
...
void setup() {
    Particle.function("set_tset", set_tset);
    Particle.function("get_tset", get_tset);
   ...
}

```

```auto

int set_tset(String command) {
    String s = "";
    Particle.publish("debug", s.format("API called set_tset: " + command));
    float x = -1;
    x = atof(command);
    if (x > 0) {
        tset = x;
    }
    return (int) x;
}

```

```auto
int get_tset(String command ) {
    String s = "";
    Particle.publish("debug", s.format("API called get_tset: |%3.3f| ", tset));
    return (int) tset;
}

```

This function works fine with curl,

```auto
curl -X POST 
    https://api.particle.io/v1/devices/$dev/set_tset?access_token=$tok 
    -d arg="667"

```

successfully sets the variable on the device. However, in the JS API, using `particle.callFunction`,

```auto
let config = {deviceId: this.devID, name: "set_tset", argument: arg,  
              auth: this.access_token};
particle.callFunction(config).then(...)

```

I get a 404 with this response:

`{"ok":false,"error":"Function set_tset not found"}`

Curiously, if I use `callFunction` with no data argument passed, it succeeds with response:  
`{"id":"3b0024001247353236343033","last_app":"","connected":true,"return_value":0}`

I get a confirmation from the console that the function was successfully called (with no argument). The function is _definitely_ there, as calling it with empty argument works fine.

---

<div class="post-metadata">

**Author:** ![Moors7](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/moors7/32/588_2.png) [@Moors7](https://community.particle.io/u/Moors7)\
**Post date:** [January 8, 2018, 9:19pm UTC](https://community.particle.io/t/js-api-404-on-callfunction-when-argument-is-used/38579/2 "2018-01-08T21:19:25Z")

</div>

Could you try that call with all hardcoded data to rule out issues on that end?

---

<div class="post-metadata">

**Author:** ![xkortex](https://avatars.discourse-cdn.com/v4/letter/x/77aa72/32.png) [@xkortex](https://community.particle.io/u/xkortex)\
**Post date:** [January 8, 2018, 9:36pm UTC](https://community.particle.io/t/js-api-404-on-callfunction-when-argument-is-used/38579/3 "2018-01-08T21:36:05Z")

</div>

Got it! I was messing around with the hardcoded function, and happened to wrap the number value in quotes (`"777"`), and it worked. Looks like somewhere in the pipeline it does not like dealing with a raw numeric type. `arg.toString()` fixed it for me.

Thanks!

---

<div class="post-metadata">

**Author:** ![Moors7](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/moors7/32/588_2.png) [@Moors7](https://community.particle.io/u/Moors7)\
**Post date:** [January 8, 2018, 9:48pm UTC](https://community.particle.io/t/js-api-404-on-callfunction-when-argument-is-used/38579/4 "2018-01-08T21:48:06Z")

</div>

Well, Particle.function _does_ expect a String, so trying to send it an integer was long shot to begin with ;).

---

<div class="post-metadata">

**Author:** ![xkortex](https://avatars.discourse-cdn.com/v4/letter/x/77aa72/32.png) [@xkortex](https://community.particle.io/u/xkortex)\
**Post date:** [January 9, 2018, 10:46pm UTC](https://community.particle.io/t/js-api-404-on-callfunction-when-argument-is-used/38579/5 "2018-01-09T22:46:14Z")

</div>

Yeah, I come from a Python background, and Javascript’s fast and loose typing trips me up quite frequently (not to mention that 404 is the wrong return code for an invalid argument). It’s not obvious to me from the JS [documentation](https://docs.particle.io/reference/javascript/#callfunction) that an integer would or would not get converted to a string as part of the POST protocol. I guess I was under the impression that because of url-encoding everything gets processed as a string.
