Sometimes you need to create a simple PHP script, or you simply don't want to use a framework or library to help you with HTTP calls.
If this fits your needs, keep reading.
This simple PHP script shows how to use cURL to retrieve the value of a configuration from Nedoto via API:
<?php
$curl = curl_init();
$configName = 'example-var-name';
$piaKey = 'example-api-key';
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://app.nedoto.com/api/get/'.$configName,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => array(
'X-Api-Key: '.$apiKey
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
Replace $configName
with the slug of your configuration and $piaKey
with the value of your API key associated with the same environment as the configuration.
This is an example of the response that the call above might return:
{
"configuration": {
"data": {
"slug": "banner-configuration",
"type": "code",
"value": "{\"configuration-slug\":\"configuration value defined in app.nedoto.com\"}",
"created_at": "2024-04-21T20:25:30+00:00",
"updated_at": "2024-04-21T20:25:30+00:00"
}
}
}
💡 Info
In this case, the response contains a configuration of type code
, and its value is a simple JSON.
Powered by Doctave