# Call to undefined function save\_token\_to\_storage()

**URL:** https://integration.keap.com/t/call-to-undefined-function-save-token-to-storage/88817
**Category:** API Q&A
**Tags:** api
**Created:** [September 20, 2022, 3:41pm UTC](https://integration.keap.com/t/call-to-undefined-function-save-token-to-storage/88817 "2022-09-20T15:41:32Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Andrew\_Johnson1](https://avatars.discourse-cdn.com/v4/letter/a/34f0e0/32.png) [@Andrew\_Johnson1](https://integration.keap.com/u/Andrew_Johnson1)
#### Post date: [September 20, 2022, 3:41pm UTC](https://integration.keap.com/t/call-to-undefined-function-save-token-to-storage/88817/1 "2022-09-20T15:41:33Z")

</div>

Hey all, rookie here when it comes to the Infusionsoft APIs. I am working on writing a set of PHP scripts, initially just to authorize and do a simple read from the database to show proof of function. I am getting caught on authorization and the proper syntax for the query. Can someone help me understand what sections of code I am missing and have incorrect here?

Initial page, index.php

```auto
<?php
if(empty(session_id())){
  session_start();
  echo "Session ID Variable Found </br>";
}

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

require_once '/Applications/MAMP/htdocs/vendor/autoload.php';

$infusionsoft = new \Infusionsoft\Infusionsoft(array(
	'clientId' => 'EQw5ZqUe(PARTIALLYREMOVED)',
	'clientSecret' => 'b5K(PARTIALLYREMOVED)',

	'redirectUri' => 'http://localhost:8888/keap/index.php',
));

// If the serialized token is available in the session storage, we tell the SDK
// to use that token for subsequent requests.
if (isset($_SESSION['token'])) {
	$infusionsoft->setToken(unserialize($_SESSION['token']));
}

// If we are returning from Infusionsoft we need to exchange the code for an
// access token.
if (isset($_GET['code']) and !$infusionsoft->getToken()) {
    $infusionsoft->requestAccessToken($_GET['code']);
}

// If we are returning from Infusionsoft we need to exchange the code for an
if ($infusionsoft->getToken()) {
    $_SESSION['token'] = serialize($infusionsoft->getToken());
     echo "<br> Confirmed Token </br>";
} else {
    echo '<a href="' . $infusionsoft->getAuthorizationUrl() . '" target="_blank" >Click here to authorize </a> </br>';
}

echo "CheckPoint #1 </br>";

$url = 'https://api.infusionsoft.com/crm/rest/v1/contacts?email=test';
$data = file_get_contents($url); // put the contents of the file into a variable
$contacts = json_decode($data); // decode the JSON feed

echo $contacts[0]->name;

foreach ($contacts as $contact) {
	echo $contact->name . '<br>';
}

echo "End of Test";

?>

```

Webpage produced:

Session ID Variable Found

Confirmed Token  
CheckPoint #1

**Warning** : file\_get\_contents([https://api.infusionsoft.com/crm/rest/v1/contacts?email=test](https://api.infusionsoft.com/crm/rest/v1/contacts?email=test)): Failed to open stream: HTTP request failed! HTTP/1.1 401 Unauthorized in **/Applications/MAMP/htdocs/keap/KEAP.PHP** on line **45**

**Warning** : Trying to access array offset on value of type null in **/Applications/MAMP/htdocs/keap/KEAP.PHP** on line **48**

**Warning** : Attempt to read property “name” on null in **/Applications/MAMP/htdocs/keap/KEAP.PHP** on line **48**

**Warning** : foreach() argument must be of type array|object, null given in **/Applications/MAMP/htdocs/keap/KEAP.PHP** on line **50**  
End of Test
