{"openapi":"3.0.0","info":{"title":"DTN Astronomical API","version":"2.0.0","x-logo":{"url":"https://www.dtn.com/wp-content/uploads/2019/03/dtn-logo-tag.png","altText":"https://www.dtn.com"},"description":"# Introduction\nWelcome to DTN's Astronomical API - the comprehensive source for Sun and Moon-based data. This API offers precise information concerning the Sun's position in the sky, encompassing both rising and setting times, as well as Moon phases for any location on Earth.\n\nThe Astronomical API is an ideal solution for various application types, including weather, astronomical, calendar, outdoor activity, photography (e.g., golden hour tracking), and navigation applications, among others.\n\nWhether you are a hobbyist developer with an interest in astronomical phenomena or a professional software engineer seeking to enhance user experiences in your applications, this API delivers dependable and accurate data to meet your specific requirements.\n\nThe interactive documentation that follows is a guide to setting up requests, understanding responses, and leveraging all the features of DTN’s Astronomical API.\n# Getting Started\n## Obtaining credentials\nTo get started, all users need their own client ID and client secret. Please contact an account manager or the [DTN sales team](https://www.dtn.com/contact-us/) to obtain these. Then, review the `Authentication` section to learn how to request an API access token. Do not share or use others' API credentials, since doing so may compromise information security.\n\n## Making requests\nThere are multiple ways to make an initial API request:\n\n**1. Interactive documentation:** Navigate to the `Authentication` section on this page, insert credentials to obtain an access token, then explore the API endpoints described in the `Endpoints` section.\n\n**2. Postman collection:** For a hands-on approach, consider downloading the Postman collection from the top of this page. Insert credentials and start testing the API in Postman's interactive application.\n\n**3. Writing code:** Ready to start coding? Try the Python example below, replacing `client_id` and `client_secret` with proper credentials. This invokes the API endpoint with a GET request and prints the response.\n\n```python\n import requests\n\n #--- Obtain an API access token ---\n\n auth_url = 'https://api.auth.dtn.com/v1/tokens/authorize'\n\n body = {\n 'grant_type': 'client_credentials',\n 'client_id': '...insert your client id here...',\n 'client_secret': '...insert your client secret here...',\n 'audience': 'https://astronomical.api.dtn.com'\n }\n response = requests.post(auth_url, json=body)\n access_token = response.json()['data']['access_token']\n\n #--- Invoke the API ---\n\n api_base_url = 'https://astronomical.api.dtn.com/v2/'\n query_parameters = '&'.join([\n 'lat=52.369',\n 'lon=4.875',\n 'startDate=2023-08-10',\n 'endDate=2023-08-12',\n ])\n endpoint = '/sun-moon?' + query_parameters\n\n headers = {'Authorization': 'Bearer ' + access_token}\n response = requests.get(api_base_url + endpoint, headers=headers)\n\n #--- Print the response ---\n\n print(response.json())\n```\n## Latitude and longitude in the response\nRequested latitudes and longitudes are rounded to three (3) decimal places when presented in `$.features.*.geometry.coordinates`. Floating point precision might affect the last digit.\n### Rounding examples\n* 1.5555 => 1.556\n* 1.5545 => 1.554\n* -1.5555 => -1.556"},"servers":[{"url":"https://astronomical.api.dtn.com"}],"tags":[{"name":"Endpoints","description":"The Astronomical API has a single endpoint that streamlines the process of obtaining Sun and Moon data."}],"paths":{"/v2/sun-moon":{"get":{"tags":["Endpoints"],"summary":"Sun and Moon","description":"This endpoint provides comprehensive astronomical data including sunrise and sunset times, current moon phase, and more related to the Sun's and Moon's status for any specific point on Earth. Specify the location and an optional date range up to 15 days long. The API responds with the requested data in GeoJSON format.\n\nUse query parameters to control the results in the response body:\n\n * Specify a location as latitude (`lat`) and longitude (`lon`).\n\n * Two important parameters are `startDate` and `endDate`:\n + The API returns data for the specified date range when both are specified.\n + The API returns data for the specified UTC day when only `startTime` is specified.\n + The API returns data for the current UTC day when neither are specified.\n\n * Complete example: `https://astronomical.api.dtn.com/v2/sun-moon?lat={lat}&lon={lon}&startDate={start_date}&endDate={end_date}`\n","operationId":"sunMoon","security":[{"clientCredentials":[]}],"parameters":[{"in":"header","name":"Accept-Encoding","schema":{"type":"string","description":"Use this request header to communicate which compression algorithms the client understands. The API supports gzip.","example":"gzip"}},{"in":"header","name":"Accept","schema":{"type":"string","description":"Use this request header to specify an acceptable response media type.","example":"application/json"}},{"$ref":"#/components/parameters/lat"},{"$ref":"#/components/parameters/lon"},{"$ref":"#/components/parameters/startDate"},{"$ref":"#/components/parameters/endDate"}],"responses":{"200":{"description":"A successful request.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SunMoon"}}}},"400":{"$ref":"#/components/responses/bad-request"},"401":{"$ref":"#/components/responses/unauthorized"},"406":{"$ref":"#/components/responses/not-acceptable"}}}}},"components":{"responses":{"bad-request":{"description":"An invalid request.","content":{"application/problem+json":{"schema":{"$ref":"#/components/schemas/general-error"},"example":{"type":"bad request","title":"Invalid Request","detail":"Validation failed.","status":400,"instance":"urn:dtn:one-astronomical-service:/v2/sun-moon:requestId:123e4567-e89b-12d3-a458-426614176000"}}}},"unauthorized":{"description":"Unable to authenticate credentials.","content":{"application/problem+json":{"schema":{"$ref":"#/components/schemas/general-error"},"example":{"type":"unauthorized","title":"Error while authenticating the user.","detail":"invalid token","status":401,"instance":"urn:dtn:one-astronomical-service:/v2/sun-moon:requestId:123e4567-e89b-12d3-a458-426614176000"}}}},"not-acceptable":{"description":"Unable to produce a response matching the Accept request header.","content":{"application/problem+json":{"schema":{"$ref":"#/components/schemas/general-error"},"example":{"type":"not-acceptable","title":"Not Acceptable","detail":"The Accept header value is invalid or unsupported.","status":406,"instance":"urn:dtn:one-astronomical-service:/v2/sun-moon:requestId:123e4567-e89b-12d3-a458-426614176000"}}}}},"schemas":{"general-error":{"type":"object","properties":{"detail":{"type":"string","description":"A human-readable description of the specific error."},"type":{"type":"string","description":"The error type."},"title":{"type":"string","description":"A short, human-readable title for the general error type."},"status":{"type":"number","description":"The HTTP status code."},"instance":{"type":"string","format":"uri","description":"A URL with the specific error ID (often pointing to an error log for that specific response)."}},"additionalProperties":false},"SunMoon":{"type":"object","properties":{"url":{"type":"string"},"type":{"type":"string"},"features":{"type":"array","items":{"type":"object","properties":{"type":{"type":"string"},"geometry":{"type":"object","properties":{"type":{"type":"string"},"coordinates":{"type":"array","items":{"type":"number"},"example":[4.875,52.369]}}},"properties":{"type":"object","properties":{"2023-08-10":{"type":"object","properties":{"sun":{"type":"object","properties":{"solarNoon":{"type":"string","format":"date-time"},"nadir":{"type":"string","format":"date-time"},"sunrise":{"type":"string","format":"date-time"},"sunset":{"type":"string","format":"date-time"},"sunriseEnd":{"type":"string","format":"date-time"},"sunsetStart":{"type":"string","format":"date-time"},"dawn":{"type":"string","format":"date-time"},"dusk":{"type":"string","format":"date-time"},"nauticalDawn":{"type":"string","format":"date-time"},"nauticalDusk":{"type":"string","format":"date-time"},"nightEnd":{"type":"string","format":"date-time"},"night":{"type":"string","format":"date-time"},"goldenHourEnd":{"type":"string","format":"date-time"},"goldenHour":{"type":"string","format":"date-time"}}},"moon":{"type":"object","properties":{"illumination":{"type":"string"},"phaseId":{"type":"integer","minimum":1,"maximum":8},"phaseName":{"type":"string","enum":["New Moon","Waxing Crescent","First Quarter","Waxing Gibbous","Full Moon","Waning Gibbous","Last Quarter","Waning Crescent"]},"moonrise":{"type":"string","format":"date-time"},"moonset":{"type":"string","format":"date-time"}}}}}}}}}}},"example":{"url":"https://astronomical.api.dtn.com/v2/sun-moon?lat=52.369298973574985&lon=4.874941498041485&startDate=2023-08-10&endDate=2023-08-12","type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"Point","coordinates":[4.875,52.369]},"properties":{"2023-08-10":{"sun":{"solarNoon":"2023-08-10T11:47:17Z","nadir":"2023-08-09T23:47:17Z","sunrise":"2023-08-10T04:15:46Z","sunset":"2023-08-10T19:18:47Z","sunriseEnd":"2023-08-10T04:19:41Z","sunsetStart":"2023-08-10T19:14:52Z","dawn":"2023-08-10T03:36:02Z","dusk":"2023-08-10T19:58:31Z","nauticalDawn":"2023-08-10T02:43:49Z","nauticalDusk":"2023-08-10T20:50:45Z","nightEnd":"2023-08-10T01:35:56Z","night":"2023-08-10T21:58:38Z","goldenHourEnd":"2023-08-10T05:04:21Z","goldenHour":"2023-08-10T18:30:13Z"},"moon":{"illumination":"29.7%","phaseId":8,"phaseName":"Waning Crescent","moonrise":"2023-08-10T22:46:37Z","moonset":"2023-08-10T15:49:49Z"}},"2023-08-11":{"sun":{"solarNoon":"2023-08-11T11:47:08Z","nadir":"2023-08-10T23:47:08Z","sunrise":"2023-08-11T04:17:25Z","sunset":"2023-08-11T19:16:52Z","sunriseEnd":"2023-08-11T04:21:19Z","sunsetStart":"2023-08-11T19:12:58Z","dawn":"2023-08-11T03:37:55Z","dusk":"2023-08-11T19:56:22Z","nauticalDawn":"2023-08-11T02:46:10Z","nauticalDusk":"2023-08-11T20:48:06Z","nightEnd":"2023-08-11T01:39:41Z","night":"2023-08-11T21:54:36Z","goldenHourEnd":"2023-08-11T05:05:49Z","goldenHour":"2023-08-11T18:28:28Z"},"moon":{"illumination":"20.8%","phaseId":8,"phaseName":"Waning Crescent","moonrise":"2023-08-11T23:28:00Z","moonset":"2023-08-11T17:01:30Z"}},"2023-08-12":{"sun":{"solarNoon":"2023-08-12T11:47:00Z","nadir":"2023-08-11T23:47:00Z","sunrise":"2023-08-12T04:19:03Z","sunset":"2023-08-12T19:14:56Z","sunriseEnd":"2023-08-12T04:22:57Z","sunsetStart":"2023-08-12T19:11:02Z","dawn":"2023-08-12T03:39:47Z","dusk":"2023-08-12T19:54:12Z","nauticalDawn":"2023-08-12T02:48:32Z","nauticalDusk":"2023-08-12T20:45:28Z","nightEnd":"2023-08-12T01:43:21Z","night":"2023-08-12T21:50:38Z","goldenHourEnd":"2023-08-12T05:07:17Z","goldenHour":"2023-08-12T18:26:42Z"},"moon":{"illumination":"13.4%","phaseId":8,"phaseName":"Waning Crescent","moonrise":"Never Rise","moonset":"2023-08-12T17:57:59Z"}}}}]}}},"parameters":{"lat":{"name":"lat","in":"query","schema":{"type":"number","format":"float"},"example":52.369,"required":true},"lon":{"name":"lon","in":"query","schema":{"type":"number","format":"float"},"example":4.875,"required":true},"startDate":{"name":"startDate","in":"query","schema":{"type":"string","format":"date"},"example":"2023-08-10"},"endDate":{"name":"endDate","in":"query","schema":{"type":"string","format":"date"},"example":"2023-08-12"}},"securitySchemes":{"clientCredentials":{"type":"oauth2","x-receive-token-in":"request-body","flows":{"clientCredentials":{"tokenUrl":"https://api.auth.dtn.com/v1/tokens/authorize"}},"description":"# Using DAIS for M2M/API Auth\nYou have been given a Client ID and a Client Secret, which are used to request a DTN Access Token. DTN Access Tokens are required when making calls to each and every DTN API endpoint. The following information provides additional details on these tokens and how they are generated.\n## What is an Access Token and how is it different from an API Key?\nAn API Key is a random string of characters that an API uses to authorize whether or not a calling client has approved access to an endpoint. These keys are a non-standard approach to API authorization and are generally issued on a per-API basis.\n\nAn Access Token is also a string of characters but is a base-64 encoded JavaScript Object Notation Web Token, or JWT. JWTs are a widely accepted standard that use OAuth concepts and approaches. \n\nBoth API Keys and Access Tokens are used in an Authorization Request Header as a Bearer, meaning there is no difference in where you put this string of characters when you make calls to DTN APIs.\n## How to generate an Access Token?\nWhen requested, an Access Token is generated for your specific Client (ID/Secret) and for a specific API. The DTN Auth and Identity Service (DAIS) generates new Access Tokens for your client. The DAIS endpoint is `POST https://api.auth.dtn.com/v1/tokens/authorize`.\n\nThis endpoint takes two Header parameters:\n * `Content-Type: application/json`\n * `Accept: application/json`\n\nThis endpoint takes four parameters in the Request Body:\n * `grant_type`: this should always be client_credentials for generating machine-to-machine tokens.\n * `client_id`: this is the Client ID or Application ID using the token and is given to you by DTN's Identity Team. This ID will never change for your client/application.\n * `client_secret`: this is the Client Secret that is associated with the Application ID and is given to you by DTN's Identity Team. This key is subject to rotation for security purposes but always with the client's knowledge.\n * `audience`: this is the API for which this Access Token will be used. For the DTN Astronomical API, you need to use the following audience: https://astronomical.api.dtn.com\n\nYou can use this CURL command template as a reference for obtaining an access token:\n ```\n curl --location --request POST 'https://api.auth.dtn.com/v1/tokens/authorize' \\\n--header 'Accept: application/json' \\\n--header 'Content-Type: application/json' \\\n--data-raw '{\n\"grant_type\": \"client_credentials\",\n\"client_id\": \"insert your client id here\",\n\"client_secret\": \"insert your client secret here\",\n\"audience\": \"insert your audience here\"\n}' \n ```\n\n*This document, for demonstration purposes, supplies a client_id and client_secret in all code examples. This client/application is for a fictitious API and cannot be used in practice to gain unauthorized access to any other DTN API.*\nUpon generating a new Access Token, you should receive an HTTP Response from DAIS similar to this:\n ```\n {\n \"data\": {\n \"access_token\": \"eyJhbGciOiJSUz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KiNRsKb30TH_WAel2hsxNlcPK3XHCmrMTYsNnu7HNqOTMn2i0__0rvBrhSWEw-_grqQDmWFJuWd7Qhi1q81AaJcdqgoSa_efz93QFclJUNw\",\n \"scope\": \"read:demo create:demo update:demo\",\n \"expires_in\": 90,\n \"token_type\": \"Bearer\"\n },\n \"meta\": {\n \"date_time\": \"2022-06-24T19:09:42.963Z\",\n \"name\": \"v1.tokens.authorize\",\n \"uuid\": \"ee6f9feb-dcf8-4421-a6fd-efd6beabdaa9\",\n \"start_timestamp\": 1656097782509,\n \"end_timestamp\": 1656097782963,\n \"execution_time\": 454\n }\n }\n ```\nLooking at this Response, you will see:\n * `access_token`: contains the JWT Access Token string you will use as your Bearer token.\n * `scope`: contains the scopes that this Access Token gives you permissions to access.\n * `expires_in`: contains the length of time before this Access Token will expire, in seconds.\n * `token_type`: verifies that this Access Token should be used as a Bearer token.\n\n## How to use an Access Token after one is generated?\nOnce a new Access Token is obtained, it is used in each call to a DTN API endpoint as a Bearer token in an Authorization Request Header. For example:\n ```\n Header: 'Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6InpfX21pZW13NGhoTmdvQWQxR3N6ciJ9.eyJodHRwczovL2F1dGguZHRuLmNvbS9jdXN0b21lcklkIjoiMTIzNDU2Nzg5MERlbW8iLCJodHRwczovL2F1dGguZHRuLmNvbS9wcm9kdWN0Q29kZSI6IkRlbW9BcGlQIiwiaHR0cHM6Ly9hdXRoLmR0bi5jb20vcmVxdWVzdGVySXAiOiIxOC4yMTMuMTc0LjI3IiwiaHR0cHM6Ly9hdXRoLmR0bi5jb20vcnBzIjoiMTAwIiwiaHR0cHM6Ly9hdXRoLmR0bi5jb20vdGllciI6IkJhc2ljIiwiaHR0cHM6Ly9hdXRoLmR0bi5jb20vcXVvdGEiOiI5OTk5OTkiLCJpc3MiOiJodHRwczovL2lkLmF1dGguZHRuLmNvbS8iLCJzdWIiOiJuZnlPM0tpS1BSOE4wREtSNUNMOGpTOUdGQkNEZXlGTUBjbGllbnRzIiwiYXVkIjoiaHR0cHM6Ly9kZW1vLWFwaS5hdXRoLmR0bi5jb20vIiwiaWF0IjoxNjU2MDk5MDY4LCJleHAiOjE2NTYwOTkxNTgsImF6cCI6Im5meU8zS2lLUFI4TjBES1I1Q0w4alM5R0ZCQ0RleUZNIiwic2NvcGUiOiJyZWFkOmRlbW8gY3JlYXRlOmRlbW8gdXBkYXRlOmRlbW8iLCJndHkiOiJjbGllbnQtY3JlZGVudGlhbHMiLCJwZXJtaXNzaW9ucyI6WyJyZWFkOmRlbW8iLCJjcmVhdGU6ZGVtbyIsInVwZGF0ZTpkZW1vIl19.0VHdyp1w9PPFVI0FPheAwuKZwb5C25rwP-LPMXcSNoRmouvga1DZtNLA67ZzE_sAlc_VpaDRr6daLKr_Alw4347mw9sdjP8wKR27kCZa9JZK5PGQMmXHscATbzBEJYpCPklfyGaajgymqTBGnedcv8F0UvlRzQPsFeRPnVoX7BWOSXpMbyToGiXWkQLBQT7r96KAmLZOPJFZspPtjw-wH2mSL2WNa_nkB4j5vMGhGxlKiNRsKb30TH_WAel2hsxNlcPK3XHCmrMTYsNnu7HNqOTMn2i0__0rvBrhSWEw-_grqQDmWFJuWd7Qhi1q81AaJcdqgoSa_efz93QFclJUNw'\n ```\n\n## Deconstructing the Access Token\nA DTN Access Token carries information within its JWT Body that is available on every API call. By deconstructing the JWT token, our Access Tokens will resemble:\n ```\n {\n \"https://auth.dtn.com/customerId\": \"1234567890Demo\",\n \"https://auth.dtn.com/productCode\": \"DemoApiP\",\n \"https://auth.dtn.com/requesterIp\": \"18.213.174.27\",\n \"https://auth.dtn.com/rps\": \"100\",\n \"https://auth.dtn.com/tier\": \"Basic\",\n \"https://auth.dtn.com/quota\": \"999999\",\n \"iss\": \"https://id.auth.dtn.com/\",\n \"sub\": \"nfyO3KiKPR8N0DKR5CL8jS9GFBCDeyFM@clients\",\n \"aud\": \"https://demo-api.auth.dtn.com/\",\n \"iat\": 1656099068,\n \"exp\": 1656099158,\n \"azp\": \"nfyO3KiKPR8N0DKR5CL8jS9GFBCDeyFM\",\n \"scope\": \"read:demo create:demo update:demo\",\n \"gty\": \"client-credentials\",\n \"permissions\": [\n \"read:demo\",\n \"create:demo\",\n \"update:demo\"\n ]\n }\n ```\n### Description of Claims\n\n | Claim | Type | Description |\n | -----------------------------------| --------------------------------------------| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n | `https://auth.dtn.com/customerId` | String | Custom DTN claim containing the Customer ID found in the DTN Order Management/Salesforce system associated with this token. |\n | `https://auth.dtn.com/productCode` | String | Custom DTN claim containing the Identity product code associated with this token. |\n | `https://auth.dtn.com/requesterIp` | String | Custom DTN claim containing the IP address of the requesting client. |\n | `https://auth.dtn.com/rps` | String | Custom DTN claim containing the maximum rate per second this customer is authorized to utilize. |\n | `https://auth.dtn.com/tier` | String | Custom DTN claim containing the data tier the customer purchased for the requested access. |\n | `https://auth.dtn.com/quota` | String | Custom DTN claim containing the maximum yearly quota the customer purchased for calling DTN endpoints for the specific product. |\n | `iss` | String (URI) | The Security Token Service (STS) that issues and returns the token. If this value is not from `https://id.auth.dtn.com/`, the token should not be considered trusted. |\n | `sub` | String (URI) | The principle about which the token asserts information (the User ID or Client ID within the Identity Provider). A User ID will start with a prefix of `auth0\\|`, while the Client ID will end with the suffix `@clients`. |\n | `aud` | String \\| Array (Strings) (URI \\| [URI, …]) | Identifies the intended recipient(s) of the token – its audience. The token should be rejected if the audience does not contain values expected by the calling application. |\n | `iat` | Number (Timestamp) | “Issued At” indicates when the authentication for this token occurred. |\n | `exp` | Number (Timestamp) | The “expiration time” on or after which the JWT must not be accepted for processing. |\n | `azp` | String | The application/client ID of the client using the token. The application can cat as itself or on behalf of a user. |\n | `gty` | String (Space-delimited) | The grant type that was used to request the token – not an RFC 7519 registered claim (Auth0-specific). |\n | `permissions` | Array (Strings) | The grant type that was used to request the token – not an RFC 7519 registered claim (Auth0-specific). |\n\n "}}}}