Search code examples
push-notificationibm-cloudibm-mobile-services

Bluemix push notification, got 400 when subscribeToTags


I called let push = IMFPushClient.sharedInstance() logger?.logInfoWithMessages("subscribe to tags: \(tagsArray)") push.subscribeToTags([tagsArray]) { (response: IMFResponse!, error: NSError!) -> Void in to subscribe to a tag, but got 400 from the stacktrace.

2016-01-22 16:48:10.648 gschat-swift[44084:5194666] [INFO] [BlueList] subscribe to tags: ["Test"]
2016-01-22 16:48:10.648 gschat-swift[44084:5194666] [INFO] [IMFPushClient] -[IMFPushClient subscribeToTags:completionHandler:] in IMFPushClient.m:314 :: Entering: subscribeToTags.
2016-01-22 16:48:10.650 gschat-swift[44084:5194666] [DEBUG] [IMF] +[WLAFHTTPClientWrapper requestWithURL:] in WLAFHTTPClientWrapper.m:44 :: Request url is https://ChatBMS.mybluemix.net/imfpush/v1/apps/2b7d11a9-57bf-47e6-8a4c-8aabf044ac8a/subscriptions
2016-01-22 16:48:10.653 gschat-swift[44084:5194666] [DEBUG] [IMF] -[WLAFHTTPClientWrapper start] in WLAFHTTPClientWrapper.m:194 :: Starting the request with URL https://ChatBMS.mybluemix.net/imfpush/v1/apps/2b7d11a9-57bf-47e6-8a4c-8aabf044ac8a/subscriptions
2016-01-22 16:48:11.255 gschat-swift[44084:5194362] [DEBUG] [IMF] -[WLAFHTTPClientWrapper requestFailed:error:] in WLAFHTTPClientWrapper.m:215 :: Request Failed
2016-01-22 16:48:11.256 gschat-swift[44084:5194362] [DEBUG] [IMF] -[WLAFHTTPClientWrapper requestFailed:error:] in WLAFHTTPClientWrapper.m:216 :: Response Status Code : 400
2016-01-22 16:48:11.257 gschat-swift[44084:5194362] [DEBUG] [IMF] -[WLAFHTTPClientWrapper requestFailed:error:] in WLAFHTTPClientWrapper.m:217 :: Response Error : Expected status code in (200-299), got 400
2016-01-22 16:48:11.259 gschat-swift[44084:5194362] [ERROR] [IMFPushClient] __51-[IMFPushClient subscribeToTags:completionHandler:]_block_invoke in IMFPushClient.m:350 :: Error while subscribing to tags - Error is: Error Domain=WLAFNetworkingErrorDomain Code=-1011 "Expected status code in (200-299), got 400" UserInfo={WLAFNetworkingOperationFailingURLRequestErrorKey=<NSMutableURLRequest: 0x7f89b8d8dd10> { URL: https://ChatBMS.mybluemix.net/imfpush/v1/apps/2b7d11a9-57bf-47e6-8a4c-8aabf044ac8a/subscriptions }, NSLocalizedRecoverySuggestion={"message":"Bad Request - Invalid JSON","code":"FPWSE0004E"}, NSErrorFailingURLKey=https://ChatBMS.mybluemix.net/imfpush/v1/apps/2b7d11a9-57bf-47e6-8a4c-8aabf044ac8a/subscriptions, WLAFNetworkingOperationFailingURLResponseErrorKey=<NSHTTPURLResponse: 0x7f89b8eb7f00> { URL: https://chatbms.mybluemix.net/imfpush/v1/apps/2b7d11a9-57bf-47e6-8a4c-8aabf044ac8a/subscriptions } { status code: 400, headers {
    Connection = "Keep-Alive";
    "Content-Type" = "application/json";
    Date = "Fri, 22 Jan 2016 16:48:09 GMT";
    "Transfer-Encoding" = Identity;
    "X-Backside-Transport" = "FAIL FAIL";
    "X-Cf-Requestid" = "cf162009-bd95-46d2-46ca-3cad50a70153";
    "X-Client-IP" = "80.111.218.187";
    "X-Global-Transaction-ID" = 2240839783;
    "X-Powered-By" = "Servlet/3.0";
} }, NSLocalizedDescription=Expected status code in (200-299), got 400}
2016-01-22 16:48:11.260 **gschat-swift[44084:5194362] [FATAL] [BlueList] error Error Domain=com.ibm.mobilefoundation.push Code=10 "Expected status code in (200-299), got 400" UserInfo={WLAFNetworkingOperationFailingURLRequestErrorKey=<NSMutableURLRequest: 0x7f89b8d8dd10> { URL: https://ChatBMS.mybluemix.net/imfpush/v1/apps/2b7d11a9-57bf-47e6-8a4c-8aabf044ac8a/subscriptions }, NSLocalizedRecoverySuggestion={"message":"Bad Request - Invalid JSON","code":"FPWSE0004E"}, NSErrorFailingURLKey=https://ChatBMS.mybluemix.net/imfpush/v1/apps/2b7d11a9-57bf-47e6-8a4c-8aabf044ac8a/subscriptions, WLAFNetworkingOperationFailingURLResponseErrorKey=<NSHTTPURLResponse: 0x7f89b8eb7f00> { URL: https://chatbms.mybluemix.net/imfpush/v1/apps/2b7d11a9-57bf-47e6-8a4c-8aabf044ac8a/subscriptions } { status code: 400, headers {
    Connection = "Keep-Alive";
    "Content-Type" = "application/json";
    Date = "Fri, 22 Jan 2016 16:48:09 GMT";
    "Transfer-Encoding" = Identity;
    "X-Backside-Transport" = "FAIL FAIL";
    "X-Cf-Requestid" = "cf162009-bd95-46d2-46ca-3cad50a70153";
    "X-Client-IP" = "80.111.218.187";
    "X-Global-Transaction-ID" = 2240839783;
    "X-Powered-By" = "Servlet/3.0";
} }, NSLocalizedDescription=Expected status code in (200-299), got 400} in subscribe to tags:["Test"]**

Solution

  • I can see in the error you are providing invalid JSON when attempting to subscribe. If you are trying to subscribe to all available tags, you first need to get the available tags and then use those tags when subscribing. For example:

    Swift:

    push.retrieveAvailableTagsWithCompletionHandler 
    {
     (response: IMFResponse!, error: NSError!) -> Void in
       let tags = response.availableTags()
       if (tags.count > 0)
     {
       //lets subcribe to all tags for demo purposes
        push.subscribeToTags(tags, completionHandler:
       { (response: IMFResponse!, error: NSError!) -> Void in
       })
     }
    }
    

    Here is documentation providing further insight:

    Tag-based Notifications