Menu

## GraphRequest
in package

GraphRequest.php : 30

Class GraphRequest

##### Tags

copyright

  2021 Microsoft Corporation

license

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

link
  https://developer.microsoft.com/graph

### Table of Contents

$requestType : string
  The type of request to make ("GET", "POST", etc.)
$returnsStream : bool
  True if the response should be returned as a stream
$returnType : string|null
  The object type to cast the response to
$graphClient : AbstractGraphClient
  The Graph client
$headers : array<string, string|string[]>
  An array of headers to send with the request
$httpRequest : Request
  PSR-7 Request to be passed to HTTP client
$requestBody : StreamInterface|string
  The body of the request (optional)
$requestUri : UriInterface
  Full Request URI (base URL + endpoint)
__construct() : mixed
  GraphRequest constructor.
addHeaders() : GraphRequest
  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() : void
  Download a file from OneDrive to a given location
execute() : array<string|int, mixed>|GraphResponse|StreamInterface|object
  Executes the HTTP request using $graphClient's http client or a PSR-18 compliant HTTP client
executeAsync() : Promise
  Executes the HTTP request asynchronously using $client
getBody() : string|StreamInterface
  Get the body of the request
getHeaders() : array<string, array<string|int, string>>
  Get the request headers
getRequestUri() : UriInterface
setAccessToken() : $this
  Sets a new accessToken
setReturnType() : $this
  Sets the return type of the response object Can be set to a model or \Psr\Http\Message\StreamInterface
upload() : array<string|int, mixed>|GraphResponse|StreamInterface|object
  Upload a file from $path to Graph API
initPsr7HttpRequest() : void
initRequestUri() : void
  Creates full request URI by resolving $baseUrl and $endpoint based on RFC 3986
setRequestUri() : void
initHeaders() : void
  Sets default headers based on baseUrl being a Graph endpoint or not

### Properties

#### $requestType

GraphRequest.php : 49

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

`protected string $requestType`

#### $returnsStream

GraphRequest.php : 56

True if the response should be returned as a stream

`protected bool $returnsStream`

#### $returnType

GraphRequest.php : 62

The object type to cast the response to

`protected string|null $returnType`

#### $graphClient

GraphRequest.php : 68

The Graph client

`private AbstractGraphClient $graphClient`

#### $headers

GraphRequest.php : 37

An array of headers to send with the request

`private array<string, string|string[]> $headers`

#### $httpRequest

GraphRequest.php : 74

PSR-7 Request to be passed to HTTP client

`private Request $httpRequest`

#### $requestBody

GraphRequest.php : 43

The body of the request (optional)

`private StreamInterface|string $requestBody = null`

#### $requestUri

GraphRequest.php : 80

Full Request URI (base URL + endpoint)

`private UriInterface $requestUri`

### Methods

#### __construct()

GraphRequest.php : 93

GraphRequest constructor.

`public __construct(string $requestType, string $endpoint, AbstractGraphClient $graphClient[, string $baseUrl = "" ]) : mixed`

Sets $baseUrl by default to $graphClient's national cloud Resolves $baseUrl and $endpoint based on RFC 3986

##### Parameters

$requestType : string

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

$endpoint : string

  The url path on the host to be called-

$graphClient : AbstractGraphClient

  The Graph client to use

$baseUrl : string = ""

  (optional) If empty, it's set to $client's national cloud

##### Tags

throws
  GraphClientException

##### Return values

mixed —

#### addHeaders()

GraphRequest.php : 159

Adds custom headers to the request

`public addHeaders(array<string, string|string[]> $headers) : GraphRequest`

##### Parameters

$headers : array<string, string|string[]>

  An array of custom headers

##### Tags

throws
  GraphClientException

  if attempting to overwrite SdkVersion header

##### Return values

GraphRequest —

object

#### attachBody()

GraphRequest.php : 188

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

`public attachBody(string|StreamInterface|object|array<string|int, mixed> $body) : $this`

