MyAstro API Developer Guides

Read the MyAstro API developers guides to learn how to authenticate API using different methods generate kundali instantly, handle API Errors properly in your code and follow best practices for getting best results from our Astrology APIs. properly in codes and best practices by which user find maximum better output by our Astrology APIs.

Generate Kundali by MyAstro API

This guide explains a step-by-step solution to instantly generate a kundali for any birth details using MyAstro API. You will learn how to send input data and authenticate API requests and receive the Kundali API JSON response.

In this guide, we will call two APIs together to get the Kundali D1 chart and basic kundali details in a single response You can use the example code provided in this guide and it should work for you.

Kundali data API Example with Response


<?php

// API URL
$apiUrl = "https://json.api.myastro.online/kundalidata";

// Input Data
$data = [
    "date" => "01/01/2026",
    "time" => "10:30",
    "lat"  => 28.6139,
    "long" => 77.2090,
    "tz"   => 5.5
];

// Convert array to JSON
$jsonData = json_encode($data);

// cURL Request
$ch = curl_init($apiUrl);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);

// Headers
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    "Content-Type: application/json",
    "Authorization: Bearer YOUR_API_KEY"
]);

// Execute Request
$response = curl_exec($ch);

// Error Check
if(curl_errno($ch)){
    echo "Curl Error: " . curl_error($ch);
} else {

    $result = json_decode($response, true);

    // Print Full Response
    print_r($result);

    // Example Access
    echo "<br><br>";
    echo "Sun Rashi: " . $result['data']['kundalidata']['sy']['rashi'];
}

curl_close($ch);

?>

  

//Example Response
{
  "data": {
    "kundalidata": {
      "sy": {
        "rashi": 1,
        "degree": 10.25,
        "speed": 1.2,
        "bhav": 5,
        "dir": "D"
      },
      "ch": {
        "rashi": 2,
        "degree": 15.40,
        "speed": 12.4,
        "bhav": 6,
        "dir": "D"
      }
    }
  }
}

  

Kundali D1 Chart API Example


<?php

// API URL
$apiUrl = "https://json.api.myastro.online/kundaliimg";

// Input Data
$data = [
    "date" => "01/01/2026",
    "time" => "10:30",
    "lat"  => 28.6139,
    "long" => 77.2090,
    "tz"   => 5.5
];

// Convert array to JSON
$jsonData = json_encode($data);

// cURL Request
$ch = curl_init($apiUrl);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);

// Headers
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    "Content-Type: application/json",
    "Authorization: Bearer YOUR_API_KEY"
]);

// Execute Request
$response = curl_exec($ch);

// Error Check
if(curl_errno($ch)){
    echo "Curl Error: " . curl_error($ch);
} else {

    $result = json_decode($response, true);

    // Base64 Image
    $base64Image = $result['data']['kundaliimg']['img'];

    // Display Kundali Image
    echo '<img src="data:image/png;base64,' . $base64Image . '" />';
}

curl_close($ch);

?>

  

//Example Response
{
  "data": {
    "kundaliimg": {
      "img": "iVBORw0KGgoAAAANSUhEUgAA..."
    }
  }
}

  

Authentication Guide

This Authentication Guide will teach you how to securely authenticate requests to the MyAstro Astrology API. API url should be requested with POST Method.

Authentication Using Authorization Header

Every request on API endpoints should have Authorization header with API_key. Our system alway prefers Authorization: Bearer API_KEY to authenticate our api end points request but you may also use Authorization: API_KEY but if you see our official Myastro API sdk we only have first method as authentication.

Authentication Using x-api-key Header

We also authenticate your request with header x-api-key: API_KEY but we recommend use this method only when there are restrictions to use Authorization header with Bearer. If the Authorization header is present, the API authenticates the request using it. Otherwise, the API backend checks for x-api-key header.

Authorization header with Bearer may give fast response instead of other api validation header. We always wanted a secure strict system with easy to access for authenticated api call.

Additional User Validation

