Sunrise SunsetSunrise Sunset

Token Usage:1 per call

Sunrise Sunset is a simple tool for getting the sunrise and sunset times. It returns the sunrise and sunset times for a given location and date.

This API provides reliable and fast access to sunrise sunset data through a simple REST interface. Built for developers who need consistent, high-quality results with minimal setup time.

To use this API, you need an API key. You can get one by creating a free account and visiting your dashboard.

View API in Directory

Endpoint

GET Request
GET https://api.apiverve.com/v1/sunrisesunset

Code Examples

Here are examples of how to call this API in different programming languages:

cURL Request
curl -X GET \
  "https://api.apiverve.com/v1/sunrisesunset?lat=36.7201600&lon=-4.4203400&date=10-22-2025" \
  -H "X-API-Key: your_api_key_here"
JavaScript (Fetch API)
const response = await fetch('https://api.apiverve.com/v1/sunrisesunset', {
  method: 'GET',
  headers: {
    'X-API-Key': 'your_api_key_here',
    'Content-Type': 'application/json'
  }
});

const data = await response.json();
console.log(data);
Python (Requests)
import requests

headers = {
    'X-API-Key': 'your_api_key_here',
    'Content-Type': 'application/json'
}

response = requests.get('https://api.apiverve.com/v1/sunrisesunset', headers=headers)

data = response.json()
print(data)
Node.js (Native HTTPS)
const https = require('https');
const url = require('url');

const options = {
  method: 'GET',
  headers: {
    'X-API-Key': 'your_api_key_here',
    'Content-Type': 'application/json'
  }
};

const req = https.request('https://api.apiverve.com/v1/sunrisesunset', options, (res) => {
  let data = '';
  res.on('data', (chunk) => data += chunk);
  res.on('end', () => console.log(JSON.parse(data)));
});

req.end();
PHP (cURL)
<?php

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'https://api.apiverve.com/v1/sunrisesunset');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'X-API-Key: your_api_key_here',
    'Content-Type: application/json'
]);

$response = curl_exec($ch);
curl_close($ch);

$data = json_decode($response, true);
print_r($data);

?>
Go (net/http)
package main

import (
    "fmt"
    "io"
    "net/http"

)

func main() {
    req, _ := http.NewRequest("GET", "https://api.apiverve.com/v1/sunrisesunset", nil)

    req.Header.Set("X-API-Key", "your_api_key_here")
    req.Header.Set("Content-Type", "application/json")

    client := &http.Client{}
    resp, err := client.Do(req)
    if err != nil {
        panic(err)
    }
    defer resp.Body.Close()

    body, _ := io.ReadAll(resp.Body)
    fmt.Println(string(body))
}
Ruby (Net::HTTP)
require 'net/http'
require 'json'

uri = URI('https://api.apiverve.com/v1/sunrisesunset')
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true

request = Net::HTTP::Get.new(uri)
request['X-API-Key'] = 'your_api_key_here'
request['Content-Type'] = 'application/json'

response = http.request(request)
puts JSON.pretty_generate(JSON.parse(response.body))

Authentication

This API requires authentication via API key. Include your API key in the request header:

Required Header
X-API-Key: your_api_key_here

Parameters

The following parameters are available for this API endpoint:

ParameterTypeRequiredLocationDescriptionExample
latnumberYesqueryThe latitude of the location for which you want to get the sunrise and sunset times (e.g., 36.7201600)36.7201600
lonnumberYesqueryThe longitude of the location for which you want to get the sunrise and sunset times (e.g., -4.4203400)-4.4203400
datestringNoqueryThe date for which you want to get the sunrise and sunset times (e.g., MM-DD-YYYY : 01-01-2022)10-22-2025

Response

The API returns responses in JSON, XML, and YAML formats:

Example Responses

