Set or change API key and update it in DB
The configuration widget of the next step lets an administrator set or change the API key from your admin panel. It does not write to your database itself: it posts the new key to a URL of your server, and a script of yours saves it. This page is that script.
The widget sends a POST request with two form fields:
n1edApiKey: the new API key, 24 characters. The widget has already checked it with the N1ED cloud before posting.n1edToken: always-. Older versions of the widget also stored an access token here; the field stays for compatibility, and your script can ignore it.
Create the script (say setApiKey.php) and let it save the key where the previous step reads it. PHP sample:
<?php
// Do not forget to check that the user has administrator permissions here
$apiKey = $_POST["n1edApiKey"];
if ($apiKey == NULL || strlen($apiKey) != 24) {
throw new AccessDeniedHttpException();
}
// Replace it with the tools your CMS offers for interacting with the DB
mysql_query(/* some query saving the API key into the DB */);
?>
Any response with a 2xx status code counts as success; on any other the widget shows an error with the response. If your admin panel protects POST requests with a CSRF token, the widget can send it: see urlSetApiKey__CSRF on the next page.
Check it
There is nothing to see yet: the script is called by the widget the next step adds. To test it alone, post n1edApiKey=<one of your keys> to it with curl and check the database.