| Qore CdsRestClient Module Reference 2.0

Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | List of all members
CdsRestClient::CdsRestClient Class Reference

this class provides the REST client API for communication with Microsoft Dynamics 365 Common Data Service servers More...

Inheritance diagram for CdsRestClient::CdsRestClient:
[legend]

## Public Member Functions
| constructor (hash< auto > opts, *softbool do_not_connect)
| creates the object with the given options
string | getApi ()
| returns the CDS REST API version currently in use

## Static Public Member Functions
static hash< auto > | getOptions (hash< auto > opts)
| returns options for the CdsRestClient::CdsRestClient::constructor()
static | raiseError (string fmt,...)
| throws an exception due to an error

## Public Attributes
const | ApiProfiles = ...
| API profiles.
const | DefaultApiVersion = "9.2"
| Default API version.
const | DefaultBusinessCentralBaseUri = "https://api.businesscentral.dynamics.com/"
| Default Dynamics 365 base URI.
const | DefaultDynamicsPingHeaders = ...
| Default Dynamics ping headers.
const | DefaultDynamicsPingMethod = "GET"
| Default Dynamics ping method.
const | DefaultDynamicsPingPath = "{api_uri_path}/WhoAmI"
| Default Dynamics ping path.
const | OAuth2AuthUriPathSuffix = "/oauth2/v2.0/authorize"
| OAuth2 auth URI path suffix.
const | OAuth2AuthUrl = sprintf("%scommon%s", OAuth2BaseUrl, OAuth2AuthUriPathSuffix)
| OAuth2 auth URL.
const | OAuth2BaseUrl = "https://login.microsoftonline.com/"
| OAuth2 auth URL.
const | OAuth2TokenUriPathSuffix = "/oauth2/v2.0/token"
| OAuth2 token URI path suffix.
const | OAuth2TokenUrl = sprintf("%scommon%s", OAuth2BaseUrl, OAuth2TokenUriPathSuffix)
| OAuth2 token URL.
const | RequestUriPathPrefix = "/api/data/v"
| Request URI path prefix.

## Protected Member Functions
hash< auto > | sendAndDecodeResponse (*data body, string m, string path, hash< auto > hdr, *reference< hash< auto > > info, *softbool decode_errors, *string assume_content_type, *string shdr, *code signer)
| sends the outgoing HTTP message and recodes the response to data

## Detailed Description

this class provides the REST client API for communication with Microsoft Dynamics 365 Common Data Service servers

This class requires the following options for Microsoft Dynamics 365 Common Data Service authentication and authorization to the target server:

- `oauth2_client_id:` the OAuth2 client ID
- `oauth2_client_secret:` the OAuth2 client secret

Errors returned from Dynamics will have the following format:

- `err:` will be the hex error code from Dynamics (ex: `0x8006088a`)
- `desc:` the exception message (ex: `Resource not found for the segment 'WhoAmi'.`)
- `arg:` the error hash from the server plus a `decoded_body` argument with any decoded message body

## Member Function Documentation

## ◆ constructor()

CdsRestClient::CdsRestClient::constructor | ( | hash< auto > | opts,
|  | *softbool | do_not_connect )

creates the object with the given options

Example:
  CdsRestClient rest({
  "url": "https://my-instance.crm2.dynamics.com",
  "oauth2_client_id": oauth2_client_id,
  "oauth2_client_secret": oauth2_client_secret,
  "oauth2_grant_type": "client_credentials",
  });

Parameters

  opts | valid options are the same as RestClient with the following differences: `api:` the API version for CDS `api_profile:` one of: `none` (no options set) `dynamics` (set client options for the MS Dynamics 365 API) `data:` see DataSerializationOptions for possible values; the default is `"json"` `scope:` the OAuth2 scope for the login; the default depends on the `"api_profile"` option
  do_not_connect | if `False` (the default), then a connection will be immediately established to the remote server

Exceptions

  RESTCLIENT-ERROR | invalid option passed to constructor, unsupported data serialization, etc
  CDSRESTCLIENT-ERROR | missing or invalid required option for REST authentication or communication