### Authentication - Validate Credentials Source: https://context7.com/astronomyapi/samples/llms.txt This example demonstrates how to validate API credentials using Basic Authentication by making a GET request to the /api/v2/bodies endpoint. It uses JavaScript with Axios to send the request and logs the response or error. ```APIDOC ## GET /api/v2/bodies ### Description Validates API credentials by checking if the application can access the list of supported celestial bodies. ### Method GET ### Endpoint https://api.astronomyapi.com/api/v2/bodies ### Parameters #### Headers - **Authorization** (string) - Required - Basic Auth header formatted as `Basic ` - **X-Requested-With** (string) - Required - Set to `XMLHttpRequest` ### Request Example ```javascript import axios from "axios"; const appId = "your_app_id"; const appSecret = "your_app_secret"; const apiEndpoint = "https://api.astronomyapi.com"; axios .get(`${apiEndpoint}/api/v2/bodies`, { headers: { "X-Requested-With": "XMLHttpRequest", Authorization: `Basic ${btoa(`${appId}:${appSecret}`)}`, }, }) .then((response) => { console.log("Credentials valid", response.data); }) .catch((e) => { console.error("Credential validation failed", e.response?.status); }); ``` ### Response #### Success Response (200) - **data** (object) - Contains a list of supported celestial bodies. #### Response Example ```json { "data": { "bodies": [ // ... list of celestial bodies ] } } ``` ``` -------------------------------- ### Get Planetary Positions with Axios Source: https://context7.com/astronomyapi/samples/llms.txt Retrieve celestial body positions (equatorial and horizontal coordinates) for a specified location and date range. This example uses Axios and Moment.js for date formatting. Adjust longitude, latitude, elevation, and date parameters as needed. ```javascript import axios from "axios"; import moment from "moment"; const appId = "your_app_id"; const appSecret = "your_app_secret"; const apiEndpoint = "https://api.astronomyapi.com"; const params = { longitude: "-84.39733", latitude: "33.775867", elevation: 1, from_date: moment().format("YYYY-MM-DD"), // e.g. "2024-06-01" to_date: moment().add(2, "days").format("YYYY-MM-DD"), time: moment().format("HH:mm:ss"), // e.g. "12:00:00" }; const headers = { "X-Requested-With": "XMLHttpRequest", Authorization: `Basic ${btoa(`${appId}:${appSecret}`)}`, }; axios.get(`${apiEndpoint}/api/v2/bodies/positions`, { params, headers }) .then((response) => { const table = response.data.data.table; // table.header → ["2024-06-01", "2024-06-02", "2024-06-03"] // table.rows → array of body rows table.rows.forEach((row) => { console.log(row.entry.name); // "Sun", "Moon", "Mars", etc. row.cells.forEach((cell) => { const eq = cell.position.equatorial; const hor = cell.position.horizonal; console.log( ` RA: ${eq.rightAscension.string}`, ` Dec: ${decodeURIComponent(eq.declination.string)}`, ` Alt: ${decodeURIComponent(hor.altitude.string)}`, ` Az: ${decodeURIComponent(hor.azimuth.string)}`, ); }); }); }) .catch((e) => console.error("Positions error:", e.response?.data)); ``` -------------------------------- ### Validate Credentials with Axios Source: https://context7.com/astronomyapi/samples/llms.txt Use this snippet to validate your Astronomy API credentials by making a GET request to the /api/v2/bodies endpoint. Ensure you have Axios installed and replace placeholders with your actual application ID and secret. ```javascript import axios from "axios"; const appId = "your_app_id"; const appSecret = "your_app_secret"; const apiEndpoint = "https://api.astronomyapi.com"; axios .get(`${apiEndpoint}/api/v2/bodies`, { headers: { "X-Requested-With": "XMLHttpRequest", Authorization: `Basic ${btoa(`${appId}:${appSecret}`)}`, }, }) .then((response) => { console.log("Credentials valid", response.data); // response.data.data contains a list of supported celestial bodies }) .catch((e) => { console.error("Credential validation failed", e.response?.status); }); ``` -------------------------------- ### GET /api/v2/bodies/positions - Planetary Positions Source: https://context7.com/astronomyapi/samples/llms.txt Retrieves a dataset of celestial body positions, including equatorial and horizontal coordinates, for a specified observer location, date range, and time. Supports various coordinate systems. ```APIDOC ## GET /api/v2/bodies/positions ### Description Returns a tabular dataset of celestial body positions (equatorial and horizontal coordinates) for an observer at a given location, over a date range and at a specific time. Supports equatorial (RA/Dec) and horizontal (altitude/azimuth) coordinate systems. ### Method GET ### Endpoint https://api.astronomyapi.com/api/v2/bodies/positions ### Parameters #### Query Parameters - **longitude** (string) - Required - The observer's longitude. - **latitude** (string) - Required - The observer's latitude. - **elevation** (number) - Optional - The observer's elevation in meters. - **from_date** (string) - Required - The start date for the position data in `YYYY-MM-DD` format. - **to_date** (string) - Required - The end date for the position data in `YYYY-MM-DD` format. - **time** (string) - Required - The time of observation in `HH:mm:ss` format. #### Headers - **Authorization** (string) - Required - Basic Auth header formatted as `Basic ` - **X-Requested-With** (string) - Required - Set to `XMLHttpRequest` ### Request Example ```javascript import axios from "axios"; import moment from "moment"; const appId = "your_app_id"; const appSecret = "your_app_secret"; const apiEndpoint = "https://api.astronomyapi.com"; const params = { longitude: "-84.39733", latitude: "33.775867", elevation: 1, from_date: moment().format("YYYY-MM-DD"), to_date: moment().add(2, "days").format("YYYY-MM-DD"), time: moment().format("HH:mm:ss"), }; const headers = { "X-Requested-With": "XMLHttpRequest", Authorization: `Basic ${btoa(`${appId}:${appSecret}`)}`, }; axios.get(`${apiEndpoint}/api/v2/bodies/positions`, { params, headers }) .then((response) => { const table = response.data.data.table; table.rows.forEach((row) => { console.log(row.entry.name); row.cells.forEach((cell) => { const eq = cell.position.equatorial; const hor = cell.position.horizonal; console.log( ` RA: ${eq.rightAscension.string}`, ` Dec: ${decodeURIComponent(eq.declination.string)}`, ` Alt: ${decodeURIComponent(hor.altitude.string)}`, ` Az: ${decodeURIComponent(hor.azimuth.string)}`, ); }); }); }) .catch((e) => console.error("Positions error:", e.response?.data)); ``` ### Response #### Success Response (200) - **data** (object) - Contains the celestial body positions in a tabular format. - **data.table** (object) - **data.table.header** (array) - Array of dates for the columns. - **data.table.rows** (array) - Array of celestial body data rows. - **data.table.rows[].entry** (object) - Information about the celestial body. - **data.table.rows[].entry.name** (string) - The name of the celestial body. - **data.table.rows[].cells** (array) - Position data for each date. - **data.table.rows[].cells[].position** (object) - **data.table.rows[].cells[].position.equatorial** (object) - Equatorial coordinates. - **data.table.rows[].cells[].position.equatorial.rightAscension** (object) - **data.table.rows[].cells[].position.equatorial.rightAscension.string** (string) - Right Ascension in string format. - **data.table.rows[].cells[].position.equatorial.declination** (object) - **data.table.rows[].cells[].position.equatorial.declination.string** (string) - Declination in string format. - **data.table.rows[].cells[].position.horizonal** (object) - Horizontal coordinates. - **data.table.rows[].cells[].position.horizonal.altitude** (object) - **data.table.rows[].cells[].position.horizonal.altitude.string** (string) - Altitude in string format. - **data.table.rows[].cells[].position.horizonal.azimuth** (object) - **data.table.rows[].cells[].position.horizonal.azimuth.string** (string) - Azimuth in string format. #### Response Example ```json { "data": { "table": { "header": ["2024-06-01", "2024-06-02", "2024-06-03"], "rows": [ { "entry": {"name": "Sun"}, "cells": [ { "position": { "equatorial": {"rightAscension": {"string": "..."}, "declination": {"string": "..."}}, "horizonal": {"altitude": {"string": "..."}, "azimuth": {"string": "..."}} } }, // ... more cells ] }, // ... more rows ] } } } ``` ``` -------------------------------- ### Set Basic Auth Key Environment Variable Source: https://github.com/astronomyapi/samples/blob/master/curl/README.md Set your generated Basic authentication key as an environment variable. This is required for authenticating API requests. ```sh export BASIC_AUTH_KEY= ``` -------------------------------- ### Generate Star Chart Image (cURL) Source: https://context7.com/astronomyapi/samples/llms.txt This cURL command demonstrates how to generate a star chart image for a specific constellation using the API. It requires setting up a BASIC_AUTH_KEY environment variable. ```bash export BASIC_AUTH_KEY="" curl --location --request POST 'https://api.astronomyapi.com/api/v2/studio/star-chart' \ --header 'Content-Type: application/json' \ --header "Authorization: Basic ${BASIC_AUTH_KEY}" \ --data '{ \ "observer": { \ "date": "2022-02-01", \ "latitude": -22.05546, \ "longitude": 54.36588 \ }, \ "style": "red", \ "view": { \ "parameters": { "constellation": "tau" }, \ "type": "constellation" \ } \ }' ``` -------------------------------- ### Generate Moon Phase Script Source: https://github.com/astronomyapi/samples/blob/master/curl/README.md Execute the provided shell script to generate moon phase data. Remember to change the parameters within the script as needed. ```sh sh generate-moon-phase.sh ``` -------------------------------- ### Generate Star Chart Image (Constellation View) Source: https://context7.com/astronomyapi/samples/llms.txt Use this snippet to generate a PNG image of a star chart for a specific constellation. Requires observer location and date. The 'inverted' style is used here. ```javascript // StarChart.vue — generate() import axios from "axios"; import moment from "moment"; const appId = "your_app_id"; const appSecret = "your_app_secret"; const apiEndpoint = "https://api.astronomyapi.com"; // --- Constellation view --- const constellationPayload = { style: "inverted", observer: { latitude: 33.775867, longitude: -84.39733, date: moment().format("YYYY-MM-DD"), }, view: { type: "constellation", parameters: { constellation: "ori" }, // Orion }, }; const headers = { "X-Requested-With": "XMLHttpRequest", Authorization: `Basic ${btoa(`${appId}:${appSecret}`)}`, }; axios.post(`${apiEndpoint}/api/v2/studio/star-chart`, constellationPayload, { headers }) .then((response) => { const imageUrl = response.data.data.imageUrl; console.log("Star chart URL:", imageUrl); // Render: }) .catch((e) => console.error("Star chart error:", e.response?.data)); ``` -------------------------------- ### Generate Moon Phase Image Source: https://context7.com/astronomyapi/samples/llms.txt Generates a styled moon phase image for an observer location and date. Offers `portrait-simple` and `landscape-simple` view types, moon styles (`default`, `sketch`, `shaded`), and fully customisable background/heading/text colours. ```APIDOC ## POST /api/v2/studio/moon-phase — Moon Phase Image ### Description Generates a styled moon phase image for an observer location and date. Offers `portrait-simple` and `landscape-simple` view types, moon styles (`default`, `sketch`, `shaded`), and fully customisable background/heading/text colours. ### Method POST ### Endpoint /api/v2/studio/moon-phase ### Request Body - **style** (object) - Optional - Styling options for the moon phase image. - **moonStyle** (string) - Optional - The style of the moon (`default`, `sketch`, `shaded`). - **backgroundStyle** (string) - Optional - The background style (`stars`, `solid`). - **backgroundColor** (string) - Optional - The background color in hex format (e.g., `#000000`). - **headingColor** (string) - Optional - The heading color in hex format. - **textColor** (string) - Optional - The text color in hex format. - **observer** (object) - Required - Observer's location and date. - **latitude** (number) - Required - Observer's latitude. - **longitude** (number) - Required - Observer's longitude. - **date** (string) - Required - The date for the moon phase in YYYY-MM-DD format. - **view** (object) - Required - The type of view to render. - **type** (string) - Required - The type of view (`portrait-simple` or `landscape-simple`). - **parameters** (object) - Required - Parameters specific to the view type (currently empty). ### Request Example ```json { "style": { "moonStyle": "shaded", "backgroundStyle": "stars", "backgroundColor": "#000000", "headingColor": "#ffffff", "textColor": "#ffffff" }, "observer": { "latitude": 33.775867, "longitude": -84.39733, "date": "2024-06-15" }, "view": { "type": "portrait-simple", "parameters": {} } } ``` ### Response #### Success Response (200) - **data** (object) - Contains the generated image URL. - **imageUrl** (string) - The URL of the generated moon phase image. ``` -------------------------------- ### Generate Star Chart Image Source: https://context7.com/astronomyapi/samples/llms.txt Generates a styled star chart PNG for a given observer location and date. Supports two view types: `constellation` and `area`. Available styles are `default`, `inverted`, `navy`, and `red`. ```APIDOC ## POST /api/v2/studio/star-chart — Star Chart Image ### Description Generates a styled star chart PNG for a given observer location and date. Supports two view types: `constellation` (renders a named constellation) and `area` (renders a custom sky area by RA/Dec/zoom). Available styles are `default`, `inverted`, `navy`, and `red`. ### Method POST ### Endpoint /api/v2/studio/star-chart ### Request Body - **style** (string) - Required - The visual style of the star chart (e.g., `default`, `inverted`, `navy`, `red`). - **observer** (object) - Required - Observer's location and date. - **latitude** (number) - Required - Observer's latitude. - **longitude** (number) - Required - Observer's longitude. - **date** (string) - Required - The date for the star chart in YYYY-MM-DD format. - **view** (object) - Required - The type of view to render. - **type** (string) - Required - The type of view (`constellation` or `area`). - **parameters** (object) - Required - Parameters specific to the view type. - **constellation** (string) - Required if type is `constellation` - The name or identifier of the constellation (e.g., `ori` for Orion). - **position** (object) - Required if type is `area` - The position of the sky area. - **equatorial** (object) - Required if type is `area` - Equatorial coordinates. - **rightAscension** (number) - Required - Right Ascension value. - **declination** (number) - Required - Declination value. - **zoom** (number) - Optional - The zoom level for the `area` view. ### Request Example ```json { "style": "inverted", "observer": { "latitude": 33.775867, "longitude": -84.39733, "date": "2024-01-01" }, "view": { "type": "constellation", "parameters": { "constellation": "ori" } } } ``` ### Response #### Success Response (200) - **data** (object) - Contains the generated image URL. - **imageUrl** (string) - The URL of the generated star chart image. ``` -------------------------------- ### Generate API Snippets with HTTPSnippet Source: https://context7.com/astronomyapi/samples/llms.txt This mixin converts API requests into code snippets for various languages. It requires a store to manage state and uses HTTPSnippet for conversion. ```javascript // mixins.js — setSnippetData() and generateSnippet() import { HTTPSnippet } from "httpsnippet"; import { store } from "./store.js"; // Called by each component right before the axios call: function setSnippetData(method, url, data, headers) { // Build HTTPSnippet-compatible HAR-like request object store.snippet = { method, url, // GET → query string, POST → body text queryString: method === "GET" ? objectToArray(data) : undefined, postData: method === "POST" ? { text: JSON.stringify(data) } : undefined, headers: objectToArray(headers), }; generateSnippet(); } function objectToArray(obj) { return Object.keys(obj) .filter((k) => k !== "X-Requested-With") .map((k) => ({ name: k, value: obj[k] ? obj[k].toString() : "" })); } function generateSnippet() { const snippet = new HTTPSnippet(store.snippet); // store.language is set by the in CodeView.vue store.request = snippet.convert(store.language); // store.request is then displayed in the Request panel } // Example: switching language at runtime store.language = "python"; generateSnippet(); // store.request now contains a Python requests snippet ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.