0572.html 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <!DOCTYPE html>
  2. <html lang="en" xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <title>Quick Overview of Proxmox VE REST API</title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  6. <meta charset="UTF-8">
  7. <meta name="keywords" content="How To,Tutorial,i12bretro,Proxmox,Proxmox VE,Hypervisor,API,Application Programming Interface,Linux,Debian,Postman">
  8. <meta name="author" content="i12bretro">
  9. <meta name="description" content="Quick Overview of Proxmox VE REST API">
  10. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  11. <script type="text/javascript" src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
  12. <script type="text/javascript">
  13. $(function(){
  14. $('textarea').each(function(i,e){
  15. theTextarea = $(this);
  16. theTextarea.height((theTextarea[0].scrollHeight-5) +'px');
  17. });
  18. $('li').each(function(i,e){
  19. if(!$(this).hasClass('noCheckbox')){
  20. var uuid = 'li_' + Math.floor(Math.random() * Math.floor(1000000)).toString() + '_' + i.toString();
  21. $(this).contents().wrap('<span id="'+ uuid +'"><label for="cb_'+ uuid +'"></label></span>');
  22. $(this).prepend('<input type="checkbox" class="completeBox" id="cb_' + uuid +'" rel="'+ uuid +'" />')
  23. }
  24. });
  25. $('code,div.codeBlock,textarea.codeBlock').each(function(i,e){
  26. theElement = $(this);
  27. var lines = theElement.html().split("\n");
  28. theElement.empty();
  29. for(l=0;l<lines.length;l++){
  30. if($.trim(lines[l]) != '' && $.trim(lines[l]).substr(0,1) != '#' && $.trim(lines[l]).indexOf(' #') == -1 && lines[l].substr(0, 4).toUpperCase() != 'REM '){
  31. theElement.append('<input type="image" src="images/clipboard.png" value="" class="copy-text" rel="copy_'+ i +'_'+ l +'" data-clipboard-text="'+ $.trim(lines[l].replace(/"/g, '&quot;')) +'" /><span id="copy_'+ i +'_'+ l +'">'+ lines[l] +'</span>');
  32. } else {
  33. theElement.append(lines[l]);
  34. }
  35. }
  36. });
  37. $(document).on('click','input.copy-text',function(){
  38. theButton = $(this);
  39. $('input.copy-text').attr('src','images/clipboard.png');
  40. $('span.copy-animation,span.copy-animation-ps').removeClass('copy-animation copy-animation-ps');
  41. try {
  42. if($('#'+ theButton.attr('rel')).parent('div').hasClass('PS')){
  43. $('#'+ theButton.attr('rel')).addClass('copy-animation-ps');
  44. } else if($('#'+ theButton.attr('rel')).parent('div').hasClass('CMD')){
  45. $('#'+ theButton.attr('rel')).addClass('copy-animation-cmd');
  46. } else {
  47. $('#'+ theButton.attr('rel')).addClass('copy-animation');
  48. }
  49. navigator.clipboard.writeText(theButton.data('clipboard-text').replace(/<[^>]*>?/gm, ''));
  50. theButton.attr('src','images/clipboard_active.png');
  51. } catch(err) {
  52. }
  53. return false;
  54. });
  55. $(document).on('click','input.completeBox',function(){
  56. theBox = $(this);
  57. $('#'+ theBox.attr('rel')).addClass('strikethrough');
  58. theBox.prop('disabled',true);
  59. theBox.parent('li').prevAll().each(function(i,e){
  60. theLI = $(this);
  61. if(theLI.find('input[type=checkbox]').not(':checked')){
  62. $('#'+ theLI.find('input[type=checkbox]').attr('rel')).addClass('strikethrough');
  63. theLI.find('input[type=checkbox]').prop('checked',true).prop('disabled',true);
  64. }
  65. });
  66. });
  67. if(window.self !== window.top){
  68. window.parent.$('iframe.stepsFrame').height((this['scrollingElement']['scrollHeight']+20) +'px');
  69. }
  70. });
  71. </script>
  72. <link href="css/steps.css" rel="stylesheet" type="text/css" />
  73. </head>
  74. <body>
  75. <div id="gridContainer">
  76. <div class="topMargin"></div>
  77. <div id="listName" class="topMargin">
  78. <h1>Quick Overview of Proxmox VE REST API</h1>
  79. </div>
  80. <div></div>
  81. <div id="content">
  82. <h2>Creating An API User</h2>
  83. <ol>
  84. <li>Log into the Proxmox VE web UI</li>
  85. <li>Select Datacenter from the left navigation menu</li>
  86. <li>Select Users from the left sub-navigation menu</li>
  87. <li>Click the Add button at the top of the main content area</li>
  88. <li>Enter the Username API, set the Realm to Proxmox VE authentication server and set and confirm a password &gt; Click Add</li>
  89. <li>Select API Tokens from the left sub-navigation menu</li>
  90. <li>Select API@pve for the username</li>
  91. <li>Enter a secret key into the Token ID field &gt; Click Add
  92. <p><em>TIP: Use a random string generator to create a unique Token ID</em> <a href="https://www.random.org/passwords/?num=1&amp;len=24&amp;format=plain&amp;rnd=new" target="_blank">String Generator</a></p>
  93. </li>
  94. <li>Copy the displayed Token ID and Secret to a text document for use later</li>
  95. <li>Close the dialog</li>
  96. <li>Select Roles from the left sub-navigation menu</li>
  97. <li>Click the Create button at the top of the main content area</li>
  98. <li>Name the new role APIAdmin and select all available Privileges &gt; Click Create
  99. <p>NOTE: These permissions can be fine-tuned later<br />
  100. INFO: More information on each privilege can be found <a href="https://pve.proxmox.com/pve-docs/pve-admin-guide.html#pveum_permission_management" target="_blank">here</a></p>
  101. </li>
  102. <li>Select Permissions from the left sub-navigation menu</li>
  103. <li>Select the Add &gt; User permission at the top of the main content area</li>
  104. <li>Set the Path to /, select the API@pve user and set the Role to APIAdmin &gt; Click Add</li>
  105. </ol>
  106. <h2>Downloading Postman</h2>
  107. <p><em>Postman is an API platform for building and using APIs. Postman simplifies each step of the API lifecycle and streamlines collaboration so you can create better APIs&mdash;faster.</em> - <a href="https://postman.com" target="_blank">https://postman.com</a></p>
  108. <ol>
  109. <li>Download Postman <a href="https://github.com/portapps/postman-portable/releases" target="_blank">Download</a></li>
  110. <li>Extract or install Postman</li>
  111. <li>Launch Postman</li>
  112. <li>Click the Skip and go to app link at the bottom left of the splash screen</li>
  113. <li>Select File &gt; Settings from the top menu bar</li>
  114. <li>Disable SSL Certificate Verification and Send anonymous usage data to Postman &gt; Close the Settings dialog window</li>
  115. </ol>
  116. <h2>Proxmox API Authentication</h2>
  117. <ol>
  118. <li>In Postman, click the + next to the Overview tab to create a new HTTP request tab</li>
  119. <li>Complete the HTTP Request form as follows:
  120. <ul style="list-style-type: none;">
  121. <li>Method: POST</li>
  122. <li>URL: https://DNSorIP:8006/api2/json/access/ticket</li>
  123. <li>Body: x-www-form-urlencoded
  124. <ul>
  125. <li>username: API@pve</li>
  126. <li>password: &lt;API@pve Password&gt;</li>
  127. </ul>
  128. </li>
  129. </ul>
  130. </li>
  131. <li>Click the Send button</li>
  132. <li>From the response, copy the ticket value and CSRFPreventionToken values to a text document for use later</li>
  133. </ol>
  134. <h2>Proxmox Version API Call</h2>
  135. <ol>
  136. <li>In Postman, click the + next to the Overview tab to create a new HTTP request tab</li>
  137. <li>Click the Cookies link below the send button</li>
  138. <li>Type the API URL up to /json/, (ie https://DNSorIP:8006/api2/json/) &gt; Click Add</li>
  139. <li>Click Add Cookie</li>
  140. <li>Replace the Cookie_1 key with PVEAuthCookie</li>
  141. <li>Replace the value with the ticket value from authentication response, the result should look like
  142. <p>PVEAuthCookie=PVE:API@pve:611F9752::aXrYKYqiv8oV/MetlZl6FC40HSULSj4gt9EjDsTIwq+GXVXpkGyqvMlXqmGP6LP/rUYUgIKkSh9ioEhz91kR9/i+jDobDFIAtjBGLIP4yJVbxbtU6hfJL91YQNyYgvHqkPv4/W6EYWir5+LFQc3womgqVE9gKApk61J8zxFNTTjwh87HbMAtv12fvAqiICEqRMdqvE6ySJF5a8E+rOlqa46MlTbUTnzCbqPTY6tWBYHryy8WS8Typ3aSkOKecup18sCBtzqxnkm9bpws+f8vW9FdJV8eKnR+MbFLQtv/re5Cw/J7RpdvcQvMsZ0JLFWqnTaPgRzBc/mM7xZBKeCiSA==</p>
  143. </li>
  144. <li>Click Save &gt; Close the Manage Cookies dialog window</li>
  145. <li>Complete the HTTP Request form as follows:
  146. <ul style="list-style-type: none;">
  147. <li>Method: GET</li>
  148. <li>URL: https://DNSorIP:8006/api2/json/version</li>
  149. <li>Headers:
  150. <ul>
  151. <li>CSRFPreventionToken: &lt;CSRFPreventionToken value from authentication response&gt;</li>
  152. </ul>
  153. </li>
  154. </ul>
  155. </li>
  156. <li>Click the Send button</li>
  157. <li>The response body should show details about the current Proxmox version</li>
  158. </ol>
  159. <h2>Proxmox Nodes API Call</h2>
  160. <ol>
  161. <li>In Postman, right click the /version HTTP request tab &gt; Duplicate Tab</li>
  162. <li>Change the URL to https://DNSorIP:8006/api2/json/nodes</li>
  163. <li>Click the Send button</li>
  164. <li>The response body should show details about the available Proxmox node(s)</li>
  165. </ol>
  166. <h2>Proxmox Node Status API Call</h2>
  167. <ol>
  168. <li>In Postman, right click the /version HTTP request tab &gt; Duplicate Tab</li>
  169. <li>Change the URL to https://DNSorIP:8006/api2/json/nodes/&lt;node name&gt;/status</li>
  170. <li>Click the Send button</li>
  171. <li>The response body should show details about the selected Proxmox node</li>
  172. </ol>
  173. <p>Simple PHP API Communication Demo <a href="https://raw.githubusercontent.com/i12bretro/tutorials/main/_Downloads/proxmox_api.php" target="_blank">Download</a></p>
  174. <p>Proxmox VE API Wiki: <a href="https://pve.proxmox.com/wiki/Proxmox_VE_API" target="_blank">https://pve.proxmox.com/wiki/Proxmox_VE_API</a><br />
  175. Proxmox VE Visual API Reference: <a href="https://pve.proxmox.com/pve-docs/api-viewer/index.html" target="_blank">https://pve.proxmox.com/pve-docs/api-viewer/index.html</a></p>
  176. </div>
  177. </div>
  178. </body>
  179. </html>