########################################################################### # CLOUD SERVER API DOCUMENTATION # # Name: createImage # Language: Python # # Description: this function creates a new image ########################################################################### from urllib.request import Request, urlopen import urllib import json #ID access to API TOKEN = "{YOUR_API_TOKEN}" # e.g.: "f03c3c76cc853ee690b879909c9c6f2a" url = "https://cloudpanel-api.ionos.com/v1" def _createImage(content): #Configure the request _command = url + "/images" _method = 'POST' request = Request(_command, data=content.encode(encoding='utf_8'), headers={'X-TOKEN':TOKEN, 'content-type':'application/json'}, method=_method) #Try to get the response try: response = urlopen(request) content = response.read() return (content.decode()) #Fetch error except urllib.error.URLError as e: return("Error " + str(e.code) + ":" + e.reason) #PARAMETERS name = 'My image' description = 'My image description' server_id = "1D9329FB64F6C308C12504DE3298C6FF" frequency = "WEEKLY" num_images = 10 data = json.dumps({'name':name, 'description':description, 'server_id':server_id, 'frequency':frequency, 'num_images':num_images}) #Create image print(_createImage(data))