Skip to content

KVSEDX OAuth WebRequestHelper#

Summary: This codeunit serves as a streamlined helper to create and send Web Requests both with and without OAuth Connections In order to do so this codeunit provides several functions to send Web Requests and evaluate the results provided by the received responses.

Procedures#

AddAdditionalRequestHeader(Text, Text) :#

Summary: This function adds an additional request header for the next Web Request sent with this codeunit.

procedure AddAdditionalRequestHeader(HeaderKey: Text; HeaderValue: Text): 

Parameters:

  • HeaderKey: Specifies the name of the header
  • HeaderValue: Specifies the value of the header

AddAdditionalContentHeader(Text, Text) :#

Summary: This function adds an additional content header for the next Web Request sent with this codeunit.

procedure AddAdditionalContentHeader(HeaderKey: Text; HeaderValue: Text): 

Parameters:

  • HeaderKey: Specifies the name of the header
  • HeaderValue: Specifies the value of the header

SetRequestTimeOutInSeconds(Integer) :#

Summary: Specifies the maximum time BC will wait for a response after sending a request. If not specified the default value of 60 Seconds will be used.

procedure SetRequestTimeOutInSeconds(NewValue: Integer): 

Parameters:

  • NewValue: Specifies the allowed time out in seconds.

SetForceUsePreviouslyRetrievedAccessToken(Boolean) :#

Summary: Specifies if the system should not check / update Access Tokens for the following Web Requests sent with this codeunit and instead simply use the previously acquired token. Use this function if you call several Web Requests in rapid succession to improve performance. Call the function after the first Web Request has been sent or a Token has been manually retrieved.

procedure SetForceUsePreviouslyRetrievedAccessToken(NewValue: Boolean): 

Parameters:

  • NewValue: Specifies whether the system should use the previously acquired Token

SendRequestGeneric(Record KVSEDX OAuth Connections, Boolean, Text, Text, Text) : Boolean#

Summary: Sends a Web Request without content to the OAuth Connections Service URL and returns the result provided by the Web Response.

procedure SendRequestGeneric(var KVSEDXOAuthConnections: Record "KVSEDX OAuth Connections"; ShowError: Boolean; SubURL: Text; Method: Text; var ResponseText: Text): Boolean

Parameters:

  • KVSEDXOAuthConnections: Specifies the OAuth Connection containing the Service URL to call.
  • ShowError: Specifies whether errors occuring while sending the Web Request should be displayed as error messages.
  • SubURL: Specifies the resource you like to adress with this Web Request. This parameter will be appended to the OAuth Connections Service URL to create the complete URL the Request will be sent to.
  • Method: Specifies the HTTP Method to use, like GET or POST.
  • ResponseText: Specifies the content of the received Web Response as text.

Returns: This functions will return TRUE if the Web Response could be retrieved successfully and when the Web Response contains a Status Code indicating success.

SendRequestGeneric(Record KVSEDX OAuth Connections, Boolean, Text, Text, HttpResponseMessage) : Boolean#

Summary: Sends a Web Request without content to the OAuth Connections Service URL and returns the result provided by the Web Response.

procedure SendRequestGeneric(var KVSEDXOAuthConnections: Record "KVSEDX OAuth Connections"; ShowError: Boolean; SubURL: Text; Method: Text; var APIHttpResponseMessage: HttpResponseMessage): Boolean

Parameters:

  • KVSEDXOAuthConnections: Specifies the OAuth Connection containing the Service URL to call.
  • ShowError: Specifies whether errors occuring while sending the Web Request should be displayed as error messages.
  • SubURL: Specifies the resource you like to adress with this Web Request. This parameter will be appended to the OAuth Connections Service URL to create the complete URL the Request will be sent to.
  • Method: Specifies the HTTP Method to use, like GET or POST.
  • APIHttpResponseMessage: Specifies the complete received Web Response.

Returns: This functions will return TRUE if the Web Response could be retrieved successfully and when the Web Response contains a Status Code indicating success.