JSON Response
200 OK
{
  "status": "ok",
  "error": null,
  "data": {
    "solarNoon": "2025-02-20T12:32:53.132Z",
    "sunrise": "2025-02-20T07:01:34.082Z",
    "sunset": "2025-02-20T18:04:12.182Z",
    "sunriseEnd": "2025-02-20T07:04:17.987Z",
    "sunsetStart": "2025-02-20T18:01:28.278Z",
    "dawn": "2025-02-20T06:35:17.568Z",
    "dusk": "2025-02-20T18:30:28.696Z",
    "nauticalDawn": "2025-02-20T06:05:07.51Z",
    "nauticalDusk": "2025-02-20T19:00:38.754Z",
    "nightEnd": "2025-02-20T05:35:08.859Z",
    "night": "2025-02-20T19:30:37.405Z",
    "goldenHourEnd": "2025-02-20T07:36:59.509Z",
    "goldenHour": "2025-02-20T17:28:46.756Z"
  }
}
XML Response
200 OK
<Root>
  <status>ok</status>
  <error />
  <data>
    <solarNoon>2025-02-20T12:32:53.132Z</solarNoon>
    <sunrise>2025-02-20T07:01:34.082Z</sunrise>
    <sunset>2025-02-20T18:04:12.182Z</sunset>
    <sunriseEnd>2025-02-20T07:04:17.987Z</sunriseEnd>
    <sunsetStart>2025-02-20T18:01:28.278Z</sunsetStart>
    <dawn>2025-02-20T06:35:17.568Z</dawn>
    <dusk>2025-02-20T18:30:28.696Z</dusk>
    <nauticalDawn>2025-02-20T06:05:07.51Z</nauticalDawn>
    <nauticalDusk>2025-02-20T19:00:38.754Z</nauticalDusk>
    <nightEnd>2025-02-20T05:35:08.859Z</nightEnd>
    <night>2025-02-20T19:30:37.405Z</night>
    <goldenHourEnd>2025-02-20T07:36:59.509Z</goldenHourEnd>
    <goldenHour>2025-02-20T17:28:46.756Z</goldenHour>
  </data>
</Root>
YAML Response
200 OK
status: ok
error: 
data:
  solarNoon: 2025-02-20T12:32:53.1320000Z
  sunrise: 2025-02-20T07:01:34.0820000Z
  sunset: 2025-02-20T18:04:12.1820000Z
  sunriseEnd: 2025-02-20T07:04:17.9870000Z
  sunsetStart: 2025-02-20T18:01:28.2780000Z
  dawn: 2025-02-20T06:35:17.5680000Z
  dusk: 2025-02-20T18:30:28.6960000Z
  nauticalDawn: 2025-02-20T06:05:07.5100000Z
  nauticalDusk: 2025-02-20T19:00:38.7540000Z
  nightEnd: 2025-02-20T05:35:08.8590000Z
  night: 2025-02-20T19:30:37.4050000Z
  goldenHourEnd: 2025-02-20T07:36:59.5090000Z
  goldenHour: 2025-02-20T17:28:46.7560000Z

Response Structure

All API responses follow a consistent structure with the following fields:

FieldTypeDescriptionExample
statusstringIndicates whether the request was successful ("ok") or failed ("error")ok
errorstring | nullContains error message if status is "error", otherwise nullnull
dataobject | nullContains the API response data if successful, otherwise null{...}

Response Data Fields

When the request is successful, the data object contains the following fields:

FieldTypeSample Value
solarNoonstring"2025-02-20T12:32:53.132Z"
sunrisestring"2025-02-20T07:01:34.082Z"
sunsetstring"2025-02-20T18:04:12.182Z"
sunriseEndstring"2025-02-20T07:04:17.987Z"
sunsetStartstring"2025-02-20T18:01:28.278Z"
dawnstring"2025-02-20T06:35:17.568Z"
duskstring"2025-02-20T18:30:28.696Z"
nauticalDawnstring"2025-02-20T06:05:07.51Z"
nauticalDuskstring"2025-02-20T19:00:38.754Z"
nightEndstring"2025-02-20T05:35:08.859Z"
nightstring"2025-02-20T19:30:37.405Z"
goldenHourEndstring"2025-02-20T07:36:59.509Z"
goldenHourstring"2025-02-20T17:28:46.756Z"

Headers

Required and optional headers for API requests:

Header NameRequiredExample ValueDescription
X-API-KeyYesyour_api_key_hereYour APIVerve API key. Found in your dashboard under API Keys.
AcceptNoapplication/jsonSpecify response format: application/json (default), application/xml, or application/yaml
User-AgentNoMyApp/1.0Identifies your application for analytics and debugging purposes
X-Request-IDNoreq_123456789Custom request identifier for tracking and debugging requests
Cache-ControlNono-cacheControl caching behavior for the request and response

Client Libraries

To get started with minimal code, most of our APIs are available through client libraries and clients:

Run in PostmanNPMPyPINuGetSwagger

Error Codes

The API uses standard HTTP status codes to indicate success or failure:

Status CodeMessageDescription
200OKRequest successful, data returned
400Bad RequestInvalid request parameters or malformed request
401UnauthorizedMissing or invalid API key
403ForbiddenAPI key does not have permission for this endpoint
429Too Many RequestsRate limit exceeded, please slow down requests
500Internal Server ErrorServer error, please try again later

What's Next?

Continue your journey with these recommended resources

Was this page helpful?

Help us improve our documentation