Skip to content

Instantly share code, notes, and snippets.

View isvargasmsft's full-sized avatar

Isaac Vargas isvargasmsft

  • Microsoft
  • San Jose, Costa Rica
View GitHub Profile
@isvargasmsft
isvargasmsft / batching.php
Last active November 8, 2023 13:01
Batching requests
<?php
use Microsoft\Graph\Core\Requests\BatchRequestContent;
use Microsoft\Graph\Generated\Models\Message;
use Microsoft\Graph\BatchRequestBuilder;
use Microsoft\Graph\Core\Requests\BatchResponseItem;
use Microsoft\Graph\Generated\Models\Message;
// Create a batch request content object
$message = new Message();
@isvargasmsft
isvargasmsft / largefileupload.php
Last active November 8, 2023 12:35
Uploading large files
<?php
use Psr\Http\Client\NetworkExceptionInterface;
// create a file stream
$file = Utils::streamFor(fopen('fileName', 'r'));
// create an upload session
$attachmentItem = new AttachmentItem();
$attachmentItem->setAttachmentType(new AttachmentType('file'));
$attachmentItem->setName('fileName');
@isvargasmsft
isvargasmsft / pageiterator.php
Last active November 8, 2023 12:31
Paging through a collection
<?php
use Microsoft\Graph\Core\Tasks\PageIterator;
use Microsoft\Graph\Generated\Models\Message;
use DateTimeInterface;
$messages = $graphServiceClient->users()->byUserId(USER_ID)->messages()->get()->wait();
$pageIterator = new PageIterator($messages, $graphServiceClient->getRequestAdapter());
$counter = 0;
@isvargasmsft
isvargasmsft / callingAPI.php
Created November 7, 2023 21:13
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';
@isvargasmsft
isvargasmsft / generateAPIclientPython.bash
Last active November 7, 2023 21:11
CLI command to generate Python API clients with Kiota
kiota generate -l python -c PostsClient -n client -d https://raw.githubusercontent.com/microsoft/kiota-samples/main/get-started/quickstart/posts-api.yml -o ./client
@isvargasmsft
isvargasmsft / generateAPIclientPHP.bash
Created November 7, 2023 21:10
Generate a PHP API client with Kiota
kiota generate -l PHP -d https://raw.githubusercontent.com/microsoft/kiota-samples/main/get-started/quickstart/posts-api.yml -c PostsApiClient -n KiotaPosts\Client -o ./client
@isvargasmsft
isvargasmsft / KiotaPHPDependencies.bash
Created November 7, 2023 21:09
Commands to install dependencies to generate PHP API Clients with Kiota
composer require microsoft/kiota-abstractions
composer require microsoft/kiota-http-guzzle
composer require microsoft/kiota-serialization-json
composer require microsoft/kiota-serialization-text
@isvargasmsft
isvargasmsft / installKiota.bash
Last active November 7, 2023 21:08
Command to install Kiota as a .NET tool
dotnet tool install --global Microsoft.OpenApi.Kiota
@isvargasmsft
isvargasmsft / callAPI.py
Created November 7, 2023 20:57
Calling the JSON Placeholder API
import asyncio
from kiota_abstractions.authentication.anonymous_authentication_provider import (
AnonymousAuthenticationProvider)
from kiota_http.httpx_request_adapter import HttpxRequestAdapter
from client.posts_client import PostsClient
from client.models.post import Post
async def main():
# You may need this if your're using asyncio on windows
# See: https://stackoverflow.com/questions/63860576
@isvargasmsft
isvargasmsft / pythondependencies.bash
Created November 7, 2023 20:52
CLI commands to install Python dependencies for Kiota
pip install microsoft-kiota-abstractions
pip install microsoft-kiota-http
pip install microsoft-kiota-serialization-json
pip install microsoft-kiota-serialization-text