Authorize Components
Every Productsup Component has to be initialized with a valid authorization token. The token also identifies your application to Productsup. The following code samples demonstrate how to request an access token to be used for the components.
To get an access token you have to provide your Client ID and Secret along with project and site properties that you're going to use to setup the Javascript component. The access token is only valid for exactly that project and site.
When you got an access token, use it and replace ACCESS_TOKEN in the Javascript with that token.
Examples
curl -X POST \
-d '{"client_id":"XXX","client_secret":"XXX"}' \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
https://capi.productsup.com/v1/authentication
{
"token":"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
"expiration_time":"2016-08-26T13:07:27+00:00",
"client_id":"XXXX"
}
<?php
$protocol = 'https'; // Defaults to https for now
$host = 'capi.productsup.io'; // Hostname of the api server
$url = sprintf('%s://%s/authentication', $protocol, $host);
$clientId = ''; // Client id for remote access
$clientSecret = ''; // Client secret for remote access
$project = 'project:1';
$site = 'feed:1';
$curlHandler = curl_init();
curl_setopt_array($curlHandler, [
CURLOPT_URL => $url,
CURLOPT_HEADER => false,
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_MAXREDIRS => 10,
CURLOPT_HTTPHEADER => [
'Accept: application/json',
'Content-Type: application/json',
],
CURLOPT_POSTFIELDS => json_encode([
'client_id' => $clientId,
'client_secret' => $clientSecret,
'project' => $project,
'site' => $site
]),
]);
$reponseBody = curl_exec($curlHandler);
$httpStatus = curl_getinfo($curlHandler, CURLINFO_HTTP_CODE);
curl_close($curlHandler);
$data = json_decode($reponseBody);
if ($httpStatus >= 400) {
// Some kind of error occured, a more specific status is usually available via: $data->message
echo 'A server error occured. ' . PHP_EOL;
if (property_exists($data, 'message')) {
echo $data->message . PHP_EOL;
}
} elseif ($httpStatus == 200) {
// All went well
echo 'Client id: ' . $data->client_id . PHP_EOL;
echo 'Access token: ' . $data->token . PHP_EOL;
echo 'Expiration time: ' . $data->expiration_time . PHP_EOL;
} else {
// Something else bad happened
echo 'An unexpected error occured. ' . PHP_EOL;
}
Every Productsup Component has to be initialized with a valid authorization token. The token also identifies your application to Productsup. The following code samples demonstrate how to request an access token to be used for the components.
To get an access token you have to provide your Client ID and Secret along with project and site properties that you're going to use to setup the Javascript component. The access token is only valid for exactly that project and site.
When you got an access token, use it and replace ACCESS_TOKEN in the Javascript with that token.
Updated almost 8 years ago
