Skip to content

Commit c6f78f5

Browse files
committed
add option to manually set requestId on AddBatchRequestStepAsync
1 parent 766c000 commit c6f78f5

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/Microsoft.Graph.Core/Requests/Content/BatchRequestContent.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,17 @@ public string AddBatchRequestStep(HttpRequestMessage httpRequestMessage)
130130
/// Adds a <see cref="RequestInformation"/> to batch request content
131131
/// </summary>
132132
/// <param name="requestInformation">A <see cref="RequestInformation"/> to use to build a <see cref="BatchRequestStep"/> to add.</param>
133+
/// <param name="requestId">An optional string that will be used as the requestId of the batch request</param>
133134
/// <returns>The requestId of the newly created <see cref="BatchRequestStep"/></returns>
134135
[Obsolete("Please use the BatchRequestContentCollection for making batch requests as it supports handling more than 20 requests and provides a similar API experience.")]
135-
public async Task<string> AddBatchRequestStepAsync(RequestInformation requestInformation)
136+
public async Task<string> AddBatchRequestStepAsync(RequestInformation requestInformation, string requestId = null)
136137
{
137138
if (BatchRequestSteps.Count >= CoreConstants.BatchRequest.MaxNumberOfRequests)
138139
throw new ArgumentException(string.Format(ErrorConstants.Messages.MaximumValueExceeded, "Number of batch request steps", CoreConstants.BatchRequest.MaxNumberOfRequests));
139-
string requestId = Guid.NewGuid().ToString();
140+
if (requestId == null)
141+
{
142+
requestId = Guid.NewGuid().ToString();
143+
}
140144
var requestMessage = await RequestAdapter.ConvertToNativeRequestAsync<HttpRequestMessage>(requestInformation);
141145
BatchRequestStep batchRequestStep = new BatchRequestStep(requestId, requestMessage);
142146
(BatchRequestSteps as IDictionary<string, BatchRequestStep>)!.Add(batchRequestStep.RequestId, batchRequestStep);

src/Microsoft.Graph.Core/Requests/Content/BatchRequestContentCollection.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,13 @@ public string AddBatchRequestStep(HttpRequestMessage httpRequestMessage)
101101
/// Adds a <see cref="RequestInformation"/> to batch request content
102102
/// </summary>
103103
/// <param name="requestInformation">A <see cref="RequestInformation"/> to use to build a <see cref="BatchRequestStep"/> to add.</param>
104+
/// <param name="requestId">An optional string that will be used as the requestId of the batch request</param>
104105
/// <returns>The requestId of the newly created <see cref="BatchRequestStep"/></returns>
105-
public Task<string> AddBatchRequestStepAsync(RequestInformation requestInformation)
106+
public Task<string> AddBatchRequestStepAsync(RequestInformation requestInformation, string requestId = null)
106107
{
107108
SetupCurrentRequest();
108109
#pragma warning disable CS0618
109-
return currentRequest.AddBatchRequestStepAsync(requestInformation);
110+
return currentRequest.AddBatchRequestStepAsync(requestInformation, requestId);
110111
#pragma warning restore CS0618
111112
}
112113

0 commit comments

Comments
 (0)