# Post XML to website using Homeyscript

**URL:** <https://community.homey.app/t/post-xml-to-website-using-homeyscript/57254>\
**Category:** Questions & Help\
**Tags:** homeyscript\
**Created:** [December 26, 2021, 9:06pm UTC](https://community.homey.app/t/post-xml-to-website-using-homeyscript/57254 "2021-12-26T21:06:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![opstad](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/opstad/32/49391_2.png) [@opstad](https://community.homey.app/u/opstad)\
**Post date:** [December 26, 2021, 9:06pm UTC](https://community.homey.app/t/post-xml-to-website-using-homeyscript/57254/1 "2021-12-26T21:06:33Z")

</div>

How do i send 6 lines of XML to an open local website using POST using Homeyscript?

---

<div class="post-metadata">

**Author:** ![Peter\_Kawa](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/peter_kawa/32/173848_2.png) [@Peter\_Kawa](https://community.homey.app/u/Peter_Kawa)\
**Post date:** [December 26, 2021, 10:27pm UTC](https://community.homey.app/t/post-xml-to-website-using-homeyscript/57254/2 "2021-12-26T22:27:34Z")

</div>

Maybe this script gets you some ideas:

> [@HTTP Request Flow with username/password](https://community.homey.app/t/http-request-flow-with-username-password/51210/3):
>
> var token\_ // variable will store the token  
> var userName = “clientID”; // app clientID  
> var passWord = “secretKey”; // app clientSecret  
> var caspioTokenUrl = “[https://xxx123.caspio.com/oauth/token”](https://xxx123.caspio.com/oauth/token%E2%80%9D); // Your application token endpoint  
> var request = new XMLHttpRequest();
> 
> function getToken(url, clientID, clientSecret) {  
> var key;  
> request.open(“POST”, url, true);  
> request.setRequestHeader(“Content-type”, “application/json”);  
> request.send(“grant\_type=client\_credentials&client\_id=”+clientID+“&”+“client\_secret=”+clientSecret); // specify the credentials to receive the token on request  
> request.onreadystatechange = function () {  
> if (request.readyState == request.DONE) {  
> var response = request.responseText;  
> var obj = JSON.parse(response);  
> key = obj.access\_token; //store the value of the accesstoken  
> token\_ = key; // store token in your global variable “token\_” or you could simply return the value of the access token from the function  
> }  
> }  
> }  
> // Get the token  
> getToken(caspioTokenUrl, userName, passWordz);

Not script, but it might come in handy:  
just a few ideas using flow cards

> [@POST HTTP request not working](https://community.homey.app/t/post-http-request-not-working/21464/6):
>
> Thx all for your help. I found a different command which works. I am using the „logic web request“ command instead of http request. Code structure is same as used in iOS Shortcuts. See screenshot below.

> [@POST HTTP request not working](https://community.homey.app/t/post-http-request-not-working/21464/10):
>
> Then i am to late to help you, but anyway here how is working with the http app from Erik: [image]

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [December 27, 2021, 6:59am UTC](https://community.homey.app/t/post-xml-to-website-using-homeyscript/57254/3 "2021-12-27T06:59:57Z")

</div>

Something like this:

```auto
const url = 'http://AA.BB.CC.DD:PP';
const xml = `\
<?xml version="1.0" encoding="UTF-8" ?>
<records>
	<record>
		<name>Alfreda Roach</name>
		<phone>(522) 884-2158</phone>
		<email>luctus.et@yahoo.ca</email>
		<address>230-6265 Aliquet, Rd.</address>
		<postalZip>361179</postalZip>
		<region>Huntingdonshire</region>
		<country>Chile</country>
	</record>
</records>
`;

await fetch(url, {
  method: 'post',
  headers: {
    'content-type' : 'text/xml',
    'content-length': xml.length,
  },
  body: xml
});

```
