Use the Add Recipes API to add a recipe to the Virtualizor panel. Recipes are predefined bash scripts that are created by admin for endusers. Only the activated recipes are visible to the enduser. These recipes can be executed on the VPS during their creation. Recipes can also be applied while the VPS is running, however you need to stop then start the VPS for the execution of the recipe to take place. The API response will contain "done" as "1" if the recipe has been added successfully. Newly added recipes are active by default and are visible to the enduser.
HTTP Request
https://hostname:4085/index.php/act=addrecipe
Parameters
Name | Method | Value | Description | Required |
---|---|---|---|---|
act | GET | addrecipe | The action will return done as 1 | Yes |
recipe_name | POST | text | Name of the recipe | Yes |
recipe_script | POST | text | Recipe script to be executed | Yes |
desc | POST | text | Description given to the recipe | No |
recipe_logo | POST | text | The logo url for the recipe | No |
shell | POST | text | Provide the shell type using which the recipe should be executed (Since 3.1.3 version) | No |
Valid shell types (Since v3.1.3)
Value | Description |
---|---|
Default(sh shell) | #!/bin/sh |
Bash | #!/bin/bash |
Ksh | #!/bin/ksh |
Zsh | #!/bin/zsh |
Custom shells can be added in /usr/local/virtualizor/globals.php file append values in array variable globals['shells'].
$globals['shells'] = array('python' => '#!/usr/bin/python');
Sample Code
<?php
require_once('/usr/local/virtualizor/sdk/admin.php');
$key = 'your_api_key';
$pass = 'your_api_pass';
$ip = 'your_server_ip';
$admin = new Virtualizor_Admin_API($ip, $key, $pass);
$post = array();
$post['recipe_name'] = 'test recipe';
$post['recipe_logo'] = '';
$post['recipe_script'] = 'echo "This is your test recipe" ';
$post['desc'] = 'This is the description for test recipe';
$post['shell'] = 'Bash';
$output = $admin->add_recipes($post);
print_r(json_encode($output));
?>
Output
{
"title": "Add Recipe",
"done": 7, //Recipe ID
"done_msg": "The Recipe has been added",
"timenow": 1536152422,
"time_taken": "0.219"
}