Update IP and port in WHMCS

From TCAdmin 2.0 Documentation

When you create a game server with the billing API WHMCS does not get updated with the game server's IP and port. This can be updated using the built in recurring task or custom scripts.


Option 1 - Built in recurring task to update the WHMCS database every day

  • Go to Settings > Recurring Tasks.
  • Create a new recurring task and configure it to execute daily.
  • In the Actions tab add a new action of type "Sync Service IP with Billing".
  • Enter the information required to connect to your WHMCS database. If you use custom billing software you can specify a custom SQL update command.
  • When the task runs the product's domain field in WHMCS should have the game server's IP and port.

Option 2 - Custom recurring task to update the WHMCS database every day using the WHMCS API

  • In WHMCS create API credentials with the Products > UpdateClientProduct role.
  • In TCAdmin go to Settings > Global Game Scripts. Add the script below. Update WHMCS_URL, WHMCS_API_IDENTIFIER, WHMCS_API_SECRET with the correct values.
  • Go to Settings > Recurring Tasks. Add a recurring task with action = Execute a script and select the script that you created.
Operating System: Any
Description: Update WHMCS (API)
Script Engine: IronPython
Event: No Event
Allow Scheduling: Checked
Script:
import clr
import urllib2
import urllib

clr.AddReference("TCAdmin.GameHosting.SDK")
from TCAdmin.GameHosting.SDK.Objects import Service

WHMCS_URL = "https://your-whmcs-site.com/includes/api.php"
WHMCS_API_IDENTIFIER = "xxxxxxx"
WHMCS_API_SECRET = "yyyyyyy"

AllServices = Service.GetServices()

for ThisService in AllServices:
  Script.WriteToConsole("Updating " + ThisService.ConnectionInfo)
  query = urllib.urlencode({'action' : 'UpdateClientProduct', 'username' : WHMCS_API_IDENTIFIER, 'password' : WHMCS_API_SECRET, 'serviceid' : ThisService.BillingId, 'domain' : ThisService.ConnectionInfo, 'responsetype' : 'json'})
  try:
    urllib2.urlopen(WHMCS_URL, data=query)
  except urllib2.HTTPError, e:
    Script.WriteToConsole("Error updating " + ThisService.ConnectionInfo + ": " + str(e.code) + " " + e.reason)

Note: To troubleshoot the script you can set the event to custom action. Execute it by selecting any game server and clicking on click on more.

Option 3 - Use these scripts in the after created event

Update_WHMCS_database_after_the_game_server_has_been_created

Retrieved from "https://help.tcadmin.com/index.php?title=Update_IP_and_port_in_WHMCS&oldid=2438"