You need to enable JavaScript to use this application.
POST استعلام

Get Address From Zipcode API

This API resolves an Iranian zipcode to a detailed postal address. A successful inquiry deducts the configured tariff from the caller's wallet and returns street, city, district, and additional address attributes provided by Sepal Yar.

POST /api/services/address-from-zipcode/
نیاز به احراز هویت Token 60 requests/minute

مستندات

Overview

Overview

The Get Address From Zipcode API resolves an Iranian postal code to a structured address using Sepal Yar address data. Typical use cases include risk assessment, KYC address verification, and enriching customer profiles with accurate location details.

On each successful call, the service:

  • Validates the zipcode format
  • Queries Sepal Yar for detailed address attributes
  • Returns district, province, street, house number, and optional floor
  • Deducts the service tariff from the authenticated wallet
  • Stores a unique request_ref for auditing

Authentication

Authentication

This endpoint requires both a token and the user's unique code header.

Authorization: Token YOUR_AUTH_TOKEN
X-Unique-Code: YOUR_UNIQUE_CODE

If either header is missing or invalid, a 401 Unauthorized response is returned.

Request Format

Request Format

Send a POST request with a JSON body:

{
  "zipcode": "8831855356"
}

The zipcode may be provided with or without separators; the service strips whitespace and dashes automatically.

Response Format

Response Format

Successful responses include:

  • success: Boolean flag
  • request_ref: Unique request reference
  • amount: Deducted tariff in Rials
  • response_data: Address attributes in the response
  • response_time_ms: Upstream latency in milliseconds
  • error_message: Always null for successful calls

Failure responses return success: false and an error object with details.

Error Handling

Error Handling

The API uses standard HTTP status codes:

  • 400 Bad Request: Validation errors
  • 401 Unauthorized: Missing/invalid auth headers
  • 402 Payment Required: Insufficient wallet balance
  • 422 Unprocessable Entity: Sepal Yar validation failure
  • 502 Bad Gateway: Unexpected Sepal Yar outage or timeout

Always inspect the error payload for detailed error messages returned by Sepal Yar.

Best Practices

Best Practices

  • Pre-validate zipcode inputs on the client to reduce 400 responses.
  • Cache resolved addresses where appropriate to minimise repeated calls.
  • Monitor wallet balance and alert users before reaching zero.
  • Log request_ref values to reconcile billing.
  • Implement retry logic with exponential backoff for transient 5xx errors.

پارامترهای درخواست

پارامتر نوع اجباری توضیحات مثال
zipcode String اجباری Iranian postal code (zipcode). Accepts 5 or 10 numeric characters. Whitespace or dash separators are removed automatically.
اعتبارسنجی: Must be numeric. Accepted lengths: 5 or 10 digits.
8831855356

مثال‌های کد

Python Example

Example using Python requests library.

import requests

url = "https://inquiry.sepal.ir/api/services/address-from-zipcode/"
headers = {
    "Authorization": "Token YOUR_AUTH_TOKEN",
    "X-Unique-Code": "YOUR_UNIQUE_CODE",
    "Content-Type": "application/json",
}
payload = {
    "zipcode": "8831855356"
}

response = requests.post(url, json=payload, headers=headers)
print(response.json())
C# Example

Example using C# HttpClient.

using System;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;

class Program
{
    static async Task Main()
    {
        var client = new HttpClient();
        client.DefaultRequestHeaders.Add("Authorization", "Token YOUR_AUTH_TOKEN");
        client.DefaultRequestHeaders.Add("X-Unique-Code", "YOUR_UNIQUE_CODE");

        var payload = new
        {
            zipcode = "8831855356"
        };

        var json = JsonSerializer.Serialize(payload);
        var content = new StringContent(json, Encoding.UTF8, "application/json");

        var response = await client.PostAsync(
            "https://inquiry.sepal.ir/api/services/address-from-zipcode/",
            content
        );

        var result = await response.Content.ReadAsStringAsync();
        Console.WriteLine(result);
    }
}
PHP Example

Example using PHP cURL.

<?php

