From 48270f67c2b0d29b6ca47c97737495d998ab6131 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edgar=20Albalate=20Iba=C3=B1ez?= Date: Wed, 20 Mar 2024 14:28:25 +0100 Subject: [PATCH] [BC Idea] Add Put method to 'Graph Client' Codeunit (#773) #### Summary This implement's HTTP Put Method in Graph API Wrapper. #### Work Item(s) Fixes microsoft/BCApps#748 Fixes [AB#507963](https://dynamicssmb2.visualstudio.com/1fcb79e7-ab07-432a-a3c6-6cf5a88ba4a5/_workitems/edit/507963) --- .../MicrosoftGraph/src/GraphClient.Codeunit.al | 15 +++++++++++++++ .../src/GraphClientImpl.Codeunit.al | 10 ++++++++++ .../src/helper/GraphRequestHelper.Codeunit.al | 5 +++++ 3 files changed, 30 insertions(+) diff --git a/src/System Application/App/MicrosoftGraph/src/GraphClient.Codeunit.al b/src/System Application/App/MicrosoftGraph/src/GraphClient.Codeunit.al index a6bd7e9e73..e3afa0b693 100644 --- a/src/System Application/App/MicrosoftGraph/src/GraphClient.Codeunit.al +++ b/src/System Application/App/MicrosoftGraph/src/GraphClient.Codeunit.al @@ -112,6 +112,21 @@ codeunit 9350 "Graph Client" exit(GraphClientImpl.Patch(RelativeUriToResource, GraphOptionalParameters, RequestHttpContent, HttpResponseMessage)); end; + /// + /// Put any request to the microsoft graph API + /// + /// Does not require UI interaction. + /// A relativ uri including the resource segment + /// A wrapper for optional header and query parameters + /// The HttpContent object for the request. + /// The response message object. + /// True if the operation was successful; otherwise - false. + /// Authentication failed. + procedure Put(RelativeUriToResource: Text; GraphOptionalParameters: Codeunit "Graph Optional Parameters"; RequestHttpContent: Codeunit "Http Content"; var HttpResponseMessage: Codeunit "Http Response Message"): Boolean + begin + exit(GraphClientImpl.Put(RelativeUriToResource, GraphOptionalParameters, RequestHttpContent, HttpResponseMessage)); + end; + /// /// Send a DELETE request to the microsoft graph API /// diff --git a/src/System Application/App/MicrosoftGraph/src/GraphClientImpl.Codeunit.al b/src/System Application/App/MicrosoftGraph/src/GraphClientImpl.Codeunit.al index 294865cbf0..c5bc81456f 100644 --- a/src/System Application/App/MicrosoftGraph/src/GraphClientImpl.Codeunit.al +++ b/src/System Application/App/MicrosoftGraph/src/GraphClientImpl.Codeunit.al @@ -79,6 +79,16 @@ codeunit 9351 "Graph Client Impl." exit(HttpResponseMessage.GetIsSuccessStatusCode()); end; + procedure Put(RelativeUriToResource: Text; GraphOptionalParameters: Codeunit "Graph Optional Parameters"; RequestHttpContent: Codeunit "Http Content"; var HttpResponseMessage: Codeunit "Http Response Message"): Boolean + var + GraphUriBuilder: Codeunit "Graph Uri Builder"; + begin + GraphUriBuilder.Initialize(MicrosoftGraphBaseUrl, GraphAPIVersion, RelativeUriToResource, GraphOptionalParameters.GetQueryParameters()); + GraphRequestHelper.SetRestClient(RestClient); + HttpResponseMessage := GraphRequestHelper.Put(GraphUriBuilder, GraphOptionalParameters, RequestHttpContent); + exit(HttpResponseMessage.GetIsSuccessStatusCode()); + end; + procedure Delete(RelativeUriToResource: Text; GraphOptionalParameters: Codeunit "Graph Optional Parameters"; var HttpResponseMessage: Codeunit "Http Response Message"): Boolean var GraphUriBuilder: Codeunit "Graph Uri Builder"; diff --git a/src/System Application/App/MicrosoftGraph/src/helper/GraphRequestHelper.Codeunit.al b/src/System Application/App/MicrosoftGraph/src/helper/GraphRequestHelper.Codeunit.al index edae59b73e..d4a137f238 100644 --- a/src/System Application/App/MicrosoftGraph/src/helper/GraphRequestHelper.Codeunit.al +++ b/src/System Application/App/MicrosoftGraph/src/helper/GraphRequestHelper.Codeunit.al @@ -36,6 +36,11 @@ codeunit 9354 "Graph Request Helper" HttpResponseMessage := SendRequest(Enum::"Http Method"::PATCH, GraphUriBuilder, GraphOptionalParameters, HttpContent); end; + procedure Put(GraphUriBuilder: Codeunit "Graph Uri Builder"; GraphOptionalParameters: Codeunit "Graph Optional Parameters"; HttpContent: Codeunit "Http Content") HttpResponseMessage: Codeunit "Http Response Message" + begin + HttpResponseMessage := SendRequest(Enum::"Http Method"::PUT, GraphUriBuilder, GraphOptionalParameters, HttpContent); + end; + procedure Delete(GraphUriBuilder: Codeunit "Graph Uri Builder"; GraphOptionalParameters: Codeunit "Graph Optional Parameters") HttpResponseMessage: Codeunit "Http Response Message" begin PrepareRestClient(GraphOptionalParameters);