Automatize API key creating for each website your CMS serves
Initially, as a first step in implementing N1ED in your CMS, you might have a single API key used for everyone. Change this behavior by defining a field (a new column) in your DB in the users table to store an N1ED API key for each customer. Then, always load the editor (N1ED, CKEditor with N1ED plugin, or TinyMCE with N1ED plugin) with the received and saved API key for that user as soon you can generate them.
N1ED offers a special SaaS API for this. This action can be automated both for generating keys for all existing clients and when a new customer registers in your CMS or creates an additional website.
When a user registers in your CMS, or when your manager does this for somebody, the CMS can automatically make a request to the N1ED server to create an API key and save it into your DB, attaching the resulting key to the newly registered user.
You may also want to create API keys for all already registered users when implementing N1ED in the CMS with a number of existing users. To do this, write a script that makes this API request in a loop.
Request format
URL: https://cloud.n1ed.com/a/saas/api-key-create
Request type: POST
Content type: application/x-www-form-urlencoded
Parameters:
-
saasToken
Your secret SaaS token that acts as an API key for SaaS API
-
domain
Domain name for which to create the API key.
Please don't include the protocol or port.
The "www." prefix may be omitted as well.
Examples:
example.com
example.com
If you don't know the domain for the final website yet, please use an internal domain that you are using temporarily:
user-534.example.com
Or even just a user ID if you don't have any temporary domain for that:
user-534
You can't have the same domains on different websites, so please ensure uniqueness. Otherwise, this SaaS API request will return an error. Think of this value as both an ID for our system and a note for yourself at the same time.
-
copyFrom
optionalAPI key on the same account that you want to use as the source for the configuration.
When specified, all the preferences (but not custom blocks templates) will be copied from a website with this API key. If you need to provide existing block templates on the target key, please use block sharing feature instead, which is available for you in the Dashboard.
Response format
The server will return the newly created API key in the data section if the request succeeds, or an error code otherwise.
HTTP code: 200
Content type: application/json
Body:
{
error: null,
data: {
apiKey: "newly-created-api-key"
}
}
Possible error codes:
CANT-CREATE-API-KEY-WITHOUT-LICENSE
- you have reached your license limit on the account. Please purchase more licenses and retry.UNABLE-TO-FIND-API-KEY-TO-COPY-FROM
- may appear if you specified thecopyFrom
parameter but such a source API key doesn't exist.DOMAIN-ALREADY-EXISTS
- you tried to create an API key with an already existing (duplicate) domain, which is not allowed.
Sample request
Here is a sample of how to make this request from the Linux console (sh, bash, or any other shell).
curl \
-X POST https://cloud.n1ed.com/a/saas/api-key-create \
-d "saasToken=your-secret-saas-token&domain=example.com"
Please refer to SaaS API basicsto see samples for PHP, JS, and learn how to write code for other languages.