bmm bmm - 1 year ago 41
JSON Question

How do I integrate to TeamUp API Calendar in PHP?

Following the documentation here I have installed Guzzle library via

composer require 'guzzlehttp/guzzle:^6.0'
...I then generated an API key.

On the sample code they have provided I tried Querying the Teamup API:

$client = new GuzzleHttp\Client(['headers' => ['Teamup-Token' => 'API KEY ']]);
$res = $client->get('');

echo $res->getStatusCode();
// "200"

echo $res->getHeader('content-type');
// 'application/json'

echo $res->getBody();
// {"subcalendars":[ ... ]}

But can not get any response when I run the same on a browser.
However, when I run the curl version on the terminal

curl ""
-H "Teamup-Token: API KEY"

I am getting the expected response.

Second Testing your API key

I tried this:

$client = new GuzzleHttp\Client(['headers' => ['Teamup-Token' => 'API_KEY']]);
$res = $client->get('');

if ($res->isSuccessful()) {
echo 'Your API key works!';
} else {
echo 'API key test failed: ' . $res->getBody();

No response but the curl version:

curl ""
-H "Teamup-Token: API_KEY"

has a response in json format. Clearly I seem to be doing something wrong. What could it be? Anyone?
Thank you.

bmm bmm
Answer Source

Seems I have found a way to fix my problem. For the sake of anyone having or ever will face the same, here is my fix.

  1. Crate th test file served by a web server

  2. Open a command window and change to that directory

  3. Execute "composer install". This will install the require Guzzle library.

  4. This assumes that you have the php package manager Composer installed on your development machine.

  5. Access the php scripts from a web browser.

You will certainly get the response.


include 'vendor/autoload.php';


 * Check API access

$client = new GuzzleHttp\Client([
    'headers' => ['Teamup-Token' => API_KEY], 
    'verify' => false  // use verify = false 
  //in test mode only to prevent error message about self-signed certificate.
$res = $client->get('');

echo $res->getStatusCode();
// "200"

echo "<br /><br />";
echo $res->getHeader('content-type')[0];
// "application/json"

echo "<br /><br />";
$json_string = json_encode(json_decode($res->getBody()), JSON_PRETTY_PRINT);
echo '<pre>' . $json_string . '</pre>';

That should work!