Create token for Portal with REST API in php

103
1
12-04-2022 06:39 AM
KarstenRank
Occasional Contributor III

Hi,

I am trying to create a token in php with the REST API on our Portal.

 

 

 

$url_base = "https://potal-url/portal";
$url = $url_base . "/sharing/rest/generateToken";

$curl = curl_init($url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));

$dataT = "username=<username>&password=<password>&client=referer&referer=$url_base&f=json";

curl_setopt($curl, CURLOPT_POSTFIELDS, $dataT);

echo $curl;
echo $dataT;
echo "<br>";

$result = curl_exec($curl);
echo('<br>Result Token: ' . $result);
curl_close($curl);

 

 

 

 

But no token is been printed in line 18.

0 Kudos
1 Reply
PanagiotisPapadopoulos
Esri Regular Contributor

you may try the request into  Postman and then you can produse the required code

PanagiotisPapadopoulos_0-1670238785197.png

 

0 Kudos