0

I want to create a list alert using the rest endpoint _api/web/alerts/add. For this I build a JSON-string representing an AlertCreationInformation-object.

I tested this AlertCreationInformation-object using CSOM Web.Alerts.Add() and it works perfectly. But when POSTing this to _api/web/alerts/add things break.

Headers:

{
  "Accept ": "application/json;odata=verbose",
  "Content-Type": "application/json;odata=verbose"
}

Payload:

{
  "AlertFrequency": 2,
  "AlertTemplateName": "SPAlertTemplateType.WebPageLibrary",
  "AlertType": 2,
  "AlwaysNotify": "true",
  "DeliveryChannels": 1,
  "EventType": 1,
  "Filter": "<Query><And><Or><Eq><FieldRef Name=\"SomeField\"/><Value type=\"string\">Word</Value></Eq><Eq><FieldRef Name=\"SomeField\"/><Value type=\"string\">Excel</Value></Eq></Or><Or><Eq><FieldRef Name=\"SomeSkill\"/><Value type=\"string\">2 - Fortgeschritten</Value></Eq></Or></And></Query>",
  "List": "3b80d325-4031-4de5-ae7f-5f6dd5f86b72",
  "Title": "My Filtered Notification",
  "User": 6
}

Error:

{
  "status": 400,
  "message": "The parameter \"AlertFrequency\" does not exist in the method \"Add\".\r\nclientRequestId: 77c80643-3a85-4c9e-8692-a3e19dafa988\r\nserviceRequestId: 02d5e69e-607c-8000-893a-517bd9aa37e8",
  "source": "https://mytenant.sharepoint.com/sites/somesite/_api/web/alerts/add",
  "errors": [
    "-1",
    "Microsoft.SharePoint.Client.InvalidClientQueryException"
  ]
}

The error-message always cites the first parameter in the JSON-object when I change the order. I also tried adding the property "__metadata": { "type": "SP.AlertCreationInformation" } or wrapping the AlertCreationInformation object inside { "parameters": { .. object here ... }. Still the same error, just referencing the properties __metadata or parameters.

How do I get this working?

2
+100

You can pass data like this:

{
    "alertCreationInformation":{    
        "__metadata":{"type": "SP.AlertCreationInformation"},
        ...
    }
}

And the SP.AlertCreationInformation properties as below.

Property             Type
AlertFrequency       Int32
AlertTemplateName    String
AlertTime            DateTime
AlertType            Int32
AlwaysNotify         Boolean
DeliveryChannels     Int32
EventType            Int32
EventTypeBitmask     Int32
Filter               String
Properties           Collection (SP.KeyValue)
Status               Int32
Title                String

Refer to: SharePoint REST API Metadata Explorer

  • This is looking good, but unlike the CSOM Version I cannot reference a list. Where do I put this parameter? – ben Apr 29 '19 at 7:09
  • Fetching the existing alerts by _api/web/alerts also does not point the alerts to any list... Or do I just point to the ViewID... will try this. – ben Apr 29 '19 at 7:11
  • You can access /_api/$metadata to see the REST API metadata. – LZ_MSFT Apr 29 '19 at 8:29
  • Your answer worked so far, that I can POST the request to the endpoint and I get no more errors concerning bad parameters or the like, but now I get "502 Bad Gateway" without any more helpful details. But as you answered the initial question, the bounty is yours. – ben Apr 29 '19 at 11:44
  • Oh, I have to wait 8 hours before award the bounty to you SO said. – ben Apr 29 '19 at 11:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.