Users may enable additional validation by providing additional header X-User-ID: YOUR_MYASTRO_USER_ID. User provided X-User-ID header validate first for existence but this may put extra validation weight on simple api call due to this you may need special permission from support.

API Security

User should always use secure HTTPS API endpoints. API key must be stored securely on server and API keys should never be exposed publicly or used in frontend JavaScript. You should always prefer change API key time to time atleast in a year for better account security.

Rate Limits

Currently, no fixed rate limits are enforced. we expect our users to avoid abusive or excessive automated requests.401 is reserved status code for API authentication Failure

Handling Authentication Failures

Applications should properly handle authentication errors and retry requests only with valid credentials. Read the API Errors Guide to understand all API error responses.

API Errors Guide

MyAstro API Errors Guide explains API Response status codes for developers. This guide helps developers understand API response and troubleshoot request issues. API error describe the response status returned by API endpoints. Status 200 indicates a successful API response.

200 ok

Request was successful and API returned the expected response data.

204 Account warning

Request reach to API endpoints but account restriction may impose in future due to some violations. Users should treat this error as a priority and discuss it with API account manager.

400 Bad Request

API input required parameters are missing or not in supported format as documented in API.

401 Unauthorized

API key is missing or invalid. 401 error status response may be related to unsupported Authentication method or User Account issue.

402 Resource overused

API resource usage limit exceeded. 402 error occurs in rare circumtances only after user has not added credits for a long time.

404 Resource not found

Requested API endpoint or resource was not found.

426 Upgrade required

This error indicates that the application should upgrade to a newer API version. Developers usually do not need to handle this error unless API versioning is enabled.

500 api internal error

Unexpected server-side API error occurred.

525 req not supported

API request have in very bad shape may get this error.

524 Account related issue

This is intermittent error if account have limited access to astrology APIs.

511 Account Block

MyAstro API Account Permanent block due to security or policy violations.

Best Practices Guide

In this guide we will learn best practices for usingMyastro APIs efficently and securly.

Secure API Key

Api keys should always be stored privately and used only in backend requests to our servers. Never expose your API key in request URLS, either intentionally or accidentally because URLs may be cached by browser, proxies, server or network routing systems.

Use POST Method

Our API supports only POST requests other HTTP request method may be rejected or return an unsupported request response.

Secure Communication

Always verify SSL certificates when making API requests SSL verification ensure secure sending and receiving of data between your application and the API endpoints.

Use Recommended Authentication Method

You should use a single authentication method that is best suited for your system. Authentication: Bearer TOKEN is recommended method that ensure fully compatibility with all API endpoints and future updates. However, you may choose any supported authentication method based on your requirements. You can read the Authentication Guide to learn more.

API Response Caching with c-id

Every Successful API response includes a unique c-id for each request You can use this ID to cache API response to repeated resource usage for identical requests and avoid unnecessary request to API servers.

API Usage Policy

Users should respect API usage based on industry-standard practices and use API endpoints responsibly. Currently, MyAstro API servers do not enforce fixed rate limit restrictions for users. However, we expect genuine and abuse-free usage of all API endpoints to maintain platform stability and service quality for everyone. If repeated security violations or abusive API activity are detected, the user account may be permanently blocked from accessing API services.

API Versioning

API Endpoint may have different version version parameter is optional and provide latest api response if version parameter not present. system api call only should attach prefer version for api response if project highly depends on some response parameters. API response also have included version numbering to developers facility

API endpoints may support different versions. The version parameter is optional, and if not provided, the API will return the latest supported response version. System API calls should preferably include the version parameter to ensure consistent API responses. All API responses also include version numbering for developer convenience and compatibility.

Monitoring API Credit Usage

API endpoints include a special credit usage call that provides remaining API credit information. This feature is disabled by default and must be activated from the dashboard by enabling the Credit Call plugin. The special credit call is useful for users who want to monitor API credits during automation workflows or for personal usage tracking. Credit usage access is activated instantly once the dashboard Credit Call plugin is enabled.