2017-09-24 86 views
0

我試圖使用REST API來取消一個待發送給單個用戶的同時也使用API​​(使用include_player_ids和單個收件人)的通知,但是如果不通過REST API,我無法做到這一點關鍵,這不應該發生,因爲在manual它說在我發送這個條件是沒有必要的。OneSignal刪除通知

我做錯了什麼或者可能是OneSignal服務的問題?下面是代碼:

//Creates the notification 
$.post(
    "https://onesignal.com/api/v1/notifications", 
    { 
     "app_id": appId, 
     "include_player_ids": [userId], 
     "send_after": later, 
     "template_id": templateId 
    }, 
    function(data){ 
     localStorage.ni = data.id; 
    } 
); 

//Cancel the notification 
var notificationId = localStorage.ni; 
$.get("https://onesignal.com/api/v1/notifications/"+notificationId+"?app_id="+appId); 

下面是取消請求的響應:

{ 
    "errors": 
     [ 
      "Please include a case-sensitive header of Authorization: Basic <YOUR-REST-API-KEY-HERE> with a valid REST API key." 
     ], 
    "reference": 
     [ 
      "https://documentation.onesignal.com/docs/accounts-and-keys#section-keys-ids" 
     ] 
} 

回答

0

答案是比我想象的更容易。要排除通知,我不能使用$.get(),我必須明確說我想刪除他們。

所以,這個工作得很好:

$.ajax({ 
    url: "https://onesignal.com/api/v1/notifications/"+notificationId+"?app_id="+appId, 
    type: "DELETE" 
});