##### Parameters

$body : string|StreamInterface|object|array<string|int, mixed>

  The payload to include in the request

##### Return values

$this —

object

#### download()

GraphRequest.php : 299

Download a file from OneDrive to a given location

`public download(string $path[, ClientInterface|null $client = null ]) : void`

##### Parameters

$path : string

  path to download the file contents to

$client : ClientInterface|null = null

  (optional) When null, defaults to $graphClient's http client

##### Tags

throws
  ClientExceptionInterface|GraphClientException

  when unable to open $path for writing

##### Return values

void —

#### execute()

GraphRequest.php : 219

Executes the HTTP request using $graphClient's http client or a PSR-18 compliant HTTP client

`public execute([ClientInterface|null $client = null ]) : array<string|int, mixed>|GraphResponse|StreamInterface|object`

##### Parameters

$client : ClientInterface|null = null

  (optional) When null, uses $graphClient's http client

##### Tags

throws
  ClientExceptionInterface

##### Return values

array<string|int, mixed>|GraphResponse|StreamInterface|object —

Graph Response object or response body cast to $returnType

#### executeAsync()

GraphRequest.php : 256

Executes the HTTP request asynchronously using $client

`public executeAsync([HttpAsyncClient|null $client = null ]) : Promise`

##### Parameters

$client : HttpAsyncClient|null = null

  (optional) When null, uses $graphClient's http client

##### Tags

throws
  Exception

  when promise fails

##### Return values

Promise —

Resolves to GraphResponse object|response body cast to $returnType. Fails throwing the exception

#### getBody()

GraphRequest.php : 207

Get the body of the request

`public getBody() : string|StreamInterface`

##### Return values

string|StreamInterface —

request body

#### getHeaders()

GraphRequest.php : 175

Get the request headers

`public getHeaders() : array<string, array<string|int, string>>`

##### Return values

array<string, array<string|int, string>> —

of headers

#### getRequestUri()

GraphRequest.php : 114
`public getRequestUri() : UriInterface`

##### Return values

UriInterface —

#### setAccessToken()

GraphRequest.php : 125

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

#### setReturnType()

GraphRequest.php : 141

Sets the return type of the response object Can be set to a model or \Psr\Http\Message\StreamInterface

`public setReturnType(string $returnClass) : $this`

##### Parameters

$returnClass : string

  The class name to use

##### Tags

throws
  GraphClientException

  when $returnClass is not an existing class

##### Return values

$this —

object

#### upload()

GraphRequest.php : 323

Upload a file from $path to Graph API

`public upload(string $path[, ClientInterface|null $client = null ]) : array<string|int, mixed>|GraphResponse|StreamInterface|object`

##### Parameters

$path : string

  path of file to be uploaded

$client : ClientInterface|null = null

  (optional)

##### Tags

throws
  ClientExceptionInterface|GraphClientException

  if $path cannot be opened for reading

##### Return values

array<string|int, mixed>|GraphResponse|StreamInterface|object —

Graph Response object or response body cast to $returnType

#### initPsr7HttpRequest()

GraphRequest.php : 377
`protected initPsr7HttpRequest() : void`

##### Return values

void —

#### initRequestUri()

GraphRequest.php : 369

Creates full request URI by resolving $baseUrl and $endpoint based on RFC 3986

`protected initRequestUri(string $baseUrl, string $endpoint) : void`

##### Parameters

$baseUrl : string
$endpoint : string

##### Tags

throws
  GraphClientException

##### Return values

void —

#### setRequestUri()

GraphRequest.php : 109
`protected setRequestUri(UriInterface $uri) : void`

##### Parameters

$uri : UriInterface

##### Return values

void —

#### initHeaders()

GraphRequest.php : 341

Sets default headers based on baseUrl being a Graph endpoint or not

`private initHeaders(string $baseUrl) : void`

##### Parameters

$baseUrl : string

##### Return values

void —

## Search results