SaaS API basics
N1ED cloud servers have an API used to edit cloud settings. First, it provides an HTTP request for automating API key creation and will later include other tools. It would be useful for website builder startups and similar businesses.
This SaaS API is available for everyone on the SaaS plan and may be connected by agreement on other plans (contact support for that).
Request format
URL: https://cloud.n1ed.com/a/saas/action
Request type: POST
Content type: application/x-www-form-urlencoded
Parameters: action parameters
Please replace "action" in the URL with the desired action from the list of available requests to the SaaS API and specify the POST parameters according to the requirements of this request.
Response format
Success result
The response format is always the same, and only the data
section containing the returned data differs. Refer to the request documentation to review the returned structure schema.
HTTP code: 200
(always)
Content type: application/json
Body:
{
error: null,
data: {
...
}
}
Result with a error:
HTTP code: 200
Content type: application/json
Body:
{
error: "string-error-code",
data: null
}
Refer to the specific request documentation to review the returned error codes, and don't forget to check whether the request has failed due to network connectivity problems.
Our servers will never respond with a code different from 200
even in the case of an error, but please check other HTTP codes in case of any potentially unhandled errors.
Code samples
Here are some samples of how to make this request from the Linux console, PHP-based CMSs, and JavaScript/TypeScript Node backends. You can also write code in the language you use.
Of course, the parts action-name
in the URL and param1=value1¶m2=value2
should be replaced accordingly to the request your code is making.
Sh/Bash
This can be called in Linux console if you prefer curl
.
curl \
-X POST https://cloud.n1ed.com/a/saas/action-name \
-d "param1=value1¶m2=value2"
And this is the command for wget
lovers:
wget \
--post-data "param1=value1¶m2=value2" \
--header="Content-Type: application/x-www-form-urlencoded" \
-O - \
https://cloud.n1ed.com/a/saas/action-name
PHP
If you use PHP without any libraries, this is the vanilla PHP code for you:
function request() {
$url = "https://cloud.n1ed.com/a/saas/action-name";
$data = http_build_query([
"param1" => "value1",
"param2" => "value2"
]);
$options = [
"http" => [
"header" => "Content-Type: application/x-www-form-urlencoded",
"method" => "POST",
"content" => $data
]
];
$context = stream_context_create($options);
$response = file_get_contents($url, false, $context);
if ($response === false) {
echo "Request failed";
return null;
} else {
return $response;
}
}
// Example usage
$response = request();
echo $response;
And here is the code for curl
library users:
function request() {
$url = "https://cloud.n1ed.com/a/saas/action-name";
$data = [
"param1" => "value1",
"param2" => "value2"
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Content-Type: application/x-www-form-urlencoded"
]);
$response = curl_exec($ch);
if (curl_errno($ch)) {
echo "cURL Error: " . curl_error($ch);
curl_close($ch);
return null;
}
curl_close($ch);
return $response;
}
// Example usage
$response = request();
echo $response;
JavaScript/TypeScript (NodeJS)
You can make call with Axios library from any framework like Express, NestJS or similar or you custom app:
const axios = require('axios');
async function request() {
try {
const params = new URLSearchParams({
param1: value1,
param2: valud2
});
const response = await axios.post(
"https://cloud.n1ed.com/a/saas/action-name",
params,
{
headers: {
"Content-Type": "application/x-www-form-urlencoded"
}
}
);
return JSON.parse(response.data);
} catch (error) {
console.error(
"Error:",
error.response ? error.response.data : error.message
);
return null;
}
}
// Example usage
createApiKey("your-secret-saas-token", "example.com")
.then(console.log);
Other languages
You can write equivalent code in any other language using the samples above. The SaaS API is available on any platform that can make HTTP requests. If you encounter any difficulties, ask support, and our developers will assist you.