SendRequestGeneric(Record KVSEDX OAuth Connections, Boolean, Text, Text, InStream, Text, HttpResponseMessage) : Boolean#

Summary: Sends a Web Request with content to the OAuth Connections Service URL and returns the result provided by the Web Response.

procedure SendRequestGeneric(var KVSEDXOAuthConnections: Record "KVSEDX OAuth Connections"; ShowError: Boolean; SubURL: Text; Method: Text; ContentInStream: InStream; ContentType: Text; var APIHttpResponseMessage: HttpResponseMessage): Boolean

Parameters:

  • KVSEDXOAuthConnections: Specifies the OAuth Connection containing the Service URL to call.
  • ShowError: Specifies whether errors occuring while sending the Web Request should be displayed as error messages.
  • SubURL: Specifies the resource you like to adress with this Web Request. This parameter will be appended to the OAuth Connections Service URL to create the complete URL the Request will be sent to.
  • Method: Specifies the HTTP Method to use, like GET or POST.
  • ContentInStream: Specifies content of this Web Request.
  • ContentType: Specifies the type of data provided with the content like application/json.
  • APIHttpResponseMessage: Specifies the complete received Web Response.

Returns: This functions will return TRUE if the Web Response could be retrieved successfully and when the Web Response contains a Status Code indicating success.

SendRequestGeneric(Record KVSEDX OAuth Connections, Boolean, Text, Text, Text, Text, HttpResponseMessage) : Boolean#

Summary: Sends a Web Request with content to the OAuth Connections Service URL and returns the result provided by the Web Response.

procedure SendRequestGeneric(var KVSEDXOAuthConnections: Record "KVSEDX OAuth Connections"; ShowError: Boolean; SubURL: Text; Method: Text; Content: Text; ContentType: Text; var APIHttpResponseMessage: HttpResponseMessage): Boolean

Parameters:

  • KVSEDXOAuthConnections: Specifies the OAuth Connection containing the Service URL to call.
  • ShowError: Specifies whether errors occuring while sending the Web Request should be displayed as error messages.
  • SubURL: Specifies the resource you like to adress with this Web Request. This parameter will be appended to the OAuth Connections Service URL to create the complete URL the Request will be sent to.
  • Method: Specifies the HTTP Method to use, like GET or POST.
  • Content: Specifies content of this Web Request.
  • ContentType: Specifies the type of data provided with the content like application/json.
  • APIHttpResponseMessage: Specifies the complete received Web Response.

Returns: This functions will return TRUE if the Web Response could be retrieved successfully and when the Web Response contains a Status Code indicating success.

SendRequestGeneric(Record KVSEDX OAuth Connections, Boolean, Text, Text, InStream, Text, Text) : Boolean#

Summary: Sends a Web Request with content to the OAuth Connections Service URL and returns the result provided by the Web Response.

procedure SendRequestGeneric(var KVSEDXOAuthConnections: Record "KVSEDX OAuth Connections"; ShowError: Boolean; SubURL: Text; Method: Text; ContentInStream: InStream; ContentType: Text; var Response: Text): Boolean

Parameters:

  • KVSEDXOAuthConnections: Specifies the OAuth Connection containing the Service URL to call.
  • ShowError: Specifies whether errors occuring while sending the Web Request should be displayed as error messages.
  • SubURL: Specifies the resource you like to adress with this Web Request. This parameter will be appended to the OAuth Connections Service URL to create the complete URL the Request will be sent to.
  • Method: Specifies the HTTP Method to use, like GET or POST.
  • ContentInStream: Specifies content of this Web Request.
  • ContentType: Specifies the type of data provided with the content like application/json.
  • Response: Specifies the content of the received Web Response as text.

Returns: This functions will return TRUE if the Web Response could be retrieved successfully and when the Web Response contains a Status Code indicating success.

SendRequestGeneric(Record KVSEDX OAuth Connections, Boolean, Text, Text, Text, Text, Text) : Boolean#

Summary: Sends a Web Request with content to the OAuth Connections Service URL and returns the result provided by the Web Response.

