The CompanySearchField class provides a search input field with a dropdown that populates with company suggestions based on the user's input. When a company is selected from the dropdown, the class allows you to register callback functions that will be executed with the selected company's information.
To use the services provided by TheCompanyAPI, follow these steps to obtain your API key:
- Visit TheCompanyAPI Website
- On the homepage, click the 'Get API Key' button.
- Select the plan that suits your needs. Note that some plans may require payment.
- Follow the prompts to enter your payment information and complete the purchase if your chosen plan requires it.
- Your API key will be emailed to you after selecting your plan and completing any necessary payments.
- Include the required JavaScript file in your HTML file:
<script src="https://app.thecompanyapi.io/js/companyapi.min.js" ></script> - Create an HTML element for the search input field:
<input type="text" id="searchInput" placeholder="Search for a company"> - Create an instance of the
CompanySearchFieldclass, passing the API key and the ID of the search input field:It will create a search input and a dropdown according to the user inputlet searchField = new CompanySearchField("YOUR_API_KEY", "searchInput");
- Register a callback function to handle the selected company information:
searchField.onCompanySelected(function(companyObject) { // Handle the selected company information console.log("Selected company:", companyObject); });
When a company is selected from the dropdown, the registered callback function receives an object with the following properties:
company_name: The name of the selected company.description: A brief description of the selected company.size: The company's size, e.g., "mnc" (multinational corporation), "startup", etc.industries: An array of industries the company operates in.linkedin_link: The URL of the company's LinkedIn page.company_id: A unique identifier for the company.company_keyword: The search keyword used to find the company.image_id: The ID of the company's logo image (may not be present).location: The company's headquarters location (may not be present).
Example:
{
company_name: 'Accenture',
description: 'Accenture is a professional services company, providing services and solutions in strategy, consulting, digital, technology and operations.',
size: 'mnc',
industries: ['Consulting', 'Information Technology'],
linkedin_link: 'https://www.linkedin.com/company/accenture/',
company_id: '578c9a1f-cfc0-41ea-87f0-c6167190a48c',
company_keyword: 'accenture',
image_id: 'bayumbfcn7b4h7xk08cc',
location: 'Dublin'
}Note: The properties present in the object may vary depending on the data available for the selected company.
var CompanySearchField = function(apiKey, domId) {
// ...
}apiKey(string): The API key required for making requests.domId(string): The ID of the search input field element in the DOM.
Register a callback function to be executed when a company is selected from the dropdown.
searchField.onCompanySelected(function(companyObject) {
// Your callback function
console.log("Selected company:", companyObject);
});callback(function): The function to be called when a company is selected. It receives the selected company's information as an object.
- The
CompanySearchFieldclass uses the customajaxfunction for making HTTP requests to our backend API.