PHP & WordPressApril 202610 min read

Vedic Astrology API for PHP and WordPress — Integration Guide

Complete PHP integration for the VedIntel™ AstroAPI — from a simple file_get_contents() one-liner to a production cURL wrapper, a Guzzle client for Laravel, and a full WordPress shortcode plugin with transient caching.

Quickest PHP API Call

No dependencies, no SDK — just PHP's built-in HTTP wrapper:

<?php
// Minimal PHP — file_get_contents (simplest approach)
$api_key = 'YOUR_KEY';
$params  = http_build_query([
    'api_key' => $api_key,
    'dob'     => '01/10/1977',  // DD/MM/YYYY
    'tob'     => '11:40',       // HH:MM
    'lat'     => 11,
    'lon'     => 77,
    'tz'      => 5.5,
]);
$url  = 'https://vedintelastroapi.com/api/v1/horoscope/planet-details?' . $params;
$json = file_get_contents($url);
$data = json_decode($json, true);

// $data['response']['planets'][0]['sign'] → 'Virgo'
// $data['remaining_api_calls'] → 4999

Production cURL Wrapper in PHP

For production PHP apps (any framework), use cURL with timeout and error handling:

<?php
// cURL — recommended for production (timeout, error handling)
function astro_api(string $endpoint, array $params, string $api_key): array {
    $params['api_key'] = $api_key;
    $url = 'https://vedintelastroapi.com/api/v1/' . ltrim($endpoint, '/') . '?' . http_build_query($params);

    $ch = curl_init($url);
    curl_setopt_array($ch, [
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_TIMEOUT        => 10,
        CURLOPT_FOLLOWLOCATION => true,
        CURLOPT_HTTPHEADER     => ['Accept: application/json'],
    ]);
    $response = curl_exec($ch);
    $errno    = curl_errno($ch);
    curl_close($ch);

    if ($errno) throw new RuntimeException('cURL error: ' . $errno);
    $decoded = json_decode($response, true);
    if ($decoded['status'] !== 200) throw new RuntimeException($decoded['error'] ?? 'API error');
    return $decoded['response'];
}

// Usage
try {
    $planets = astro_api('horoscope/planet-details', [
        'dob' => '01/10/1977', 'tob' => '11:40', 'lat' => 11, 'lon' => 77, 'tz' => 5.5,
    ], 'YOUR_KEY');

    foreach ($planets['planets'] as $planet) {
        echo "{$planet['name']}: {$planet['sign']} (House {$planet['house']})\n";
    }
} catch (RuntimeException $e) {
    echo 'Error: ' . $e->getMessage();
}

Vedic Astrology API with Guzzle (Laravel / Symfony)

Guzzle is the standard HTTP client for Laravel and Symfony. Store your API key in .env as ASTRO_API_KEY:

<?php
// Guzzle (Laravel / Symfony / modern PHP)
use GuzzleHttp\Client;

$client = new Client([
    'base_uri' => 'https://vedintelastroapi.com/api/v1/',
    'timeout'  => 10,
]);

$response = $client->get('horoscope/planet-details', [
    'query' => [
        'api_key' => env('ASTRO_API_KEY'),
        'dob'     => '01/10/1977',
        'tob'     => '11:40',
        'lat'     => 11,
        'lon'     => 77,
        'tz'      => 5.5,
    ],
]);

$data    = json_decode($response->getBody(), true);
$planets = $data['response']['planets'];

WordPress Astrology Plugin with Shortcode

Drop this into a WordPress plugin file. It adds a [astro_chart] shortcode and caches results for 24 hours using WordPress transients — so you only make an API call on the first load per unique birth chart:

<?php
/*
 * Plugin Name: VedIntel™ Astro Shortcode
 * Description: Display a Vedic birth chart via shortcode. Usage: [astro_chart dob="01/10/1977" tob="11:40" lat="11" lon="77" tz="5.5"]
 * Version: 1.0
 */

defined('ABSPATH') || exit;

function vedintel_fetch_chart(string $dob, string $tob, float $lat, float $lon, float $tz): ?array {
    $params = http_build_query([
        'api_key' => defined('VEDINTEL_API_KEY') ? VEDINTEL_API_KEY : get_option('vedintel_api_key', ''),
        'dob' => $dob, 'tob' => $tob, 'lat' => $lat, 'lon' => $lon, 'tz' => $tz,
    ]);
    $cache_key = 'vedintel_' . md5($params);
    $cached    = get_transient($cache_key);
    if ($cached !== false) return $cached;

    $response = wp_remote_get('https://vedintelastroapi.com/api/v1/horoscope/planet-details?' . $params, [
        'timeout' => 10,
    ]);
    if (is_wp_error($response)) return null;

    $body = json_decode(wp_remote_retrieve_body($response), true);
    if (($body['status'] ?? 0) !== 200) return null;

    set_transient($cache_key, $body['response'], DAY_IN_SECONDS); // cache 24hrs
    return $body['response'];
}

function vedintel_astro_shortcode(array $atts): string {
    $atts = shortcode_atts([
        'dob' => '', 'tob' => '06:00', 'lat' => '', 'lon' => '', 'tz' => '5.5',
    ], $atts);

    if (empty($atts['dob']) || empty($atts['lat']) || empty($atts['lon'])) {
        return '<p>Please provide dob, lat, and lon attributes.</p>';
    }

    $chart = vedintel_fetch_chart($atts['dob'], $atts['tob'], (float)$atts['lat'], (float)$atts['lon'], (float)$atts['tz']);
    if (!$chart) return '<p>Could not load chart data.</p>';

    $html = '<div class="vedintel-chart"><table><thead><tr><th>Planet</th><th>Sign</th><th>House</th><th>Nakshatra</th></tr></thead><tbody>';
    foreach ($chart['planets'] as $p) {
        $retro = !empty($p['is_retro']) ? ' ℞' : '';
        $html .= "<tr><td>{$p['name']}{$retro}</td><td>{$p['sign']}</td><td>{$p['house']}</td><td>{$p['nakshatra']}</td></tr>";
    }
    $html .= '</tbody></table></div>';
    return $html;
}
add_shortcode('astro_chart', 'vedintel_astro_shortcode');

Usage in any WordPress post or page: [astro_chart dob="01/10/1977" tob="11:40" lat="11" lon="77" tz="5.5"]

Date Format — What PHP Developers Need to Know

<?php
// Convert Y-m-d to DD/MM/YYYY (what the API expects)
function to_api_date(string $ymd): string {
    $dt = DateTime::createFromFormat('Y-m-d', $ymd);
    return $dt ? $dt->format('d/m/Y') : $ymd;
}

// Convert a PHP date picker value
$dob = to_api_date($_POST['birth_date']); // '1977-10-01' → '01/10/1977'

Start building your PHP astrology project today

500 free API calls. Works with any PHP version 7.4+. No Composer required for the basic integration.

Get free API key →WordPress plugin →