Skip to content

Latest commit

 

History

History
127 lines (109 loc) · 3.17 KB

OtherAPIs.md

File metadata and controls

127 lines (109 loc) · 3.17 KB

Other APIs

VERSION

Passing in a version through .version() has the highest priority. It overrides the Microsoft Graph client default version from .init() and the global library default (currently v1.0).

try{letres=awaitclient.api("/me/ownedDevices").version("beta").get();console.log(res);}catch(error){throwerror;}

QUERY

You can pass in any URL query parameters through .query() as a dictionary or string.

try{// Below three statements are sameletres1=awaitclient.api("/me").query({$select: "displayName"}).get();letres2=awaitclient.api("/me").query("$select=displayName").get();letres3=awaitclient.api("/me").select("displayName").get();}catch(error){throwerror;}

HEADER AND HEADERS

You can pass in additional request headers through .header() or .headers() either individually or in a dictionary.

try{letmessageBody={message: {subject: "Meet for lunch?",body: {contentType: "Text",content: "The new cafeteria is open.",},toRecipients: [{emailAddress: {address: "garthf@contoso.com",},},],},};// Below two statements are sameletres1=awaitclient.api("/me/sendMail").header("content-type","application/json").post(messageBody);letres2=awaitclient.api("/me/sendMail").headers({"content-type": "application/json"}).post(messageBody);}catch(error){throwerror;}

OPTION AND OPTIONS

You can pass in additional request options through .option() and .options(), either individually or in a dictionary. Options can be node specific or from fetch standard

letHttpProxyAgent=require('https-proxy-agent');try{// HTTP/HTTPS proxy to connect toletproxy=<YOURPROXY>;letagent=newHttpProxyAgent(proxy);// Below two statements are sameletres1=awaitclient.api("/me").option("agent",agent).get();letres2=awaitclient.api("/me").options({agent: agent}).get();}catch(error){throwerror;}

MIDDLEWAREOPTIONS

You can override the client middleware behavior by setting per request middleware options. Use the .middlewareOptions() request builder method to add custom middleware behavior for a specific request. The middlewareOptions() method takes an array of strongly typed middleware options. These middleware options are an implementation of the MiddlewareOptions interface.

try{letres=awaitclient.api("/me/messages").middlewareOptions([newRetryHandlerOptions(5000)]).get();console.log(res);}catch(error){throwerror;}

RESPONSETYPE

To set a custom response type, use the.responseType(<ResponseType>) method. Refer ResponseType.ts for available options.

try{letres=awaitclient.api(`/me/drive/root/children/${fileName}/content`).responseType(MicrosoftGraph.ResponseType.BLOB).get();console.log(res);}catch(error){throwerror;}
close