Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I can't get the Moon Phase data because of CORS policy #117

Open
fatcat529 opened this issue Nov 12, 2024 · 1 comment
Open

I can't get the Moon Phase data because of CORS policy #117

fatcat529 opened this issue Nov 12, 2024 · 1 comment

Comments

@fatcat529
Copy link

Please use this template to ask your question so I can answer you better

Description of the issue

I created a application in Astronomy and set the origin as https://market-performace.fatcat529.com.

What did you try and what didn't work

I tried to do it on several api test tools such as Postman but it also doesn't work well.

Example code (if applicable)

const authHeader = btoa(
${process.env.NEXT_PUBLIC_ASTRONOMY_APPLICATION_ID}:${process.env.NEXT_PUBLIC_ASTRONOMY_APPLICATION_SECRET}
);

const response = await fetch(
"https://api.astronomyapi.com/api/v2/studio/moon-phase",
{
method: "GET",
headers: {
"X-Requested-With": "XMLHttpRequest",
Authorization: Basic ${authHeader},
},
}
);

Application ID (this will help trace the logs to see what went wrong)

NEXT_PUBLIC_ASTRONOMY_APPLICATION_ID = 63cb8a55-5349-4e5c-9a76-835059d3f8bb

@astroanu
Copy link
Member

You also need to pass a json payload in your fetch request body.

See https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#setting_a_body on how to set a body. Also the method should be POST not GET.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants