Codeunit "Rest Client"
Provides functionality to easily work with the HttpClient object.
Properties
| Name | Value |
|---|---|
| Access | Public |
| InherentEntitlements | X |
| InherentPermissions | X |
Methods
Create
Initializes a new instance of the Rest Client class.
procedure Create(): Codeunit "Rest Client"
Returns
| Type | Description |
|---|---|
| Codeunit System.RestClient."Rest Client" |
The Rest Client object. |
Remarks
The default Http Client Handler and anonymous Http authentication will be used.
Create
Initializes a new instance of the Rest Client class.
procedure Create(HttpClientHandler: Interface "Http Client Handler"): Codeunit "Rest Client"
Parameters
| Name | Type | Description |
|---|---|---|
| HttpClientHandler | Interface System.RestClient."Http Client Handler" |
The Http Client Handler to use. |
Returns
| Type | Description |
|---|---|
| Codeunit System.RestClient."Rest Client" |
The Rest Client object. |
Remarks
The anynomous Http Authentication will be used.
Create
Initializes a new instance of the Rest Client class.
procedure Create(HttpAuthentication: Interface "Http Authentication"): Codeunit "Rest Client"
Parameters
| Name | Type | Description |
|---|---|---|
| HttpAuthentication | Interface System.RestClient."Http Authentication" |
The authentication to use. |
Returns
| Type | Description |
|---|---|
| Codeunit System.RestClient."Rest Client" |
The Rest Client object. |
Remarks
The default Http Client Handler will be used.
Create
Initializes a new instance of the Rest Client class.
procedure Create(HttpClientHandler: Interface "Http Client Handler", HttpAuthentication: Interface "Http Authentication"): Codeunit "Rest Client"
Parameters
| Name | Type | Description |
|---|---|---|
| HttpClientHandler | Interface System.RestClient."Http Client Handler" |
The Http Client Handler to use. |
| HttpAuthentication | Interface System.RestClient."Http Authentication" |
The authentication to use. |
Returns
| Type | Description |
|---|---|
| Codeunit System.RestClient."Rest Client" |
The Rest Client object. |
Initialize
Initializes the Rest Client with the default Http Client Handler and anonymous Http authentication.
procedure Initialize()
Initialize
Initializes the Reest Client with the given Http Client Handler
procedure Initialize(HttpClientHandler: Interface "Http Client Handler")
Parameters
| Name | Type | Description |
|---|---|---|
| HttpClientHandler | Interface System.RestClient."Http Client Handler" |
The Http Client Handler to use. |
Remarks
The anynomous Http Authentication will be used.
Initialize
Initializes the Rest Client with the given Http Authentication.
procedure Initialize(HttpAuthentication: Interface "Http Authentication")
Parameters
| Name | Type | Description |
|---|---|---|
| HttpAuthentication | Interface System.RestClient."Http Authentication" |
The authentication to use. |
Remarks
The default Http Client Handler will be used.
Initialize
Initializes the Rest Client with the given Http Client Handler and Http Authentication.
procedure Initialize(HttpClientHandler: Interface "Http Client Handler", HttpAuthentication: Interface "Http Authentication")
Parameters
| Name | Type | Description |
|---|---|---|
| HttpClientHandler | Interface System.RestClient."Http Client Handler" |
The Http Client Handler to use. |
| HttpAuthentication | Interface System.RestClient."Http Authentication" |
The authentication to use. |
SetDefaultRequestHeader
Sets a new value for an existing default header of the Http Client object, or addds the header if it does not already exist.
procedure SetDefaultRequestHeader(Name: Text, Value: Text)
Parameters
| Name | Type | Description |
|---|---|---|
| Name | Text |
The name of the request header. |
| Value | Text |
The header of request header. |
Remarks
Default request headers will be added to every request that is sent with this Rest Client instance The Rest Client will be initialized if it was not initialized before.
SetDefaultRequestHeader
Sets a new value for an existing default header of the Http Client object, or addds the header if it does not already exist.
procedure SetDefaultRequestHeader(Name: Text, Value: SecretText)
Parameters
| Name | Type | Description |
|---|---|---|
| Name | Text |
The name of the request header. |
| Value | SecretText |
The header of request header. |
Remarks
Default request headers will be added to every request that is sent with this Rest Client instance The Rest Client will be initialized if it was not initialized before.
SetBaseAddress
Sets the base address of the Rest Client.
procedure SetBaseAddress(Url: Text)
Parameters
| Name | Type | Description |
|---|---|---|
| Url | Text |
The base address to use. |
Remarks
The base address will be used for every request that is sent with this Rest Client instance. Calls to the Get, Post, Patch, Put and Delete methods must use a relative path which will be appended to the base address. The Rest Client will be initialized if it was not initialized before.
GetBaseAddress
Gets the base address of the Rest Client.
procedure GetBaseAddress(): Text
Returns
| Type | Description |
|---|---|
| Text |
The base address of the Rest Client. |
SetTimeOut
Sets the timeout of the Rest Client.
procedure SetTimeOut(Timeout: Duration)
Parameters
| Name | Type | Description |
|---|---|---|
| Timeout | Duration |
The timeout to use. |
Remarks
The timeout will be used for every request that is sent with this Rest Client instance. The Rest Client will be initialized if it was not initialized before.
GetTimeOut
Gets the timeout of the Rest Client.
procedure GetTimeOut(): Duration
Returns
| Type | Description |
|---|---|
| Duration |
The timeout of the Rest Client. |
AddCertificate
Adds a certificate to the Rest Client.
procedure AddCertificate(Certificate: Text)
Parameters
| Name | Type | Description |
|---|---|---|
| Certificate | Text |
The Base64 encoded certificate |
Remarks
The certificate will be used for every request that is sent with this Rest Client instance. The Rest Client will be initialized if it was not initialized before.
AddCertificate
Adds a certificate to the Rest Client.
procedure AddCertificate(Certificate: Text, Password: SecretText)
Parameters
| Name | Type | Description |
|---|---|---|
| Certificate | Text |
The Base64 encoded certificate |
| Password | SecretText |
The password of the certificate |
Remarks
The certificate will be used for every request that is sent with this Rest Client instance. The Rest Client will be initialized if it was not initialized before.
SetUseServerCertificateValidation
Sets the use of server certificate validation.
procedure SetUseServerCertificateValidation(Value: Boolean)
Parameters
| Name | Type | Description |
|---|---|---|
| Value | Boolean |
If true, the server certificate validation is enabled. False to disable |
Remarks
Use this function to enable or disable the server certificate validation. The Rest Client will be initialized if it was not initialized before.
SetUserAgentHeader
Sets the user agent header of the Rest Client.
procedure SetUserAgentHeader(Value: Text)
Parameters
| Name | Type | Description |
|---|---|---|
| Value | Text |
The user agent header to use. |
Remarks
Use this function to overwrite the default User-Agent header. The default user agent header is "Dynamics 365 Business Central - |[Publisher]| [App Name]/[App Version]". The Rest Client will be initialized if it was not initialized before.
SetAuthorizationHeader
Sets the authorization header of the Rest Client.
procedure SetAuthorizationHeader(Value: SecretText)
Parameters
| Name | Type | Description |
|---|---|---|
| Value | SecretText |
The authorization header to use. |
Remarks
Use this function to set the authorization header. The Rest Client will be initialized if it was not initialized before.
SetUseResponseCookies
Sets the use of response cookies in subsequent requests.
procedure SetUseResponseCookies(Value: Boolean)
Parameters
| Name | Type | Description |
|---|---|---|
| Value | Boolean |
If true, the client automatically attaches cookies received in the response to all subsequent requests. False to disable |
Remarks
Use this function to enable or disable automatically attach cookies received in the response to all subsequent requests. The Rest Client will be initialized if it was not initialized before.
Get
Sends a GET request to the specified Uri and returns the response message.
procedure Get(RequestUri: Text): Codeunit "Http Response Message"
Parameters
| Name | Type | Description |
|---|---|---|
| RequestUri | Text |
The Uri the request is sent to. |
Returns
| Type | Description |
|---|---|
| Codeunit System.RestClient."Http Response Message" |
The response message object |
Remarks
The function fails with a collectible error if the request could not be sent or a response was not received. If a response was received, then the response message object contains information about the status.
Post
Sends a POST request to the specified Uri and returns the response message.
procedure Post(RequestUri: Text, Content: Codeunit "Http Content"): Codeunit "Http Response Message"
Parameters
| Name | Type | Description |
|---|---|---|
| RequestUri | Text |
The Uri the request is sent to. |
| Content | Codeunit System.RestClient."Http Content" |
The content to send. |
Returns
| Type | Description |
|---|---|
| Codeunit System.RestClient."Http Response Message" |
The response message object |
Remarks
The function fails with a collectible error if the request could not be sent or a response was not received. If a response was received, then the response message object contains information about the status.
Patch
Sends a PATCH request to the specified Uri and returns the response message.
procedure Patch(RequestUri: Text, Content: Codeunit "Http Content"): Codeunit "Http Response Message"
Parameters
| Name | Type | Description |
|---|---|---|
| RequestUri | Text |
The Uri the request is sent to. |
| Content | Codeunit System.RestClient."Http Content" |
The content to send. |
Returns
| Type | Description |
|---|---|
| Codeunit System.RestClient."Http Response Message" |
The response message object |
Remarks
The function fails with a collectible error if the request could not be sent or a response was not received. If a response was received, then the response message object contains information about the status.
Put
Sends a PUT request to the specified Uri and returns the response message.
procedure Put(RequestUri: Text, Content: Codeunit "Http Content"): Codeunit "Http Response Message"
Parameters
| Name | Type | Description |
|---|---|---|
| RequestUri | Text |
The Uri the request is sent to. |
| Content | Codeunit System.RestClient."Http Content" |
The content to send. |
Returns
| Type | Description |
|---|---|
| Codeunit System.RestClient."Http Response Message" |
The response message object |
Remarks
The function fails with a collectible error if the request could not be sent or a response was not received. If a response was received, then the response message object contains information about the status.
Delete
Sends a DELETE request to the specified Uri and returns the response message.
procedure Delete(RequestUri: Text): Codeunit "Http Response Message"
Parameters
| Name | Type | Description |
|---|---|---|
| RequestUri | Text |
The Uri the request is sent to. |
Returns
| Type | Description |
|---|---|
| Codeunit System.RestClient."Http Response Message" |
The response message object |
Remarks
The function fails with a collectible error if the request could not be sent or a response was not received. If a response was received, then the response message object contains information about the status.
GetAsJson
Sends a GET request to the specified Uri and returns the response content as JsonToken.
procedure GetAsJson(RequestUri: Text): JsonToken
Parameters
| Name | Type | Description |
|---|---|---|
| RequestUri | Text |
The Uri the request is sent to. |
Returns
| Type | Description |
|---|---|
| JsonToken |
The response content as JsonToken |
Remarks
The function fails with a collectible error if the request could not be sent or a response was not received. The function also fails with a collectible error in case the response does not contain a success status code. In case the response contains no content, an empty JsonToken is returned. In case the response contains content, then the function fails with a collectible error if the content is invalid JSON.
PostAsJson
Sends a POST request to the specified Uri and returns the response content as JsonToken.
procedure PostAsJson(RequestUri: Text, Content: JsonObject): JsonToken
Parameters
| Name | Type | Description |
|---|---|---|
| RequestUri | Text |
The Uri the request is sent to. |
| Content | JsonObject |
The content to send as a JsonObject. |
Returns
| Type | Description |
|---|---|
| JsonToken |
The response content as JsonToken |
Remarks
The function fails with an error message if the request could not be sent or a response was not received. The function also fails with a collectible error in case the response does not contain a success status code. In case the response contains no content, an empty JsonToken is returned. In case the response contains content, then the function fails if the content is invalid JSON.
PostAsJson
Sends a POST request to the specified Uri and returns the response content as JsonToken.
procedure PostAsJson(RequestUri: Text, Content: JsonArray): JsonToken
Parameters
| Name | Type | Description |
|---|---|---|
| RequestUri | Text |
The Uri the request is sent to. |
| Content | JsonArray |
The content to send as a JsonArray. |
Returns
| Type | Description |
|---|---|
| JsonToken |
The response content as JsonToken |
Remarks
The function fails with an error message if the request could not be sent or a response was not received. The function also fails with a collectible error in case the response does not contain a success status code. In case the response contains no content, an empty JsonToken is returned. In case the response contains content, then the function fails if the content is invalid JSON.
PostAsJson
Sends a POST request to the specified Uri and returns the response content as JsonToken.
procedure PostAsJson(RequestUri: Text, Content: JsonToken): JsonToken
Parameters
| Name | Type | Description |
|---|---|---|
| RequestUri | Text |
The Uri the request is sent to. |
| Content | JsonToken |
The content to send as a JsonToken. |
Returns
| Type | Description |
|---|---|
| JsonToken |
The response content as JsonToken |
Remarks
The function fails with an error message if the request could not be sent or a response was not received. The function also fails with a collectible error in case the response does not contain a success status code. In case the response contains no content, an empty JsonToken is returned. In case the response contains content, then the function fails if the content is invalid JSON.
PatchAsJson
Sends a PATCH request to the specified Uri and returns the response content as JsonToken.
procedure PatchAsJson(RequestUri: Text, Content: JsonObject): JsonToken
Parameters
| Name | Type | Description |
|---|---|---|
| RequestUri | Text |
The Uri the request is sent to. |
| Content | JsonObject |
The content to send as a JsonObject. |
Returns
| Type | Description |
|---|---|
| JsonToken |
The response content as JsonToken |
Remarks
The function fails with an error message if the request could not be sent or a response was not received. The function also fails with a collectible error in case the response does not contain a success status code. In case the response contains no content, an empty JsonToken is returned. In case the response contains content, then the function fails if the content is invalid JSON.
PatchAsJson
Sends a PATCH request to the specified Uri and returns the response content as JsonToken.
procedure PatchAsJson(RequestUri: Text, Content: JsonArray): JsonToken
Parameters
| Name | Type | Description |
|---|---|---|
| RequestUri | Text |
The Uri the request is sent to. |
| Content | JsonArray |
The content to send as a JsonArray. |
Returns
| Type | Description |
|---|---|
| JsonToken |
The response content as JsonToken |
Remarks
The function fails with an error message if the request could not be sent or a response was not received. The function also fails with a collectible error in case the response does not contain a success status code. In case the response contains no content, an empty JsonToken is returned. In case the response contains content, then the function fails if the content is invalid JSON.
PatchAsJson
Sends a PATCH request to the specified Uri and returns the response content as JsonToken.
procedure PatchAsJson(RequestUri: Text, Content: JsonToken): JsonToken
Parameters
| Name | Type | Description |
|---|---|---|
| RequestUri | Text |
The Uri the request is sent to. |
| Content | JsonToken |
The content to send as a JsonToken. |
Returns
| Type | Description |
|---|---|
| JsonToken |
The response content as JsonToken |
Remarks
The function fails with an error message if the request could not be sent or a response was not received. The function also fails with a collectible error in case the response does not contain a success status code. In case the response contains no content, an empty JsonToken is returned. In case the response contains content, then the function fails if the content is invalid JSON.
PutAsJson
Sends a PUT request to the specified Uri and returns the response content as JsonToken.
procedure PutAsJson(RequestUri: Text, Content: JsonObject): JsonToken
Parameters
| Name | Type | Description |
|---|---|---|
| RequestUri | Text |
The Uri the request is sent to. |
| Content | JsonObject |
The content to send as a JsonObject. |
Returns
| Type | Description |
|---|---|
| JsonToken |
The response content as JsonToken |
Remarks
The function fails with an error message if the request could not be sent or a response was not received. The function also fails with a collectible error in case the response does not contain a success status code. In case the response contains no content, an empty JsonToken is returned. In case the response contains content, then the function fails if the content is invalid JSON.
PutAsJson
Sends a PUT request to the specified Uri and returns the response content as JsonToken.
procedure PutAsJson(RequestUri: Text, Content: JsonArray): JsonToken
Parameters
| Name | Type | Description |
|---|---|---|
| RequestUri | Text |
The Uri the request is sent to. |
| Content | JsonArray |
The content to send as a JsonArray. |
Returns
| Type | Description |
|---|---|
| JsonToken |
The response content as JsonToken |
Remarks
The function fails with an error message if the request could not be sent or a response was not received. The function also fails with a collectible error in case the response does not contain a success status code. In case the response contains no content, an empty JsonToken is returned. In case the response contains content, then the function fails if the content is invalid JSON.
PutAsJson
Sends a PUT request to the specified Uri and returns the response content as JsonToken.
procedure PutAsJson(RequestUri: Text, Content: JsonToken): JsonToken
Parameters
| Name | Type | Description |
|---|---|---|
| RequestUri | Text |
The Uri the request is sent to. |
| Content | JsonToken |
The content to send as a JsonToken. |
Returns
| Type | Description |
|---|---|
| JsonToken |
The response content as JsonToken |
Remarks
The function fails with an error message if the request could not be sent or a response was not received. The function also fails with a collectible error in case the response does not contain a success status code. In case the response contains no content, an empty JsonToken is returned. In case the response contains content, then the function fails if the content is invalid JSON.
Send
Sends a request with the specific Http method and an empty content to the specified Uri and returns the response message.
procedure Send(Method: Enum "Http Method", RequestUri: Text): Codeunit "Http Response Message"
Parameters
| Name | Type | Description |
|---|---|---|
| Method | Enum System.RestClient."Http Method" |
The HTTP method to use. |
| RequestUri | Text |
The Uri the request is sent to. |
Returns
| Type | Description |
|---|---|
| Codeunit System.RestClient."Http Response Message" |
The response message object |
Remarks
The function fails with a collectible error if the request could not be sent or a response was not received. If a response was received, then the response message object contains information about the status.
Send
Sends a request with the specific Http method and the given content to the specified Uri and returns the response message.
procedure Send(Method: Enum "Http Method", RequestUri: Text, Content: Codeunit "Http Content"): Codeunit "Http Response Message"
Parameters
| Name | Type | Description |
|---|---|---|
| Method | Enum System.RestClient."Http Method" |
The HTTP method to use. |
| RequestUri | Text |
The Uri the request is sent to. |
| Content | Codeunit System.RestClient."Http Content" |
The content to send. |
Returns
| Type | Description |
|---|---|
| Codeunit System.RestClient."Http Response Message" |
The response message object |
Remarks
The function fails with a collectible error if the request could not be sent or a response was not received. If a response was received, then the response message object contains information about the status.
Send
Sends the given request message and returns the response message.
procedure Send(var HttpRequestMessage: Codeunit "Http Request Message"): Codeunit "Http Response Message"
Parameters
| Name | Type | Description |
|---|---|---|
| HttpRequestMessage | Codeunit System.RestClient."Http Request Message" |
The request message to send. |
Returns
| Type | Description |
|---|---|
| Codeunit System.RestClient."Http Response Message" |
The response message object |
Remarks
The function fails with a collectible error if the request could not be sent or a response was not received.