$url = "https://inquiry.sepal.ir/api/services/address-from-zipcode/";
$payload = [
    "zipcode" => "8831855356"
];

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    "Authorization: Token YOUR_AUTH_TOKEN",
    "X-Unique-Code: YOUR_UNIQUE_CODE",
    "Content-Type: application/json"
]);

$response = curl_exec($ch);
curl_close($ch);

echo $response;
?>
cURL Example

Command-line cURL example.

curl -X POST "https://inquiry.sepal.ir/api/services/address-from-zipcode/" \
  -H "Authorization: Token YOUR_AUTH_TOKEN" \
  -H "X-Unique-Code: YOUR_UNIQUE_CODE" \
  -H "Content-Type: application/json" \
  -d '{
    "zipcode": "8831855356"
  }'

فرمت پاسخ

200
پاسخ موفق

Successful response when the zipcode is resolved successfully.

ساختار پاسخ:
{
  "amount": "integer",
  "success": "boolean",
  "request_ref": "string",
  "error_message": "null",
  "response_data": {
    "no": "string",
    "floor": "string",
    "ref_id": "string",
    "street": "string",
    "district": "string",
    "province": "string",
    "zip_code": "string",
    "locality_code": "integer",
    "operation_time": "integer (epoch milliseconds)"
  },
  "response_time_ms": "integer"
}
مثال پاسخ:
{
  "amount": 20000,
  "success": true,
  "request_ref": "NEGL1X9THOY4GZDXABUBXNZTA8VH0XSW",
  "error_message": null,
  "response_data": {
    "no": "34",
    "floor": "1",
    "ref_id": "0f4b35f3-c28f-4d7c-a135-b2a8977f1f0b",
    "street": "محله فدائیان اسلام ، کوچه ((کانال))، کوچه سی ام [30]",
    "district": "فرخشهر",
    "province": "چهارمحال وبختیاری",
    "zip_code": "8831855356",
    "locality_code": 0,
    "operation_time": 1762626604346
  },
  "response_time_ms": 2909
}
400
خطا

Bad request - Invalid or missing zipcode parameter.

ساختار پاسخ:
{
  "error": {
    "code": "string (optional)",
    "errors": "list (optional)",
    "details": "object (optional)",
    "message": "string"
  },
  "success": "boolean"
}
مثال پاسخ:
{
  "error": {
    "code": "INVALID_PARAMETERS",
    "details": {
      "zipcode": [
        "Ensure this field has at least 5 characters."
      ]
    },
    "message": "Invalid input parameters."
  },
  "success": false
}
401
خطا

Unauthorized - Authentication headers missing or invalid.

ساختار پاسخ:
{
  "error": {
    "code": "string (optional)",
    "errors": "list (optional)",
    "details": "object (optional)",
    "message": "string"
  },
  "success": "boolean"
}
مثال پاسخ:
{
  "error": {
    "code": "AUTHENTICATION_ERROR",
    "message": "Authentication credentials were not provided."
  },
  "success": false
}
402
خطا

Payment Required - Insufficient wallet balance.

ساختار پاسخ:
{
  "error": {
    "code": "string (optional)",
    "errors": "list (optional)",
    "details": "object (optional)",
    "message": "string"
  },
  "success": "boolean"
}
مثال پاسخ:
{
  "error": {
    "code": "INSUFFICIENT_BALANCE",
    "message": "Insufficient wallet balance."
  },
  "success": false
}
422
خطا

Sepal Yar validation error (returned as-is).

ساختار پاسخ:
{
  "error": {
    "code": "string (optional)",
    "errors": "list (optional)",
    "details": "object (optional)",
    "message": "string"
  },
  "success": "boolean"
}
مثال پاسخ:
{
  "error": {
    "message": "SERVICE_FAILURE"
  },
  "success": false
}
502
خطا

Bad Gateway - Sepal Yar service error or unexpected exception.

ساختار پاسخ:
{
  "error": {
    "code": "string (optional)",
    "errors": "list (optional)",
    "details": "object (optional)",
    "message": "string"
  },
  "success": "boolean"
}
مثال پاسخ:
{
  "error": {
    "code": "SERVICE_ERROR",
    "message": "خطا در فراخوانی سرویس: service timeout."
  },
  "success": false
}