Documentation

GraphRequest

Class GraphRequest

Tags
category

Library

license

https://opensource.org/licenses/MIT MIT License

link
https://graph.microsoft.io/

Table of Contents

$accessToken  : string
A valid access token
$apiVersion  : string
The API version to use ("v1.0", "beta")
$baseUrl  : string
The base url to call
$endpoint  : string
The endpoint to call
$headers  : mixed
An array of headers to send with the request
$http_errors  : bool
Request options to decide if Guzzle Client should throw exceptions when http code is 4xx or 5xx
$proxyPort  : string
The proxy port to use. Null to disable
$proxyVerifySSL  : bool
Whether SSL verification should be used for proxy requests
$requestBody  : string
The body of the request (optional)
$requestType  : object
The type of request to make ("GET", "POST", etc.)
$returnsStream  : bool
True if the response should be returned as a stream
$returnType  : object
The return type to cast the response as
$timeout  : int
The timeout, in seconds
__construct()  : mixed
Constructs a new Graph Request object
addHeaders()  : $this
Adds custom headers to the request
attachBody()  : $this
Attach a body to the request. Will JSON encode any Microsoft\Graph\Model objects as well as arrays
download()  : null
Download a file from OneDrive to a given location
execute()  : mixed
Executes the HTTP request using Guzzle
executeAsync()  : mixed
Executes the HTTP request asynchronously using Guzzle
getApiVersion()  : string
Gets the API version in use for the request
getBaseUrl()  : string
Gets the Base URL the request is made to
getBody()  : mixed
Get the body of the request
getHeaders()  : array<string|int, mixed>
Get the request headers
getReturnsStream()  : bool
Gets whether request returns a stream or not
getTimeout()  : int
Gets the timeout value of the request
setAccessToken()  : $this
Sets a new accessToken
setHttpErrors()  : $this
Sets a http errors option
setReturnType()  : $this
Sets the return type of the response object
setTimeout()  : $this
Sets the timeout limit of the cURL request
upload()  : mixed
Upload a file to OneDrive from a given location
createGuzzleClient()  : Client
Create a new Guzzle client To allow for user flexibility, the client is not reused. This allows the user to set and change headers on a per-request basis
getConcatenator()  : string
Checks whether the endpoint currently contains query parameters and returns the relevant concatenator for the new query string
_getDefaultHeaders()  : array<string|int, mixed>
Get a list of headers for the request
_getRequestUrl()  : string
Get the concatenated request URL

Properties

$accessToken

A valid access token

protected string $accessToken

$apiVersion

The API version to use ("v1.0", "beta")

protected string $apiVersion

$endpoint

The endpoint to call

protected string $endpoint

$headers

An array of headers to send with the request

protected mixed $headers

$http_errors

Request options to decide if Guzzle Client should throw exceptions when http code is 4xx or 5xx

protected bool $http_errors

$proxyPort

The proxy port to use. Null to disable

protected string $proxyPort

$proxyVerifySSL

Whether SSL verification should be used for proxy requests

protected bool $proxyVerifySSL

$requestBody

The body of the request (optional)

protected string $requestBody

$requestType

The type of request to make ("GET", "POST", etc.)

protected object $requestType

$returnsStream

True if the response should be returned as a stream

protected bool $returnsStream

$returnType

The return type to cast the response as

protected object $returnType

Methods

__construct()

Constructs a new Graph Request object

public __construct(string $requestType, string $endpoint, string $accessToken, string $baseUrl, string $apiVersion[, string $proxyPort = null ][, bool $proxyVerifySSL = false ]) : mixed
Parameters
$requestType : string

The HTTP method to use, e.g. "GET" or "POST"

$endpoint : string

The Graph endpoint to call

$accessToken : string

A valid access token to validate the Graph call

$baseUrl : string

The base URL to call

$apiVersion : string

The API version to use

$proxyPort : string = null

The url where to proxy through

$proxyVerifySSL : bool = false

Whether the proxy requests should perform SSL verification

Tags
throws
GraphException

when no access token is provided

Return values
mixed

addHeaders()

Adds custom headers to the request

public addHeaders(array<string|int, mixed> $headers) : $this
Parameters
$headers : array<string|int, mixed>

An array of custom headers

Return values
$this

object

attachBody()

Attach a body to the request. Will JSON encode any Microsoft\Graph\Model objects as well as arrays

public attachBody(mixed $obj) : $this
Parameters
$obj : mixed

The object to include in the request

Return values
$this

object

download()

Download a file from OneDrive to a given location

public download(string $path[, mixed $client = null ]) : null
Parameters
$path : string

The path to download the file to

$client : mixed = null

The client to use in the request

Tags
throws
GraphException

if file path is invalid

throws
GuzzleException
Return values
null

execute()

Executes the HTTP request using Guzzle

public execute([mixed $client = null ]) : mixed
Parameters
$client : mixed = null

The client to use in the request

Tags
throws
GuzzleException
Return values
mixed

object or array of objects of class $returnType

executeAsync()

Executes the HTTP request asynchronously using Guzzle

public executeAsync([mixed $client = null ]) : mixed
Parameters
$client : mixed = null

The client to use in the request

Return values
mixed

object or array of objects of class $returnType

getApiVersion()

Gets the API version in use for the request

public getApiVersion() : string
Return values
string

getBaseUrl()

Gets the Base URL the request is made to

public getBaseUrl() : string
Return values
string

getBody()

Get the body of the request

public getBody() : mixed
Return values
mixed

request body of any type

getHeaders()

Get the request headers

public getHeaders() : array<string|int, mixed>
Return values
array<string|int, mixed>

of headers

getReturnsStream()

Gets whether request returns a stream or not

public getReturnsStream() : bool
Return values
bool

getTimeout()

Gets the timeout value of the request

public getTimeout() : int
Return values
int

setAccessToken()

Sets a new accessToken

public setAccessToken(string $accessToken) : $this
Parameters
$accessToken : string

A valid access token to validate the Graph call

Return values
$this

object

setHttpErrors()

Sets a http errors option

public setHttpErrors(string $http_errors) : $this
Parameters
$http_errors : string

A bool option to the Graph call

Return values
$this

object

setReturnType()

Sets the return type of the response object

public setReturnType(mixed $returnClass) : $this
Parameters
$returnClass : mixed

The object class to use

Return values
$this

object

setTimeout()

Sets the timeout limit of the cURL request

public setTimeout(int $timeout) : $this
Parameters
$timeout : int

The timeout in seconds

Return values
$this

object

upload()

Upload a file to OneDrive from a given location

public upload(string $path[, mixed $client = null ]) : mixed
Parameters
$path : string

The path of the file to upload

$client : mixed = null

The client to use in the request

Tags
throws
GraphException

if file is invalid

throws
GuzzleException
Return values
mixed

DriveItem or array of DriveItems

createGuzzleClient()

Create a new Guzzle client To allow for user flexibility, the client is not reused. This allows the user to set and change headers on a per-request basis

protected createGuzzleClient() : Client

If a proxyPort was passed in the constructor, all requests will be forwared through this proxy.

Return values
Client

The new client

getConcatenator()

Checks whether the endpoint currently contains query parameters and returns the relevant concatenator for the new query string

protected getConcatenator() : string
Return values
string

"?" or "&"

_getDefaultHeaders()

Get a list of headers for the request

private _getDefaultHeaders() : array<string|int, mixed>
Return values
array<string|int, mixed>

The headers for the request

_getRequestUrl()

Get the concatenated request URL

private _getRequestUrl() : string
Return values
string

request URL

Search results