procedure SendRequestGeneric(var OAuthConnections: Record "KVSEDX OAuth Connections"; ShowError: Boolean; SubURL: Text; Method: Text; Content: Text; ContentType: Text; var Response: Text): Boolean

Parameters:

  • OAuthConnections: Specifies the OAuth Connection containing the Service URL to call.
  • ShowError: Specifies whether errors occuring while sending the Web Request should be displayed as error messages.
  • SubURL: Specifies the resource you like to adress with this Web Request. This parameter will be appended to the OAuth Connections Service URL to create the complete URL the Request will be sent to.
  • Method: Specifies the HTTP Method to use, like GET or POST.
  • Content: Specifies content of this Web Request.
  • ContentType: Specifies the type of data provided with the content like application/json.
  • Response: Specifies the content of the received Web Response as text.

Returns: This functions will return TRUE if the Web Response could be retrieved successfully and when the Web Response contains a Status Code indicating success.

SendRequestGenericWithoutOAuthConnection(Boolean, Text, Text, InStream, Text, Text) : Boolean#

Summary: Sends a Web Request without utilizing a OAuth Connection.

procedure SendRequestGenericWithoutOAuthConnection(ShowError: Boolean; FullURL: Text; Method: Text; ContentInStream: InStream; ContentType: Text; var Response: Text): Boolean

Parameters:

  • ShowError: Specifies whether errors occuring while sending the Web Request should be displayed as error messages.
  • FullURL: Specifies the complete URL this Web Service should adress.
  • Method: Specifies the HTTP Method to use, like GET or POST.
  • ContentInStream: Specifies content of this Web Request.
  • ContentType: Specifies the type of data provided with the content like application/json.
  • Response: Specifies the content of the received Web Response as text.

Returns:

SendRequestGenericWithoutOAuthConnection(Boolean, Text, Text, Text, Text, Text) : Boolean#

Summary: Sends a Web Request without utilizing a OAuth Connection.

procedure SendRequestGenericWithoutOAuthConnection(ShowError: Boolean; FullURL: Text; Method: Text; Content: Text; ContentType: Text; var Response: Text): Boolean

Parameters:

  • ShowError: Specifies whether errors occuring while sending the Web Request should be displayed as error messages.
  • FullURL: Specifies the complete URL this Web Service should adress.
  • Method: Specifies the HTTP Method to use, like GET or POST.
  • Content: Specifies content of this Web Request.
  • ContentType: Specifies the type of data provided with the content like application/json.
  • Response: Specifies the content of the received Web Response as text.

Returns:

GetErrorTextFromJSONResponse(Text) : Text#

Summary: This function tries to extract the error message provided from a failed Web Response's content provided as JSON. If no error message can be extracted the provided parameter will be returned.

procedure GetErrorTextFromJSONResponse(ResponseText: Text): Text

Parameters:

  • ResponseText: Specifies the JSON content containing the error message

Returns: Returns the contained error message

GetErrorCodeFromJSONResponse(Text) : Text#

Summary: This function tries to extract the error code provided from a failed Web Response's content provided as JSON. If no error code can be extracted the provided parameter will be returned.

procedure GetErrorCodeFromJSONResponse(ResponseText: Text): Text

Parameters:

  • ResponseText: Specifies the JSON content containing the error code

Returns: Returns the contained error code

GetValueTextFromJSONResponse(Text) : Text#

Summary: This function tries to extract the value provided from a successfull Web Response's content provided as JSON. The function assumes the value will be stored in a node called "Value" in the Response.

procedure GetValueTextFromJSONResponse(ResponseText: Text): Text

Parameters:

  • ResponseText: Specifies the JSON content containing the value

Returns: Returns the value

GetValueTextFromJSONResponse(JsonObject) : Text#

Summary: This function tries to extract the value provided from a successfull Web Response's content provided as JSON. The function assumes the value will be stored in a node called "Value" in the Response.

procedure GetValueTextFromJSONResponse(JObject: JsonObject): Text

Parameters:

  • ResponseText: Specifies the JSON content containing the value

Returns: Returns the value