# Function digitalwrite not found when REST API(solved)

**URL:** <https://community.particle.io/t/function-digitalwrite-not-found-when-rest-api-solved/12075>\
**Category:** Firmware\
**Created:** [May 25, 2015, 5:47pm UTC](https://community.particle.io/t/function-digitalwrite-not-found-when-rest-api-solved/12075 "2015-05-25T17:47:59Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![helxsz](https://avatars.discourse-cdn.com/v4/letter/h/f0a364/32.png) [@helxsz](https://community.particle.io/u/helxsz)\
**Post date:** [May 25, 2015, 5:47pm UTC](https://community.particle.io/t/function-digitalwrite-not-found-when-rest-api-solved/12075/1 "2015-05-25T17:47:59Z")

</div>

I did remember that Particle did provide a REST API to make pin on and off by calling digitalwrite function.

After I loaded a firmware, when I called this API, it doesn’t work. is it because this API only works for the official firmware

for example

```auto
curl https://api.particle.io/v1/devices/51ff73165082554910410187/digitalwrite?access_token=c30b010a6fbd25e0f081f6ba6ecfbaa6d6b7f4c4 -d params=D7,HIGH

```

but the server gives me back a response saying

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

```

---

<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:** [May 25, 2015, 6:00pm UTC](https://community.particle.io/t/function-digitalwrite-not-found-when-rest-api-solved/12075/2 "2015-05-25T18:00:40Z")

</div>

> [@helxsz](#):
>
> is it because this API only works for the official firmware

Partly Correct. It is not so much the "official firmware" but rather "adequate code". If you were to create a function called `digitalwrite`, you'd also be able to toggle it, provided your code handles it correctly. The REST API will also work with your own code, but you'll have to adjust your code/calls accordingly. If you haven't got a function `digitalwrite`, it becomes really hard to use it, right? All of this is described in the [Tinker section](http://docs.particle.io/core/tinker/) of the docs, since that's the code that runs as factory firmware/reset. Over here, it explains how to [Use Tinker with your own code.](http://docs.particle.io/core/tinker/#tinkering-with-tinker-using-tinker-with-your-code)  
[Here](http://docs.particle.io/core/firmware/#spark-function) you can see examples of how to use fucntions, and call them correctly.  
If you want an easy way to check what functions/ variables are available, and like to call them, you could take a look at [this page](http://jordymoors.nl/interface/) I've made with the [Particle JavaScript library.](http://docs.particle.io/core/javascript/) Just log in with your Particle credentials, and you should be good to go (I won't have access to it!) 😄 Alternatively, you could call the API directly, using this URL:  
`api.particle.io/v1/devices/{device ID here}?access_token={access token here}`

Let me know if you need further explanation.

---

<div class="post-metadata">

**Author:** ![Bendrix](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/bendrix/32/5001_2.png) [@Bendrix](https://community.particle.io/u/Bendrix)\
**Post date:** [May 26, 2015, 12:53am UTC](https://community.particle.io/t/function-digitalwrite-not-found-when-rest-api-solved/12075/3 "2015-05-26T00:53:44Z")

</div>

@helxsz Here is the the code to open a web page that has two buttons you can use to pass a variable to a function. You will have to substitute your function name, your device ID and your token. It works very well. If all you want to do is experiment with running a function this will do it. I’m sure you could expand the example to get variables. Thanks to @bko for this example page.

```auto
<html>
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript" charset="utf-8"></script>
  <body>
    <P><br>Toggle Digital Output Pin 0<br><br></P>
    <script type="text/javascript">
      var deviceID = "123YourDeviceId456";
      var accessToken = "123YourAccessToken456";
      var setFunc = "lightLed0"; <----- replace lightLed0 with the name referenced in particle.function
      var newValue = "0";
      
      function sparkSetLED(newValue) {
      	var requestURL = "https://api.spark.io/v1/devices/" +deviceID + "/" + setFunc + "/";
      	$.post( requestURL, { params: newValue, access_token: accessToken });
      }
    </script>
    <button id="pushmeoff" onclick="sparkSetLED(0);">Push Me Off!</button>
    <button id="pushmeon" onclick="sparkSetLED(1);">Push Me On!</button>
  </body>
</html>

```

---

<div class="post-metadata">

**Author:** ![bko](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/bko/32/20704_2.png) [@bko](https://community.particle.io/u/bko)\
**Post date:** [May 26, 2015, 12:56am UTC](https://community.particle.io/t/function-digitalwrite-not-found-when-rest-api-solved/12075/4 "2015-05-26T00:56:42Z")

</div>

> [@Bendrix](#):
>
> I believe, @bko in an answer to me, suggested that it is not possible to run a function directly from the URL.

Hi @Bendrix

You are right that in a browser you cannot just type in a URL to POST to a form which is what a Particle function requires, but curl is smart about figuring out if a request should be a GET or a POST and with -d argument to curl, it will be a POST and work fine.

---

<div class="post-metadata">

**Author:** ![Bendrix](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/bendrix/32/5001_2.png) [@Bendrix](https://community.particle.io/u/Bendrix)\
**Post date:** [May 26, 2015, 1:01am UTC](https://community.particle.io/t/function-digitalwrite-not-found-when-rest-api-solved/12075/5 "2015-05-26T01:01:23Z")

</div>

If I prefix the https:// url instructions with ‘curl’, the browser tells me that Google could not find a document. 😄

---

<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:** [May 26, 2015, 1:03am UTC](https://community.particle.io/t/function-digitalwrite-not-found-when-rest-api-solved/12075/6 "2015-05-26T01:03:25Z")

</div>

That’s because CURL is a command line program you’ve got to install (depending on your OS) and thus has nothing to do with your browser 😉

---

<div class="post-metadata">

**Author:** ![Bendrix](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/bendrix/32/5001_2.png) [@Bendrix](https://community.particle.io/u/Bendrix)\
**Post date:** [May 26, 2015, 1:05am UTC](https://community.particle.io/t/function-digitalwrite-not-found-when-rest-api-solved/12075/7 "2015-05-26T01:05:03Z")

</div>

I guess I’m one of those who just can’t tell a joke… 😉

---

<div class="post-metadata">

**Author:** ![abhi](https://avatars.discourse-cdn.com/v4/letter/a/b487fb/32.png) [@abhi](https://community.particle.io/u/abhi)\
**Post date:** [July 11, 2015, 8:22pm UTC](https://community.particle.io/t/function-digitalwrite-not-found-when-rest-api-solved/12075/8 "2015-07-11T20:22:41Z")

</div>

I’m facing the same problem. Received a Photon Wifi development kit at SOLID con last month. Trying to access the API at [http://docs.particle.io/photon/tinker/#the-tinker-api-digitalwrite](http://docs.particle.io/photon/tinker/#the-tinker-api-digitalwrite) - get the same “function not found error”. Any idea why their own documentation isn’t 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 11, 2015, 8:42pm UTC](https://community.particle.io/t/function-digitalwrite-not-found-when-rest-api-solved/12075/9 "2015-07-11T20:42:51Z")

</div>

You mean this?

```nohighlight
curl https://api.particle.io/v1/devices/<YOURDEVICEID>/digitalwrite -d access_token=<YOURACCESSTOKEN> -d params=D0,HIGH

```

Have you got `curl` installed and replaced the `<YOUR....>` portions with your personal data?

---

<div class="post-metadata">

**Author:** ![abhi](https://avatars.discourse-cdn.com/v4/letter/a/b487fb/32.png) [@abhi](https://community.particle.io/u/abhi)\
**Post date:** [July 11, 2015, 10:24pm UTC](https://community.particle.io/t/function-digitalwrite-not-found-when-rest-api-solved/12075/10 "2015-07-11T22:24:07Z")

</div>

Thanks @ScruffR yes I did. digital write or the other functions all return the same error

If I just want a list of devices, that works. What else do I need to do?

---

<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:** [July 11, 2015, 11:03pm UTC](https://community.particle.io/t/function-digitalwrite-not-found-when-rest-api-solved/12075/11 "2015-07-11T23:03:15Z")

</div>

Just to make sure that your code is okay, could you check on [this](http://jordymoors.nl/interface) page which functions are available, and if you’re able to trigger them?

---

<div class="post-metadata">

**Author:** ![abhi](https://avatars.discourse-cdn.com/v4/letter/a/b487fb/32.png) [@abhi](https://community.particle.io/u/abhi)\
**Post date:** [July 12, 2015, 4:50pm UTC](https://community.particle.io/t/function-digitalwrite-not-found-when-rest-api-solved/12075/12 "2015-07-12T16:50:47Z")

</div>

Thanks @Moors7. Yes, I’m able to see my device listed. When I clicked on the events, I can see a set of events…

event: spark/status  
data: {“data”:“online”,“ttl”:“60”,“published\_at”:“2015-07-12T16:45:07.661Z”,“coreid”:"{deviceID}"}

## event: spark/cc3000-patch-version data: {“data”:“null”,“ttl”:“60”,“published\_at”:“2015-07-12T16:45:07.759Z”,“coreid”:"{deviceID"}

This works - [https://api.spark.io/v1/devices/{deviceID}?access\_token={access\_token}](https://api.spark.io/v1/devices/%7BdeviceID%7D?access_token=%7Baccess_token%7D)

This doesnt - [https://api.spark.io/v1/devices/{deviceID}/digitalwrite?access\_token={access\_token}&params=D0,HIGH](https://api.spark.io/v1/devices/%7BdeviceID%7D/digitalwrite?access_token=%7Baccess_token%7D&params=D0,HIGH).

It returns

{  
“ok”: false,  
“error”: “Variable not found”  
}

btw, it takes a while to get the event stream. you should check out [www.zettajs.org](http://www.zettajs.org) for an instant access to web socket data stream.

---

<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:** [July 12, 2015, 5:40pm UTC](https://community.particle.io/t/function-digitalwrite-not-found-when-rest-api-solved/12075/13 "2015-07-12T17:40:32Z")

</div>

> [@abhi](#):
>
> Yes, I'm able to see my device listed.

But, did it show the functions you were looking for, `digitalwrite`, and if so, were you able to call them successfully using that page? The events are irrelevant for functions/variables.  
I'm not familiar with zettajs, but it appears to already support the Particle ecosystem, so there's no reason you shouldn't be able to use that, should you so desire.

> [@abhi](#):
>
> This doesnt - [https://api.spark.io/v1/devices/{deviceID}/digitalwrite?access\_token={access\_token}&params=D0,HIGH](https://api.spark.io/v1/devices/%7BdeviceID%7D/digitalwrite?access_token=%7Baccess_token%7D&params=D0,HIGH).

Where did you try that, in a browser? Since a function call requires a POST request, that won't work, considering a browser makes GET request.

---

<div class="post-metadata">

**Author:** ![abhi](https://avatars.discourse-cdn.com/v4/letter/a/b487fb/32.png) [@abhi](https://community.particle.io/u/abhi)\
**Post date:** [July 13, 2015, 12:21am UTC](https://community.particle.io/t/function-digitalwrite-not-found-when-rest-api-solved/12075/14 "2015-07-13T00:21:51Z")

</div>

Thanks @Moors7. On ur site, I only see my photon - don’t see any functions.

I tried the API in browser and Postman. Neither worked

---

<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 13, 2015, 7:41am UTC](https://community.particle.io/t/function-digitalwrite-not-found-when-rest-api-solved/12075/15 "2015-07-13T07:41:51Z")

</div>

> [@abhi](#):
>
> On ur site, I only see my photon - don't see any functions.

Then it is quite likely that you've got some firmware running on your device that doesn't expose any `Spark.function` or `Spark.variable`.  
If you want to call `digitalwrite` you either have to reflash Tinker firmware, or flash your own firmware which exposes such a function, or do a factory reset, which also reverts back to Tinker.
