> For the complete documentation index, see [llms.txt](https://docs.astronomyapi.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.astronomyapi.com/endpoints/studio/moon-phase.md).

# Moon Phase

If you're looking to quickly integrate this feature on your website without making API calls, checkout [Widgets](/widgets.md)

## Generate Moon Phase

<mark style="color:green;">`POST`</mark> `https://api.astronomyapi.com/api/v2/studio/moon-phase`

#### Headers

| Name                                            | Type   | Description   |
| ----------------------------------------------- | ------ | ------------- |
| Authorization<mark style="color:red;">\*</mark> | string | Basic \<hash> |

#### Request Body

| Name                                       | Type   | Description                                                                                                                                                                                                                                                                                                                                                                |
| ------------------------------------------ | ------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| format                                     | string | Image format to be returned. Valid values are `png` or `svg`. Defaults to `png`                                                                                                                                                                                                                                                                                            |
| style                                      | object | Style object contains the styling parameters for the image generated.                                                                                                                                                                                                                                                                                                      |
| observer<mark style="color:red;">\*</mark> | object | Observer object must contain the `latitude`, `longitude` and `date` of the observer.                                                                                                                                                                                                                                                                                       |
| view<mark style="color:red;">\*</mark>     | object | <p>View object is used to configure the view of the rendered image. The view object must contain a <code>type</code> object. </p><p></p><p><code>orientation</code> specifies which side of the moon should be up depending on the hemisphere you live in the world. This parameter is optional. If not provided AstronomyAPI will determine the values automatically.</p> |

{% tabs %}
{% tab title="200: OK " %}

```typescript
{
    "data": {
        "imageUrl": "https://widgets.astronomyapi.com/moon-phase/generated/1234567890.png"
    }
}
```

{% endtab %}
{% endtabs %}

```typescript
{
    "format": "png",
    "style": {
        "moonStyle": "sketch",
        "backgroundStyle": "stars",
        "backgroundColor": "red",
        "headingColor": "white",
        "textColor": "red"
    },
    "observer": {
        "latitude": 6.56774,
        "longitude": 79.88956,
        "date": "2020-11-01"
    },
    "view": {
        "type": "portrait-simple",
        "orientation": "south-up"
    }
}
```

## Format

The API currently supports outputting images in `svg` and `png` formats. These can be used in different use cases, depending on how and where you want them to be displayed.&#x20;

## Style

#### `moonStyle`

Valid values are `default`, `sketch` and `shaded.` Below are sample moons for each value.

<div align="left"><img src="/files/-MLMfuVXwb-nvqU5Gd3F" alt="default"></div>

<div align="left"><img src="/files/-MLMfxkLOrFj75Y6WLqR" alt="shaded"></div>

<div align="left"><img src="/files/-MLMg2GgWznHGk4LErJE" alt="sketch"></div>

#### `backgroundStyle`

Background style supports the values either `stars` or `solid`. Passing `stars` will render a stars background while `solid` will render the background with a solid color specified by the `backgroundColor` property.

#### `backgroundColor, headingColor and textColor`

These properties could be used to customise the image further. Colours could be defined as hex or as any of the [140 html colour names](https://www.w3schools.com/tags/ref_colornames.asp).

## View

#### `type`

The type parameter in the view object should specify which template to be used when rendering the image. Currently two templates are available.

<div align="left"><img src="/files/-MLMjeSRNBAehVN5Cx6W" alt="portrait-simple"></div>

<div align="left"><img src="/files/-MLMjiu-yLVApMbCY5pg" alt="landscape-simple"></div>

#### `orientation`

Orientation parameter in the view object, determines which orientation to use when rendering the moon. By default it will render north side up, as seen by an observer facing the south side of the sky. This parameter is optional.

Below is an example of the same image with different orientations.

<div align="left"><img src="/files/Tyh0o7gjZI801tktKixQ" alt="north-up"></div>

<div align="left"><img src="/files/wiPlfrpO5kjiko2ArMHk" alt="south-up"></div>
