PHPackages                             cosmotown/api-client - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. cosmotown/api-client

ActiveLibrary[API Development](/categories/api)

cosmotown/api-client
====================

PHP Library for Cosmotown Reseller API

0.0.3(2mo ago)07↓90.9%MITPHPPHP &gt;=8.1

Since Mar 31Pushed 2mo agoCompare

[ Source](https://github.com/NamingHive/cosmotown-api-client)[ Packagist](https://packagist.org/packages/cosmotown/api-client)[ RSS](/packages/cosmotown-api-client/feed)WikiDiscussions main Synced 4w ago

READMEChangelog (3)Dependencies (6)Versions (4)Used By (0)

Cosmotown API PHP Client
========================

[](#cosmotown-api-php-client)

A robust, strongly-typed PHP library for interacting with the [Cosmotown Reseller API](https://cosmotown.com).

This library provides an object-oriented wrapper around the Cosmotown endpoints, transforming raw JSON responses into explicitly typed Data Transfer Objects (DTOs) and handling common HTTP errors gracefully with custom exceptions.

Requirements
------------

[](#requirements)

- PHP 8.1 or higher
- [GuzzleHTTP](https://docs.guzzlephp.org/) `^7.8`

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require cosmotown/api-client
```

*(Note: If this is used as a local repository, ensure you dump autoloads first via `composer dump-autoload`.)*

Authentication &amp; Initialization
-----------------------------------

[](#authentication--initialization)

To use the API, you must have an API token generated from your Cosmotown Reseller dashboard. Cosmotown provides a Test Server Environment called "Sandbox". You can enable sandbox endpoints by passing `true` as the second argument to the `Client`.

```
use Cosmotown\Api\Client;

// For Production
$client = new Client('YOUR_PRODUCTION_API_KEY');

// For Sandbox (Testing environment)
$client = new Client('YOUR_SANDBOX_API_KEY', true);
```

Usage Examples
--------------

[](#usage-examples)

All responses are properly typed. IDEs with autocompletion (like PhpStorm or VS Code) will suggest all properties natively.

### 1. Get My Domains

[](#1-get-my-domains)

Fetches a list of domains currently registered to your reseller account.

```
$domains = $client->getMyDomains(limit: 50, offset: 0);

foreach ($domains as $domainEntry) {
    echo $domainEntry->domain . " expires on " . $domainEntry->expirationDate . "\n";
    // Accessible properties:
    // $domainEntry->autoBilling (bool)
    // $domainEntry->whoisPrivacy (bool)
    // $domainEntry->locked (bool)
    // $domainEntry->created (?string)
}
```

### 2. Search Domain Availability

[](#2-search-domain-availability)

Allows batch querying for domain name availability via **public RDAP**.

*Note: Since this leverages public RDAP infrastructure rather than Cosmotown internal pricing data, the `$price` attribute will currently be `null`.*

```
$searchQuery = [
    'exampledomain.com',
    'exampledomain2.net'
];

$results = $client->searchDomains($searchQuery);

foreach ($results as $result) {
    if ($result->isAvailable()) {
        echo "{$result->domain} is available!\n";
    } else {
        echo "Sorry, {$result->domain} is: {$result->message}\n";
    }
}
```

### 3. Get Domain Information

[](#3-get-domain-information)

Get detailed information about a single domain, including nameservers and contact information.

```
$domainInfo = $client->getDomainInfo('exampledomain.com');

echo "Nameservers: " . implode(", ", $domainInfo->nameservers) . "\n";
echo "Registrant Email: " . $domainInfo->contact->registrant->email . "\n";
echo "Billing Phone: " . $domainInfo->contact->billing->phone . "\n";
```

### 4. Register a Domain

[](#4-register-a-domain)

Register new domains specifying the registration length in years. *(This workflow is asynchronous on the Cosmotown side.)*

```
$items = [
    ['name' => 'newdomain1.com', 'years' => 1],
    ['name' => 'newdomain2.net', 'years' => 2]
];

// Provide an optional coupon code as the second parameter if you have one
$results = $client->registerDomains($items, 'MY_COUPON');

foreach ($results as $registration) {
    echo "{$registration->domain} Status: {$registration->status}\n";
}
```

### 5. Managing Domains (Nameservers &amp; Options)

[](#5-managing-domains-nameservers--options)

Update nameservers or toggle privacy, locks, and auto-billing.

```
// Update nameservers
$client->saveDomainNameservers('exampledomain.com', [
    'ns1.cosmotown.com',
    'ns2.cosmotown.com'
]);

// Change Domain Options
$success = $client->changeDomainOptions('exampledomain.com', [
    'enable_private_whois' => true,
    'lock_domain' => true,
    'enable_auto_billing' => false
]);

if ($success) {
    echo "Options successfully updated!";
}
```

### 6. Managing Domain Contacts

[](#6-managing-domain-contacts)

You can update the primary contacts linked to a domain.

```
use Cosmotown\Api\Models\Contact;
use Cosmotown\Api\Models\ContactSet;

// Create Contact entries
$registrant = new Contact(
    firstName: 'John',
    lastName: 'Doe',
    company: 'Acme Corp',
    phone: '+1.5555555555',
    extension: '',
    fax: '',
    city: 'New York',
    state: 'NY',
    zip: '10001',
    country: 'USA',
    email: 'john@example.com',
    address1: '123 Main St',
    address2: ''
);

// Map different contact roles (they can reuse the same Contact object)
$contactSet = new ContactSet(
    registrant: $registrant,
    administrative: $registrant,
    technical: $registrant,
    billing: $registrant
);

$updatedDomainInfo = $client->saveDomainContactInformation('exampledomain.com', $contactSet);
```

### 7. Actions: Transfer, Renew, and Auth Code

[](#7-actions-transfer-renew-and-auth-code)

```
// Renew Domains
$success = $client->renewDomains([
    ['name' => 'exampledomain.com', 'years' => 1]
]);

// Transfer Domains
$transferResult = $client->transferDomains([
    ['name' => 'transferme.com', 'authCode' => base64_encode('YourAuthCode123!')]
]);

// Get Auth/EPP Code for outbound transfers
$authCode = $client->getDomainAuthCode('exampledomain.com');
echo "EPP Code: " . $authCode;
```

Error Handling
--------------

[](#error-handling)

The library catches Guzzle requests and maps specific backend HTTP status codes to typed exceptions for easy granular `try/catch` control flow:

- `400 Bad Request` throws `Cosmotown\Api\Exceptions\ValidationException` (Unsuccessful request due to missing arguments)
- `403 Forbidden` throws `Cosmotown\Api\Exceptions\UnauthorizedException` (Invalid IP or Bad API Key)
- `429 Too Many Requests` throws `Cosmotown\Api\Exceptions\RateLimitException`
- `500 Server Error` throws `Cosmotown\Api\Exceptions\ServerException`

All of these extend the base `CosmotownException` class.

```
use Cosmotown\Api\Exceptions\RateLimitException;
use Cosmotown\Api\Exceptions\UnauthorizedException;
use Cosmotown\Api\Exceptions\CosmotownException;

try {
    $client->getMyDomains();
} catch (UnauthorizedException $e) {
    // API key revoked or bad IP
    echo "Auth failed: " . $e->getMessage();
} catch (RateLimitException $e) {
    // Wait before requesting again
    echo "Slow down: " . $e->getMessage();
} catch (CosmotownException $e) {
    // Generic catch-all API error
    echo "General API Error: " . $e->getMessage();
}
```

###  Health Score

34

—

LowBetter than 75% of packages

Maintenance84

Actively maintained with recent releases

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity35

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~4 days

Total

3

Last Release

83d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/157a447476a71b34729aa087d49ad1d0d992b7f44fb4254e20ddf55cf85657a7?d=identicon)[Ploxian](/maintainers/Ploxian)

---

Top Contributors

[![Ploxian](https://avatars.githubusercontent.com/u/221890979?v=4)](https://github.com/Ploxian "Ploxian (3 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/cosmotown-api-client/health.svg)

```
[![Health](https://phpackages.com/badges/cosmotown-api-client/health.svg)](https://phpackages.com/packages/cosmotown-api-client)
```

###  Alternatives

[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3661.2M46](/packages/tencentcloud-tencentcloud-sdk-php)[neuron-core/neuron-ai

The PHP Agentic Framework.

2.0k496.1k34](/packages/neuron-core-neuron-ai)[avalara/avataxclient

Client library for Avalara's AvaTax suite of business tax calculation and processing services. Uses the REST v2 API.

528.3M7](/packages/avalara-avataxclient)[eslazarev/wildberries-sdk

Wildberries OpenAPI clients (generated).

252.5k](/packages/eslazarev-wildberries-sdk)[files.com/files-php-sdk

Files.com PHP SDK

2478.1k](/packages/filescom-files-php-sdk)[aimeos/prisma

A powerful PHP package for integrating media related Large Language Models (LLMs) into your applications

1942.4k4](/packages/aimeos-prisma)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
