Alvin Brown provides a tutorial on how to create a personalized domain name suggestion tool using GoDaddy’s API.
It’s been a while since my last tutorial spotlighting the use of GoDaddy’s API to retrieve a list of domains associated with your GoDaddy account.
Today’s tutorial aims to help create a simple tool that returns available domain names based on submitted keywords and domain ideas.
There is no shortage of domain name suggestion tools available when brainstorming what to name your next product, service, business, or project.
Before diving into today’s tutorial, please review and read previous tutorials to learn how to get started using GoDaddy’s API, and its various API endpoints offered to programmatically manage various aspects of your account.
At the end of this tutorial, you’ll find a link to download the zip file containing the entire code example for the domain name suggestion tool.
It’s also worth noting the tutorial code is procedural instead of object-oriented for the sake of simplicity, and not encouraged for use in or as production-ready environments.
Another key detail to pay close attention too, it ensuring you add/replace GoDaddy API credentials with your own credentials, or this tutorial will not work.
Without further ado, open up a text editor of your choice, and let us get started.
Again, I won’t dive into the details but will give a high-level overview of the necessary parts to use GoDaddy’s suggest method to retrieve a suggested list of alternate domains.
Creating search form for domain name suggestion tool
From a text editor of your choice, save and name the following php file: suggest.php. With main file created, the first item of business to address is the HTML form used to submit keywords. Copy and paste the following html into the suggest.php:
The code screenshot is really simple, containing a mix of PHP, HTML, Javascript, and CSS. The styling of the page can be found in the following css files for Bootstrap 3 and a local file I created (see zip file):
- bootstrap.min.css
- dnw-gd-suggest.css
The last 10 or so lines of code in the suggest.php contains the logic to display a suggested list of alternate domains once the form has been successfully submitted.
Although contained in the suggest.php file, the results of the PHP code above are not visible from a web browser on initial page load. The form must be completed and submitted to reveal results.
With the frontend UI/UX in place, let us dive into the page functionality once submitting keywords or domains for suggested list of alternate domains.
Creating PHP logic for domain name suggestion tool
At the very top of the suggest.php file, copy and paste the following PHP logic:
The first item to note in the image is the use of PHP’s built-in define function, which is implemented to define the constant variable SITE_NAME (i.e., Domain Suggestions).
The next set of variables to define are mission critical to authenticate and instantiate a GoDaddy API request. The API_KEY and API_SECRET credentials can be obtained by visiting the API Key Management page.
After defining critical variables for GoDaddy API authentication, the next set of variables to define are as follows:
- prepend – an optional variable if you would like to prepend alpha, numeric, or alphanumeric values to submitted keywords
- typer – this is a required variable
- msg – default variable used to capture and return human-readable error messages to display
- searchDNAvailable – default variable used to trigger whether or not to display domain results each time the page is loaded or submitted. If value is 0, then no domains are shown (i.e., initial page load). If value is 1, then form was successfully submitted and suggested list of alternate domains are available for display.
The PHP logic for what should occur when form is submitted can be executed once variables are defined. The code below determines whether or not the submit button has been pressed.
If submit button has been pressed, then an error message is defined by default using the msg variable. In this case, the error message is displayed if the user clicks the submit button without entering a keyword.
The next few lines proceed to sanitize submitted keywords (i.e., $_POST[‘domain’] is cleaned and set as value of keywords variable) to ward off any hackers attempting to hijack the search tool should host on a public web server.
The last line of logic contains all the heavy lifting. If keywords variable is not empty and is defined, then the following variables are defined:
- msg is set to equal nothing, and this now replaces the previous error message
- typer is set equal to KEYWORD_SPIN (other available values per GoDaddy’s API documentation for suggest method: KEYWORD_SPIN, keyword spin, EXTENSION, extension, PREMIUM, premium, CC_TLD, cctld)
- searchDNAvailable is set equal to 1
- searched is set equal to the getDomains function, passing typer as first argument and keywords as second argument
Completing the aforementioned variable definitions closes out the PHP logic for establishing and displaying the suggested list of alternate domains.
But not so fast though. If you were to open a web browser and attempt to execute code up to this point, you would encounter warnings of the following functions not defined: getDomains, RemoveSpecialChar, and printDomainResults.
Necessary PHP functions for domain name suggestion tool
Below is a high level overview of 3 critical functions necessary for successfully executing this tutorial (each function is included in suggest.php file):
getDomains
The getDomains function is the brains of searching and compiling the suggested list of alternate domains based on source (i.e., typer variable) and keyword (i.e., keywords variable). Within this function exists PHP’s built-in CURL method that makes the API request to the suggest method with submitted keywords and sources.
In addition, feel free to modify the country and limit variables as well as add variables to narrow or expand domain search based on GoDaddy’s suggest method attributes:
- country – two-letter ISO country code to be used as a hint for target region
- city – name of city to be used as a hint for target region
- sources – sources to be queried (see previous section for typer variable)
- tlds – top-level domains to be included in suggestions
- lengthMax – maximum length of second-level domain
- lengthMin – minimum length of second-level domain
- limit – maximum number of suggestions to return
- waitMS – maximum amount of time, in milliseconds, to wait for responses; if elapses, return the results compiled up to that point
RemoveSpecialChar
The RemoveSpecialChar function is the most simple of the 3 functions, using PHP’s preg_replace and regex to remove any special characters from keyword submittal.
printDomainResults
The printDomainResults function prepares domain results to present to web browser display using HTML. Each domain is linked to GoDaddy’s domain availability page to check the domain’s availability for registration (see image below).
Closing Thoughts
I encourage you to download the tutorial code, make necessary modifications, and see where this tool takes you.
DOWNLOAD dnsuggest.zip for GoDaddy API Suggest
If hand registering domains is your strategy, or you simply need assistance in discovering an alternative domain for your next business, idea, project or whatever, this tool aims to help you save time and money.
With not much effort and slight modification to the printDomainResults function, you could easily host your very own domain search tool for the general public to use.
Taking the aforementioned path could transform this tool into a profit center using affiliate services (i.e., CJ Affiliate) to associate domain registrations to domain registrars (i.e., NameCheap.com, GoDaddy, HostGator and many more…). (hint hint) 😉
Please don’t hesitate to leave comments should you have questions or encounter technical challenges implantation this tutorial.
Thanks and that’s all for now!
This looks like the Verisign API underneath, not built by GoDaddy.
Okay so do you go about getting an API key, can you share the link? Thanks!
Hi Alan – The link is shared in the “Creating PHP logic for domain name suggestion tool” section as well as the 3rd link from beginning. 🙂 Visit https://developer.godaddy.com to create an account and obtain necessary API keys. Thanks and hope you find value in this tutorial.