PHPackages                             ancalagon/netbox - 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. ancalagon/netbox

ActiveLibrary[API Development](/categories/api)

ancalagon/netbox
================

High Level Netbox API interface to handle objects like virtual machine, ip addresses, ...

0.0.9(1mo ago)075MITPHPPHP ^8.5

Since Feb 7Pushed 1mo agoCompare

[ Source](https://github.com/bmairlot/netbox)[ Packagist](https://packagist.org/packages/ancalagon/netbox)[ RSS](/packages/ancalagon-netbox/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (5)Versions (10)Used By (0)

ancalagon/netbox
================

[](#ancalagonnetbox)

A PHP library providing high-level object-oriented wrappers around the [NetBox](https://netbox.dev/) REST API.

Each NetBox resource is represented as a PHP class with full CRUD support, fluent setters, and automatic hydration from API responses.

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

[](#requirements)

- PHP 8.5+
- `ext-json`
- `ext-curl`

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

[](#installation)

```
composer require ancalagon/netbox
```

Configuration
-------------

[](#configuration)

The library requires three environment variables to connect to your NetBox instance:

```
export NETBOX_URL_PREFIX="https://netbox.example.com/api"
export NETBOX_KEY="your-key-prefix"
export NETBOX_TOKEN="your-token-value"
```

The API token is assembled as `nbt_{NETBOX_KEY}.{NETBOX_TOKEN}`.

Usage
-----

[](#usage)

### Virtual Machines

[](#virtual-machines)

```
use Ancalagon\Netbox\VirtualMachine;

// Create a VM
$vm = new VirtualMachine();
$vm->setName('web-server-01')
   ->setStatus('active')
   ->setCluster('1')
   ->setVcpus(4)
   ->setMemory(8192)
   ->setDisk(100);
$vm->add();

echo $vm->getId(); // NetBox-assigned ID

// Load an existing VM by name
$vm = new VirtualMachine();
$vm->setName('web-server-01');
$vm->load();

// Load by ID
$vm = new VirtualMachine();
$vm->setId('42');
$vm->load();

// Update (PATCH)
$vm->setMemory(16384);
$vm->update();

// Replace (PUT)
$vm->edit();

// List with filters
$vm = new VirtualMachine();
$results = $vm->list(['cluster_id' => '1', 'status' => 'active']);

// Delete
$vm->delete();
```

### Clusters

[](#clusters)

```
use Ancalagon\Netbox\ClusterType;
use Ancalagon\Netbox\ClusterGroup;
use Ancalagon\Netbox\Cluster;

// Create a cluster type and cluster
$ct = new ClusterType();
$ct->setName('VMware')->setSlug('vmware');
$ct->add();

$cluster = new Cluster();
$cluster->setName('prod-cluster')
        ->setType($ct->getId())
        ->setStatus('active');
$cluster->add();
```

### Devices

[](#devices)

```
use Ancalagon\Netbox\DeviceType;
use Ancalagon\Netbox\DeviceRole;
use Ancalagon\Netbox\Device;

// Create a device role
$role = new DeviceRole();
$role->setName('Server')->setSlug('server');
$role->add();

// Create a device type (requires manufacturer)
$dt = new DeviceType();
$dt->setManufacturer($manufacturerId)
   ->setModel('PowerEdge R640')
   ->setSlug('poweredge-r640');
$dt->add();

// Create a device
$device = new Device();
$device->setName('srv-01')
       ->setDeviceType($dt->getId())
       ->setRole($role->getId())
       ->setSite($siteId)
       ->setStatus('active');
$device->add();
```

### IP Addresses

[](#ip-addresses)

```
use Ancalagon\Netbox\IpAddress;

// Create an IP address
$ip = new IpAddress();
$ip->setAddress('192.168.1.10/24')
   ->setStatus('active')
   ->setDnsName('web-server-01.example.com');
$ip->add();

// Assign to a VM interface
$ip->assignToVmInterface('15');

// Assign to a physical device interface
$ip->assignToInterface('23');

// List IPs on a VM interface
$ip = new IpAddress();
$results = $ip->listByVmInterface('15');

// Unassign
$ip->unassign();
```

### VLANs

[](#vlans)

```
use Ancalagon\Netbox\Vlan;

$vlan = new Vlan();
$vlan->setVid(100)
     ->setName('Management')
     ->setStatus('active')
     ->setDescription('Management VLAN');
$vlan->add();

// Load by VID
$vlan = new Vlan();
$vlan->setVid(100);
$vlan->load();
```

### Prefixes

[](#prefixes)

```
use Ancalagon\Netbox\Prefix;

$prefix = new Prefix();
$prefix->setPrefix('10.0.0.0/24')
       ->setStatus('active')
       ->setDescription('Server network');
$prefix->add();
```

### VM Interfaces

[](#vm-interfaces)

```
use Ancalagon\Netbox\VirtualMachineInterface;

// Create an interface on a VM
$iface = new VirtualMachineInterface();
$iface->setVirtualMachine('42')
      ->setName('eth0')
      ->setEnabled(true)
      ->setMtu(1500);
$iface->add();

// VLAN management
$iface->assignUntaggedVlan('100');
$iface->addTaggedVlan('200');
$iface->addTaggedVlan('300');
$iface->removeTaggedVlan('200');

// List all interfaces for a VM
$iface = new VirtualMachineInterface();
$results = $iface->listByVm('42');
```

### Physical Network Interfaces

[](#physical-network-interfaces)

```
use Ancalagon\Netbox\NetworkInterface;

$iface = new NetworkInterface();
$iface->setDevice('5')
      ->setName('GigabitEthernet0/1')
      ->setType(['value' => '1000base-t', 'label' => '1000BASE-T'])
      ->setEnabled(true);
$iface->add();

// List all interfaces for a device
$results = $iface->listByDevice('5');
```

### MAC Addresses

[](#mac-addresses)

```
use Ancalagon\Netbox\MacAddress;

$mac = new MacAddress();
$mac->setMacAddress('00:1A:2B:3C:4D:5E')
    ->setDescription('Primary NIC');
$mac->add();

// Load by MAC
$mac = new MacAddress();
$mac->setMacAddress('00:1A:2B:3C:4D:5E');
$mac->load();
```

### Owners and Owner Groups

[](#owners-and-owner-groups)

```
use Ancalagon\Netbox\OwnerGroup;
use Ancalagon\Netbox\Owner;

// Create an owner group
$group = new OwnerGroup();
$group->setName('Infrastructure Team')
      ->setDescription('Manages core infrastructure');
$group->add();

// Create an owner in that group
$owner = new Owner();
$owner->setName('Network Ops')
      ->setGroup($group->getId())
      ->setDescription('Network operations team')
      ->setUsers([1, 2, 3]);
$owner->add();

// List owners in a group
$owner = new Owner();
$results = $owner->listByGroup($group->getId());
```

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

[](#error-handling)

All API errors are wrapped in `Exception`:

```
use Ancalagon\Netbox\Exception;

try {
    $vm = new VirtualMachine();
    $vm->setName('test-vm');
    $vm->load();
} catch (Exception $e) {
    echo $e->getMessage();
}
```

Testing
-------

[](#testing)

Integration tests run against a live NetBox instance:

```
vendor/bin/phpunit
```

CRUD Method Reference
---------------------

[](#crud-method-reference)

Every entity class provides the same set of operations:

MethodHTTP VerbDescription`add()`POSTCreate a new resource`load()`GETFetch by ID or unique field(s)`list()`GETList resources with optional filters`edit()`PUTFull replacement of a resource`update()`PATCHPartial update of a resource`delete()`DELETERemove a resourceLicense
-------

[](#license)

MIT - see [LICENSE](LICENSE).

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance89

Actively maintained with recent releases

Popularity13

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 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 ~5 days

Total

9

Last Release

57d ago

PHP version history (2 changes)v0.0.1PHP ^8.4

v0.0.4PHP ^8.5

### Community

Maintainers

![](https://www.gravatar.com/avatar/c49406a0ccd1c1c6025d93ae54a9e8d22ef139a07eca2aa1ab7b8a00e5ab6a78?d=identicon)[bmairlot](/maintainers/bmairlot)

---

Top Contributors

[![bmairlot](https://avatars.githubusercontent.com/u/141404435?v=4)](https://github.com/bmairlot "bmairlot (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/ancalagon-netbox/health.svg)

```
[![Health](https://phpackages.com/badges/ancalagon-netbox/health.svg)](https://phpackages.com/packages/ancalagon-netbox)
```

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M480](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M272](/packages/twilio-sdk)[facebook/php-business-sdk

PHP SDK for Facebook Business

90821.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

74513.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

265103.1M454](/packages/google-gax)[google/common-protos

Google API Common Protos for PHP

173103.7M50](/packages/google-common-protos)

PHPackages © 2026

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