# Rest api - able to get propertys of web things but not to set

**URL:** <https://discourse.mozilla.org/t/rest-api-able-to-get-propertys-of-web-things-but-not-to-set/42968>\
**Category:** WebThings\
**Created:** [July 24, 2019, 8:03am UTC](https://discourse.mozilla.org/t/rest-api-able-to-get-propertys-of-web-things-but-not-to-set/42968 "2019-07-24T08:03:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![negrival](https://avatars.discourse-cdn.com/v4/letter/n/f07891/32.png) [@negrival](https://discourse.mozilla.org/u/negrival)\
**Post date:** [July 24, 2019, 8:03am UTC](https://discourse.mozilla.org/t/rest-api-able-to-get-propertys-of-web-things-but-not-to-set/42968/1 "2019-07-24T08:03:43Z")

</div>

I would like to control web things from a web page.  
I’m able to get property this is my code:  
var url = “https://\*\*\*.mozilla-iot.org/things/gpio-20/properties/on”;  
try {  
var mzreq = new XMLHttpRequest();  
mzreq .open(“GET”, url, false);  
mzreq .setRequestHeader(‘Accept’, ‘application/json’);  
mzreq .setRequestHeader(‘Authorization’, ‘Bearer eyJ…’);  
mzreq .onreadystatechange = function () {  
if (mzreq .readyState === 4) {  
if (mzreq .status === 200 || mzreq .status == 0) {  
var allText = mzreq .responseText;  
alert(allText);  
}  
}  
}  
mzreq .send(null);  
}  
catch (err) {  
alert(err);  
}

but i’m not able to set property value:  
var url = “https://\*\*\*.mozilla-iot.org/things/gpio-20/properties/on”;  
try {  
var mzreq = new XMLHttpRequest();  
mzreq .open(“PUT”, file, true);  
mzreq .setRequestHeader(‘Accept’, ‘application/json’);  
mzreq .setRequestHeader(‘Authorization’, ‘Bearer eyJ…’);  
mzreq .onreadystatechange = function () {  
if (mzreq .readyState === 4) {  
if (mzreq .status === 200 || mzreq .status == 0) {  
var allText = mzreq .responseText;  
alert(allText);  
}  
}  
}  
mzreq .send(’{ “on”: true }’);  
}  
catch (err) {  
alert(err);  
}

I get response 400.

P.S.:  
I have installed gateway manually from github, not from pre-built image.

---

<div class="post-metadata">

**Author:** ![hobinjk](https://avatars.discourse-cdn.com/v4/letter/h/4af34b/32.png) [@hobinjk](https://discourse.mozilla.org/u/hobinjk)\
**Post date:** [July 24, 2019, 1:50pm UTC](https://discourse.mozilla.org/t/rest-api-able-to-get-propertys-of-web-things-but-not-to-set/42968/2 "2019-07-24T13:50:35Z")

</div>

I believe the bug here is that you need to set the PUT XMLHttpRequest’s ‘Content-Type’ header to ‘application/json’

---

<div class="post-metadata">

**Author:** ![negrival](https://avatars.discourse-cdn.com/v4/letter/n/f07891/32.png) [@negrival](https://discourse.mozilla.org/u/negrival)\
**Post date:** [July 24, 2019, 4:58pm UTC](https://discourse.mozilla.org/t/rest-api-able-to-get-propertys-of-web-things-but-not-to-set/42968/3 "2019-07-24T16:58:49Z")

</div>

Thank you James, now it work.  
Another question:  
How can I control things on local network?  
I have test [https://ip:4443](https://ip:4443), it work via browser but not with XMLHttpRequest

---

<div class="post-metadata">

**Author:** ![TechPhoenix](https://avatars.discourse-cdn.com/v4/letter/t/b4bc9f/32.png) [@TechPhoenix](https://discourse.mozilla.org/u/TechPhoenix)\
**Post date:** [November 6, 2019, 11:59am UTC](https://discourse.mozilla.org/t/rest-api-able-to-get-propertys-of-web-things-but-not-to-set/42968/4 "2019-11-06T11:59:35Z")

</div>

Man, you saved my day ^^ It took me 3 Hours to figure this out. Thank you so much.
