Getting Started With Our API


Our API is extremely dynamic and has different rules for different types of requests. When calling our API from your own website, you will be using what we call "App Commands". We will explain the other types in this guide too, but they are used for requests for web hosting and webhooks sent by integrated 3rd party providers. As a developer using our services, App Commands are all you need to setup yourself.


All Required Fields For All App Command API Requests

Name

Field

Notes

Posting URL:

https://api.aiappsapi.com

HTML Method:

POST

No data is passed in the url

Account ID:

accountID

Your AI Apps Account Number

API Key:

key

Create API Keys On Our Settings Page

App:

app

The App associated with this api call

Command:

command

The specific action being taken

JSON Data Array:

json

All the other parameters for an api request go in here.



This is the core PHP Function used in our SDK used for any App Command. See the specific docs for each app to see examples of building the JSON array for each command.

<php

define("AIAppsAPIKey", "Your API Key");
define("AIAppsAPIAccountID", "Your Account Number");

function Make_AIAppsAPI_Request ($app, $command, $json = array())
{
	$api_url = "https://api.aiappsapi.com";
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, $api_url);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_TIMEOUT, 60);
	curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
	curl_setopt($ch, CURLOPT_POST, true);
	curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array("app" => $app, "command" => $command, "key" => AIAppsAPIKey, "accountID" => AIAppsAPIAccountID, "json" => json_encode($json))));
	$result = curl_exec ($ch);
	$curl_error = curl_error($ch);
	curl_close ($ch);
	$response = json_decode($result, true);
	
	if (!is_array($response)) $response = array();
	return $response;
}

?>


All commands are mostly the same format, with the json field having all unique fields in the request. Command names are not unique, different apps may have a command with the same name, and are generally the same type of functionality. We post the API key inside the same posted fields to make things easier, all requests use https encryption, so is no less secure than using auth headers. You can use our PHP SDK for examples, all API calls use the same Curl function.



App Jobs

An App Job is the same as an App Command, with the difference being that it handles a long running task that takes too long for a website to wait for. The job is triggered by an API request using the App Command format above, and will queue the task for background processing. The API will respond immediately in less than 1 second, and the background process will start within 1 minute. If the task stores the result on our end, such as adding content to our databases, then triggering the task is all you need to do. For situations where you need the task's results on your own website, then we have the option of doing a "Postback" to your website using the sample postback script in our SDK, or by downloading a file we create and email to you. Some commands can also be called from the command line of your own servers, and allow you to pass a field named "allowLongRunning" to true. We only give this option on commands that have a max of 10 minutes of processing time.



Other Types Of API Calls

Just for your own general knowledge, we explain some other things our API does, however, these are not things you need to code yourself. The most common is what is called a webhook, which is when a 3rd party provider sends information to you (through us as the receiver). In these cases you would simply need to provide these 3rd party providers with the correct website Url we provide for your account. We have already integrated their Post requests to us. See the specific docs fpr each app to get the exact Url for each type of webhook.



The main difference is that our normal API security key is not needed, and that the 3rd party controls the Post data of the request. Your Url will have 3 pieces of information for our system to ID you and the app you are receiving the webhook for. We do not use query strings, instead each are in a directory structure like https://api.aiappsapi.com/accountID/app/mode. We call these "Modes" to not confuse them with "Commands" which are the API requests used to call secure AI Apps remote functionality. Whenever you code your own API requests, you should always prefer to use Commands, even if we give you both a Mode and Command that do the same thing. There will only be both options if we know of 3rd party systems you might use that can't be customized to handle a command call.



The last thing our API does that we will cover is hosting of web pages and full websites. This is managed completely in our admin area and there is nothing you need to code / program with this. Hosting a domain or sub-domain with us uses the same api however, meaning hosting a website with us provides the same serverless speed and scalability as our API has. All built on Amazon AWS, our API uses CloudFront to handle requests from all over the world as if the user was in the same location as your website, as well as, serverless database and web page loading (Lambda Function is the exact name). Our one API can handle any number of App requests, website traffic and webhooks to an unlimited number of users with either high or low amounts of traffic.