PHP astrology API quickstart
cURL or Guzzle, both fine.
No extension and no SDK needed - the API is JSON over HTTPS. This page uses PHP's bundled cURL so it works on any shared host, then shows the Guzzle version for projects that already have it.
There is no official PHP SDK. The examples below use ext-curl, which ships with essentially every PHP install.
Step 1
Keep the key out of your code
The key authenticates every call and should never reach a client bundle or a commit. Put it in the environment and read it from there.
# .env (git-ignored) ASTRONODE_API_KEY=aie_test_your_key_here
Step 2
Make the call
Bundled cURL, no Composer package required.
<?php
$ch = curl_init("https://api.astronode.dev/v1/charts/birth");
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
"Authorization: Bearer " . getenv("ASTRONODE_API_KEY"),
"Content-Type: application/json",
"Accept: application/json",
],
CURLOPT_POSTFIELDS => json_encode([
"date" => "1993-07-04",
"time" => "09:27:11",
"tz_offset_minutes" => 330,
"lat" => 31.7473,
"lng" => 77.7754,
]),
]);
$raw = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
curl_close($ch);
$json = json_decode($raw, true);
if ($status >= 400) {
// Same envelope, with "error" instead of "data".
throw new RuntimeException($json["error"]["code"] . ": " . $json["error"]["message"]);
}
print_r($json["data"]["ascendant"]);Step 3
With Guzzle
If your project already has Guzzle, this is the same call with the error handling folded in.
<?php
use GuzzleHttp\Client;
use GuzzleHttp\Exception\ClientException;
$client = new Client(["base_uri" => "https://api.astronode.dev"]);
try {
$res = $client->post("/v1/charts/birth", [
"headers" => [
"Authorization" => "Bearer " . getenv("ASTRONODE_API_KEY"),
"Accept" => "application/json",
],
"json" => [
"date" => "1993-07-04",
"time" => "09:27:11",
"tz_offset_minutes" => 330,
"lat" => 31.7473,
"lng" => 77.7754,
],
]);
$data = json_decode($res->getBody(), true)["data"];
} catch (ClientException $e) {
$body = json_decode($e->getResponse()->getBody(), true);
throw new RuntimeException($body["error"]["message"] ?? "request failed");
}Next
Where to go from here
The call above is one of 110 endpoints. They all take the same bearer token and return the same envelope, so the second one is a path change. Each endpoint page carries its request fields and constraints.
Free tier covers 1,000 requests / month. No card, and test keys work on every endpoint.
Other languages