PHP code example of ocolin / netbox
1. Go to this page and download the library: Download ocolin/netbox library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
ocolin / netbox example snippets
// Manually creating for demonstration
$_ENV['NETBOX_API_HOST'] = 'http://localhost:8000';
$_ENV['NETBOX_API_AUTH'] = 2;
$_ENV['NETBOX_API_TOKEN'] = 'abcdefg';
$_ENV['NETBOX_API_KEY'] = 'abcdefg';
$netbox = new \Ocolin\Netbox\Netbox();
$netbox = new Ocolin\Netbox\Netbox(
config: new Ocolin\Netbox\Config(
host: 'http://localhost:8000',
auth: 2,
token: 'abcdefg',
key: 'abcdefg',
options: [
'verify' => true
]
)
);
$output = $netbox->get(
endpoint: '/api/dcim/sites/{id}/',
query: [ 'id' => 123 ]
);
$output = $netbox->post(
endpoint: '/api/dcim/sites/',
body: [
'name' => 'My Site',
'slug' => 'My-Site'
]
);
$output = $netbox->patch(
endpoint: '/api/dcim/sites/{id}/',
query: [ 'id' => 123 ],
body: [ 'name' => 'My Updated Name' ]
);
$output = $netbox->put(
endpoint: '/api/dcim/sites/{id}/',
query: [ 'id' => 123 ],
body: $newBody
);
$output = $netbox->delete(
endpoint: '/api/dcim/sites/{id}/',
query: [ 'id' => 123 ]
);
$output = $netbox->options( endpoint: '/api/dcim/sites/' );