Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

List webhooks feature. #630

Merged
merged 1 commit into from
Nov 17, 2021
Merged

List webhooks feature. #630

merged 1 commit into from
Nov 17, 2021

Conversation

s-KaiNet
Copy link
Collaborator

This PR adds support for the SharePoint list webhooks API.

✔ Unit tests added
✔ Docs updated
✔ The API is similar to the PnP.Framework for easier migrations

Closes #217

@codecov-commenter
Copy link

Codecov Report

Merging #630 (258f109) into dev (c13436b) will increase coverage by 6.89%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##              dev     #630      +/-   ##
==========================================
+ Coverage   75.32%   82.22%   +6.89%     
==========================================
  Files         257      411     +154     
  Lines       19708    28266    +8558     
==========================================
+ Hits        14846    23242    +8396     
- Misses       4862     5024     +162     
Impacted Files Coverage Δ
...del/SharePoint/Core/Internal/FieldLocationValue.cs 0.00% <0.00%> (-35.49%) ⬇️
...ore.Auth/Utilities/ApplicationBuilderExtensions.cs 62.06% <0.00%> (-26.17%) ⬇️
...h/Public/UsernamePasswordAuthenticationProvider.cs 68.60% <0.00%> (-25.52%) ⬇️
...P.Core/QueryModel/Query/BaseDataModelExtensions.cs 38.88% <0.00%> (-23.07%) ⬇️
...k/PnP.Core/Model/Teams/Internal/TeamIdentitySet.cs 50.00% <0.00%> (-16.67%) ⬇️
src/sdk/PnP.Core/Utilities/StringExtensions.cs 85.07% <0.00%> (-14.93%) ⬇️
.../Model/Teams/Internal/TeamChatMessageAttachment.cs 85.71% <0.00%> (-14.29%) ⬇️
...e/Model/SharePoint/Core/Internal/StorageMetrics.cs 77.77% <0.00%> (-9.73%) ⬇️
...rc/sdk/PnP.Core/Services/Core/Query/QueryClient.cs 77.65% <0.00%> (-8.20%) ⬇️
....Core/QueryModel/Query/DataModelQueryTranslator.cs 77.61% <0.00%> (-7.11%) ⬇️
... and 277 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 621061f...258f109. Read the comment docs.

@s-KaiNet
Copy link
Collaborator Author

Notes for testing. We cannot test webhooks in online mode without actual service. I used below very simple code based on OOB Azure Functions project (.NET 5) in VS:

Code
public static class Function1
{
	[Function("HandleEvent")]
	public static HttpResponseData RunAsync([HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequestData req,
		FunctionContext executionContext)
	{
		var logger = executionContext.GetLogger(nameof(Function1));
		logger.LogInformation("C# HTTP trigger function processed a request.");

		var query = System.Web.HttpUtility.ParseQueryString(req.Url.Query);
		var token = query["validationtoken"];

		if (!string.IsNullOrEmpty(token))
		{
			var tokenResponse = req.CreateResponse(HttpStatusCode.OK);
			tokenResponse.Headers.Add("Content-Type", "text/plain");
			tokenResponse.WriteString(token);
			return tokenResponse;
		}

		var response = req.CreateResponse(HttpStatusCode.OK);
		response.Headers.Add("Content-Type", "text/plain");
		return response;
	}

	[Function("HandleEventNew")]
	public static HttpResponseData RunAsync2([HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequestData req,
		FunctionContext executionContext)
	{
		var logger = executionContext.GetLogger(nameof(Function1));
		logger.LogInformation("C# HTTP trigger function processed a request.");

		var query = System.Web.HttpUtility.ParseQueryString(req.Url.Query);
		var token = query["validationtoken"];

		if (!string.IsNullOrEmpty(token))
		{
			var tokenResponse = req.CreateResponse(HttpStatusCode.OK);
			tokenResponse.Headers.Add("Content-Type", "text/plain");
			tokenResponse.WriteString(token);
			return tokenResponse;
		}

		var response = req.CreateResponse(HttpStatusCode.OK);
		response.Headers.Add("Content-Type", "text/plain");

		return response;
	}
}

And ngrok service:

ngrok http 7071 --host-header=localhost

@jansenbe
Copy link
Contributor

Wow, another great PR @s-KaiNet 💪🥇🎉🚀Thanks a ton for helping out!!

@jansenbe jansenbe self-assigned this Nov 17, 2021
@jansenbe jansenbe merged commit be8188f into pnp:dev Nov 17, 2021
@s-KaiNet s-KaiNet deleted the webhooks-impl branch November 21, 2021 12:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create model for SP Web Hook Subscriptions
3 participants