Difference between revisions of "Update WHMCS database after the game server has been created"
(6 intermediate revisions by the same user not shown) | |||
Line 33: | Line 33: | ||
Thanks to [https://community.tcadmin.com/profile/12219-dennis/ Dennis] for this script. | Thanks to [https://community.tcadmin.com/profile/12219-dennis/ Dennis] for this script. | ||
− | In WHMCS create api credentials with UpdateClientProduct role. | + | In WHMCS create api credentials with the Products > UpdateClientProduct role. |
Update the API identifier and api secret. | Update the API identifier and api secret. | ||
Line 49: | Line 49: | ||
WHMCS_API_IDENTIFIER = "xxxxxxx" | WHMCS_API_IDENTIFIER = "xxxxxxx" | ||
WHMCS_API_SECRET = "yyyyyyy" | WHMCS_API_SECRET = "yyyyyyy" | ||
+ | WHMCS_API_ACCESS_KEY = "" | ||
− | query = urllib.urlencode({'action' : 'UpdateClientProduct', 'username' : WHMCS_API_IDENTIFIER, 'password' : WHMCS_API_SECRET, 'serviceid' : ThisService.BillingId, 'domain' : | + | query = urllib.urlencode({'action' : 'UpdateClientProduct', 'username' : WHMCS_API_IDENTIFIER, 'password' : WHMCS_API_SECRET, 'accesskey' : WHMCS_API_ACCESS_KEY, 'serviceid' : ThisService.BillingId, 'domain' : ThisService.ConnectionInfo, 'responsetype' : 'json'}) |
− | |||
try: | try: | ||
− | urllib2.urlopen(WHMCS_URL, data=query) | + | response = urllib2.urlopen(WHMCS_URL, data=query) |
+ | content = response.read() | ||
+ | Script.WriteToConsole(content) | ||
except urllib2.HTTPError, e: | except urllib2.HTTPError, e: | ||
Script.WriteToConsole(str(e.code)) | Script.WriteToConsole(str(e.code)) |
Latest revision as of 16:46, 22 September 2022
TCAdmin has a recurring task that can update your WHMCS database every few hours. If you need to update your database right after the game server has been created you can configure this global script for the after created event.
Update WHMCS by connecting to the database
Update the mysql_ variables with your WHMCS database connection.
Operating System: Any Description: Update WHMCS (SQL) Script Engine: IronPython Event: After Created Script:
import clr; import System; clr.AddReference("TCAdmin.DatabaseProviders.MySql"); clr.AddReference("TCAdmin.SDK"); from TCAdmin.DatabaseProviders.MySql import MySqlManager; from System import String; mysql_server="WHMCSIP"; mysql_user="WHMCSUSER"; mysql_password="WHMCSPASSWORD"; mysql_database="WHMCSDATABASE"; with MySqlManager() as mysql: mysql.UseMasterWebService = False; mysql.DisableReplication = True; mysql.Connect(String.Format("Data Source={0};User Id={1};Password={2};Database={3};Pooling=False;", mysql_server, mysql_user, mysql_password, mysql_database)); mysql.ExecuteNonQuery(String.Format("UPDATE tblhosting SET domain='{0}' WHERE id='{1}'", ThisService.ConnectionInfo, ThisService.BillingId));
Update WHMCS by connecting to the API
Thanks to Dennis for this script.
In WHMCS create api credentials with the Products > UpdateClientProduct role.
Update the API identifier and api secret.
Operating System: Any Description: Update WHMCS (API) Script Engine: IronPython Event: After Created Script:
import urllib2 import urllib WHMCS_URL = 'https://your-whmcs-site.com/includes/api.php' WHMCS_API_IDENTIFIER = "xxxxxxx" WHMCS_API_SECRET = "yyyyyyy" WHMCS_API_ACCESS_KEY = "" query = urllib.urlencode({'action' : 'UpdateClientProduct', 'username' : WHMCS_API_IDENTIFIER, 'password' : WHMCS_API_SECRET, 'accesskey' : WHMCS_API_ACCESS_KEY, 'serviceid' : ThisService.BillingId, 'domain' : ThisService.ConnectionInfo, 'responsetype' : 'json'}) try: response = urllib2.urlopen(WHMCS_URL, data=query) content = response.read() Script.WriteToConsole(content) except urllib2.HTTPError, e: Script.WriteToConsole(str(e.code))