2

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
  • Were you able to create list alert by this method? I am also trying this approach and I also have same queries as you had. Please let me know if there is any solution on this.
    – Krithi
    Jul 10, 2020 at 11:11
  • AFAIR it did not work over Rest (see Bad Gateway comment below) and we switched to An Azure Function using CSOM.
    – ben
    Jul 16, 2020 at 11:02

1 Answer 1

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

6
  • 2
    This is looking good, but unlike the CSOM Version I cannot reference a list. Where do I put this parameter?
    – ben
    Apr 29, 2019 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, 2019 at 7:11
  • You can access /_api/$metadata to see the REST API metadata.
    – LZ_MSFT
    Apr 29, 2019 at 8:29
  • 1
    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, 2019 at 11:44
  • 1
    Hi @ben If possible, could you please your rest code here. I am trying to implement the same thing(create alert using REST API) but I am not able to do it. Sep 17, 2020 at 11:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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