# \[Script\] Moon-phase appi form Rapid in .js script have some problems

**URL:** <https://community.homey.app/t/script-moon-phase-appi-form-rapid-in-js-script-have-some-problems/129104>\
**Category:** Questions & Help\
**Created:** [January 28, 2025, 11:58am UTC](https://community.homey.app/t/script-moon-phase-appi-form-rapid-in-js-script-have-some-problems/129104 "2025-01-28T11:58:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Theo\_de\_Koning](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/theo_de_koning/32/136062_2.png) [@Theo\_de\_Koning](https://community.homey.app/u/Theo_de_Koning)\
**Post date:** [January 28, 2025, 11:58am UTC](https://community.homey.app/t/script-moon-phase-appi-form-rapid-in-js-script-have-some-problems/129104/1 "2025-01-28T11:58:05Z")

</div>

To get the JSON file of the moon data it seem to me that it cant by the Logic Get card.

What I found was a .js script but there are some difficulties for Homey-script.

```auto
 1 const fetchMoonPhaseData = async () =&gt; {
 2 try {
 3 const response = await fetch("https://moon-phase.p.rapidapi.com/advanced", {
 4 "method": "GET",
 5 "headers": {
 6 "x-rapidapi-host": "moon-phase.p.rapidapi.com",
 7 "x-rapidapi-key": "xxxxxxxxx"
 8 }
 9 });
10
11 if (!response.ok) {
12 throw new Error(`HTTP error ${response.status}`);
13 }
14
15 const data = await response.json();
16 displayMoonPhase(data.phase_name);
17 } catch (error) {
18 console.error("Error fetching data:", error);
19 displayMoonPhase("Error fetching moon phase data");
20 }
21 };
22
23 const displayMoonPhase = (text) =&gt; {
24 const phaseTextElement = document.getElementById("phase-text");
25 phaseTextElement.innerText = text;
26 };
27
28 fetchMoonPhaseData();
29
30 // await tag('Moon data' , ?);

```

Line 30 is put by me for later getting the data out but how I don’t no jet.  
The line numbers I put here myself so the lining is not correct.

In lines 1 and 23 the 1st error: =&gt. Changed in =\>  
Then the “;” in between the “=\>” and “{” gives the next error.

Delete that “,” like a normal reaction but I’m tricky about it and don’t want to make problems on the api provider.

Further if some one can make it still working with the Logic Get card I prefer that.

---

<div class="post-metadata">

**Author:** ![Theo\_de\_Koning](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/theo_de_koning/32/136062_2.png) [@Theo\_de\_Koning](https://community.homey.app/u/Theo_de_Koning)\
**Post date:** [January 29, 2025, 9:29am UTC](https://community.homey.app/t/script-moon-phase-appi-form-rapid-in-js-script-have-some-problems/129104/2 "2025-01-29T09:29:42Z")

</div>

At last I have that “;” deleted.

Outcome:  
`  
✅ Script Success  
↩ Returned: undefined

Error fetching data: ReferenceError: document is not defined  
at displayMoonPhase (Moon data.js:24:30)  
at fetchMoonPhaseData (Moon data.js:16:9)  
at process.processTicksAndRejections (node:internal/process/task\_queues:95:5)`

In line 23: const displayMoonPhase = (text) =\> {  
**3 dots** under the 1st t of (text).

So I’m stuck again.

**EDIT**

Looking in my account I see that de data is going without error.  
How to get them visible is still not happening.  
Lines 22 - 29 are in remark.  
Added this:

```auto
// await tag('Moon data' , ?);
console.log();
return(true);

```

This file seem to me part of an other program.  
Looking to names with no var/const/let in front.

But the in line 3 _const response_ I cant put it in the _console.log(response)_  
———————————————————  
❌ Script Error

⚠ ReferenceError: response is not defined  
at Moon data.js:41:13  
at process.processTicksAndRejections (node:internal/process/task\_queues:95:5)

No idea for now to go further.

---

<div class="post-metadata">

**Author:** ![Theo\_de\_Koning](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/theo_de_koning/32/136062_2.png) [@Theo\_de\_Koning](https://community.homey.app/u/Theo_de_Koning)\
**Post date:** [January 29, 2025, 5:55pm UTC](https://community.homey.app/t/script-moon-phase-appi-form-rapid-in-js-script-have-some-problems/129104/3 "2025-01-29T17:55:35Z")

</div>

### And Now for Something Completely Different

* * *

After dinner, 1 + 1 came together and I fount in my account an other possibility.  
JavaScript with fetch. The above turned out to be for XMLHttpRequest

The only problem was the place of _await tag(‘Moondata’,result);_ .  
That had to be what higher in the lines then what I thought.

```auto
const url = 'https://moon-phase.p.rapidapi.com/advanced?lat=51.4768&lon=-0.0004';
const options = {
	method: 'GET',
	headers: {
		'x-rapidapi-key': 'xyx',
		'x-rapidapi-host': 'moon-phase.p.rapidapi.com'
	}
};

try {
	const response = await fetch(url, options);
	const result = await response.text();
	console.log(result);
	await tag('Moondata',result);
} catch (error) {
	console.error(error);
}
return(true);

```
