Skip to content

Instantly share code, notes, and snippets.

@isvargasmsft
Created November 7, 2023 21:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isvargasmsft/f732a15462d615c56c9dad6a55119f53 to your computer and use it in GitHub Desktop.
Save isvargasmsft/f732a15462d615c56c9dad6a55119f53 to your computer and use it in GitHub Desktop.
Calling the demo API with PHP
<?php
use KiotaPosts\Client\PostsApiClient;
use KiotaPosts\Client\Models\Post;
use Microsoft\Kiota\Abstractions\ApiException;
use Microsoft\Kiota\Abstractions\Authentication\AnonymousAuthenticationProvider;
use Microsoft\Kiota\Http\GuzzleRequestAdapter;
require __DIR__.'/vendor/autoload.php';
try {
$authProvider = new AnonymousAuthenticationProvider();
$requestAdapter = new GuzzleRequestAdapter($authProvider);
$client = new PostsApiClient($requestAdapter);
// GET /posts
$allPosts = $client->posts()->get()->wait();
$postCount = sizeof($allPosts);
echo "Retrieved {$postCount} posts.\n";
}catch (ApiException $ex) {
echo $ex->getMessage();
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment