<?php
// Tableau server details
$tableauServerUrl = 'https://dub01.online.tableau.com';
$name = 'coefficient2';
$secret = 'yKHsYWffQ6WwVdkafm0UQQ==:3s4Ml6EOXErsWVVF2S0BP0ZzVCzIoLn2';
// API version
$apiVersion = '3.12'; // Use the appropriate API version
// Set the URL for authentication
$authUrl = "$tableauServerUrl/api/$apiVersion/auth/signin";
// Create a request body
$data = array(
'credentials' => array(
'personalAccessTokenName' => $name,
'personalAccessTokenSecret' => $secret,
'site' => array(
'contentUrl' => 'hsplus'
)
)
);
// Initialize cURL session
$ch = curl_init($authUrl);
// Set cURL options
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Accept: application/json'
));
// Execute cURL request
$response = curl_exec($ch);
// Close cURL session
curl_close($ch);
// Decode the JSON response
$responseData = json_decode($response, true);
// Extract token
$token = $responseData['credentials']['token'];
// Display the token
echo "Token: $token";
?>