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. To use this API, you need an API key. You can get one by creating a free account and visiting your dashboard.
Important: Ensure that this API is enabled from within your dashboard to use it in your application. If not, you may receive a 403
error
Get the sunrise and sunset times for a given location
This is a required header
on every request. Your API Key is found from within your dashboard
This is an optional header
. Set the value to application/json
, application/xml
, or application/yaml
double
(required)The latitude of the location for which you want to get the sunrise and sunset times (e.g., 36.7201600)
londouble
(required)The longitude of the location for which you want to get the sunrise and sunset times (e.g., -4.4203400)
datestring
The date for which you want to get the sunrise and sunset times (e.g., MM-DD-YYYY : 01-01-2022)
Sample Request
import requests
url = "https://api.apiverve.com/v1/sunrisesunset"
querystring = {'lat': '36.7201600', 'lon': '-4.4203400', 'date': '02-04-2025'}
headers = {
"x-api-key": "YOUR_API_KEY"
}
response = requests.get(url, headers=headers, params=querystring)
print(response.json())
using System.Net.Http.Headers;
var client = new HttpClient();
var request = new HttpRequestMessage
{
Method = HttpMethod.Get,
RequestUri = new Uri("https://api.apiverve.com/v1/sunrisesunset?lat=36.7201600&lon=-4.4203400&date=02-04-2025"),
Headers =
{
{ "x-api-key", "YOUR_API_KEY" }
},
};
using (var response = await client.SendAsync(request))
{
response.EnsureSuccessStatusCode();
var body = await response.Content.ReadAsStringAsync();
Console.WriteLine(body);
}
const data = null;
const xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener('readystatechange', function () {
if (this.readyState === this.DONE) {
console.log(this.responseText);
}
});
xhr.open('GET', 'https://api.apiverve.com/v1/sunrisesunset?lat=36.7201600&lon=-4.4203400&date=02-04-2025');
xhr.setRequestHeader('x-api-key', 'YOUR_API_KEY');
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.setRequestHeader('Accept', 'application/json');
xhr.send(data);
const request = require('request');
const options = {
method: 'GET',
url: 'https://api.apiverve.com/v1/sunrisesunset?lat=36.7201600&lon=-4.4203400&date=02-04-2025',
headers: {
'x-api-key': 'YOUR_API_KEY'
}
};
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
});
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://api.apiverve.com/v1/sunrisesunset?lat=36.7201600&lon=-4.4203400&date=02-04-2025"))
.header("x-api-key", "YOUR_API_KEY")
.method("GET", HttpRequest.BodyPublishers.noBody())
.build();
HttpResponse response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
import Foundation
let headers = [
"x-api-key": "YOUR_API_KEY"
]
let request = NSMutableURLRequest(url: NSURL(string: "https://api.apiverve.com/v1/sunrisesunset?lat=36.7201600&lon=-4.4203400&date=02-04-2025")! as URL,
cachePolicy: .useProtocolCachePolicy,
timeoutInterval: 10.0)
request.httpMethod = "GET"
request.allHTTPHeaderFields = headers
let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
if (error != nil) {
print(error as Any)
} else {
let httpResponse = response as? HTTPURLResponse
print(httpResponse)
}
})
dataTask.resume()
curl --request GET \
--url 'https://api.apiverve.com/v1/sunrisesunset?lat=36.7201600&lon=-4.4203400&date=02-04-2025' \
--header 'x-api-key: YOUR_API_KEY'
Sample Response
{
"status": "ok",
"error": null,
"data": {
"solarNoon": "2024-09-01T12:19:07.959Z",
"sunrise": "2024-09-01T05:50:23.51Z",
"sunset": "2024-09-01T18:47:52.407Z",
"sunriseEnd": "2024-09-01T05:53:05.874Z",
"sunsetStart": "2024-09-01T18:45:10.043Z",
"dawn": "2024-09-01T05:23:56.584Z",
"dusk": "2024-09-01T19:14:19.333Z",
"nauticalDawn": "2024-09-01T04:52:34.262Z",
"nauticalDusk": "2024-09-01T19:45:41.655Z",
"nightEnd": "2024-09-01T04:20:08.217Z",
"night": "2024-09-01T20:18:07.7Z",
"goldenHourEnd": "2024-09-01T06:24:51.482Z",
"goldenHour": "2024-09-01T18:13:24.435Z"
},
"code": 200
}
<Root>
<status>ok</status>
<error />
<data>
<solarNoon>2024-09-01T12:19:07.959Z</solarNoon>
<sunrise>2024-09-01T05:50:23.51Z</sunrise>
<sunset>2024-09-01T18:47:52.407Z</sunset>
<sunriseEnd>2024-09-01T05:53:05.874Z</sunriseEnd>
<sunsetStart>2024-09-01T18:45:10.043Z</sunsetStart>
<dawn>2024-09-01T05:23:56.584Z</dawn>
<dusk>2024-09-01T19:14:19.333Z</dusk>
<nauticalDawn>2024-09-01T04:52:34.262Z</nauticalDawn>
<nauticalDusk>2024-09-01T19:45:41.655Z</nauticalDusk>
<nightEnd>2024-09-01T04:20:08.217Z</nightEnd>
<night>2024-09-01T20:18:07.7Z</night>
<goldenHourEnd>2024-09-01T06:24:51.482Z</goldenHourEnd>
<goldenHour>2024-09-01T18:13:24.435Z</goldenHour>
</data>
<code>200</code>
</Root>
status: ok
error:
data:
solarNoon: 2024-09-01T12:19:07.9590000Z
sunrise: 2024-09-01T05:50:23.5100000Z
sunset: 2024-09-01T18:47:52.4070000Z
sunriseEnd: 2024-09-01T05:53:05.8740000Z
sunsetStart: 2024-09-01T18:45:10.0430000Z
dawn: 2024-09-01T05:23:56.5840000Z
dusk: 2024-09-01T19:14:19.3330000Z
nauticalDawn: 2024-09-01T04:52:34.2620000Z
nauticalDusk: 2024-09-01T19:45:41.6550000Z
nightEnd: 2024-09-01T04:20:08.2170000Z
night: 2024-09-01T20:18:07.7000000Z
goldenHourEnd: 2024-09-01T06:24:51.4820000Z
goldenHour: 2024-09-01T18:13:24.4350000Z
code: 200
The Sunrise Sunset API supports the following response content types:
application/json
, application/xml
, application/yaml
You can specify the response content type by setting the Accept
header in your request. If you don't specify a content type, the API will default to application/json
.
The Sunrise Sunset API uses an API Key to authenticate requests. You can view and manage your API key by visiting your dashboard.
Your API keys carry many privileges. To keep them from being abused, please do not share the keys on client-side code or Github etc. Keep them very secure.
To use any API, you must have it enabled from within your dashboard. Disabled APIs will fail to respond to your requests.
All requests made to the API must contain the header x-api-key
in each of your requests. API requests without authentication will fail.
All API requests must also be made over secure HTTPS
. Requests made over plain HTTP
will fail.
Error Code | Meaning |
---|---|
401 | Your request was made with invalid credentials. This error also appears when you don't pass the x-api-key header in your request.
|
403 | Typically, this occurs when you are trying to access an API that you have not enabled. |
{
"status": "error",
"data": null,
"error": "tokens have been depleted",
"code": 429
}
Each subscription has its own monthly token limit. Your token count is based on your subscription plan. If you reach your limits, don't worry. You can always upgrade or downgrade at any time.
When you reach your limit, the service will stop responding and typically return an HTTP 429
response status code. The error will also contain a detailed JSON.
The Sunrise Sunset API uses the following error code:
Error Code | Meaning |
---|---|
429 | You have exceeded your rate limit and further requests will be denied until the next cycle. |
For reference, the Sunrise Sunset API uses the following error codes:
Error Code | Meaning |
---|---|
Code | Message |
200 | The request was successful. The response will include the requested data. |
400 | The request was invalid. The response will include a message that explains the error. |
401 | The request was not authorized. Usually, this means that the API key is missing or invalid. |
403 | This means that the request was trying to access a resource that it does not have permission to access. |
404 | This means that the resource you are trying to access does not exist. |
429 | This means that you have reached the rate limit. The response will include a Retry-After header that indicates how many seconds you need to wait before making a new request. |
500 | This means that there was an error on the server side. We are alerted when this happens and we will work to fix it as soon as possible. |