Skip to content

API Integration Guide

Welcome! This guide will help you connect your website or application with the Dokha.pk API in a simple and secure way.

1. Get Your API Key

  1. Log in to your Dokha.pk account.
  2. Go to the Developer / API Access page.
  3. Click Generate API Key.
  4. Copy your key and store it in a safe place (password manager or environment variable).
    ⚠️ Never share this key publicly or paste it into client-side code (JavaScript/HTML).

2. How It Works

  • Your website/app will send a query (like a phone number) to the API.
  • Dokha.pk will return a JSON response (structured data).
  • You can display this data however you like (tables, widgets, dashboards, etc).

3. Integration Options

Option A: Server-to-Server (Recommended )

Best for backend apps or secure environments.
Example in PHP:

$ch = curl_init(‘https://dokha.pk/wp-json/dokha/v1/search?query=03001234567’); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, [‘Authorization: Bearer YOUR_API_KEY’]); $response = curl_exec($ch); echo $response;

Example in Python:

import requests url = “https://dokha.pk/wp-json/dokha/v1/search” headers = {“Authorization”: “Bearer YOUR_API_KEY”} r = requests.get(url, params={“query”: “03001234567”}, headers=headers) print(r.json())

4. WordPress Example

If your site runs on WordPress, add a custom REST route that forwards requests securely.

functions.php:

add_action(‘rest_api_init’, function(){ register_rest_route(‘dokha/v1′,’/search’,[ ‘methods’=>’GET’, ‘callback’=> function($req){ $q = sanitize_text_field($req->get_param(‘q’)); $res = wp_remote_get(‘https://dokha.pk/wp-json/dokha/v1/search?query=’ . $q, [ ‘headers’=>[‘Authorization’=>’Bearer ‘ . YOUR_API_KEY] ]); return json_decode(wp_remote_retrieve_body($res), true); }, ‘permission_callback’ => ‘__return_true’, ]); });

Frontend call:

fetch(‘/wp-json/dokha/v1/search?q=03001234567’) .then(r => r.json()).then(console.log);

5. Best Practices (Very Important )

  • Keep your API key private. Store it in environment variables or server config.
  • Never expose the key in client-side code (HTML, JavaScript, mobile apps).
  • Use HTTPS to prevent data interception.
  • Add caching on your proxy for better performance.
  • Rotate API keys regularly for security.
  • Handle errors gracefully (401 = invalid key, 429 = too many requests).

That’s it! You’re now ready to integrate the Dokha.pk API into your own platform.