We are moving to Discord!

Join us on the Countly Community Discord Server! Engage in discussions, share your feature ideas, and learn from fellow Countly users to build exceptional apps and experiences.

Problem for setting Push Notification requests

Hi,

I'm trying to integrate Countly SDK on web app in order to communicate with our server we just configured for Push Notifications.
I have implemented some requests that are working well (as /o/apps/all, /o/users/me, /o/apps/details, etc ...).
But I'm unable to send requests for /i/pushes/prepare or /i/pushes/create for example.

I always get "Bad message type" as answer.
The problem is due to 'content' area.

That's why I'm trying to test the corresponding uri into a web browser but I don't succeed in using correct uri for that.

For example, for 'prepare' request, the code in C# is:
var request = new HttpRequestMessage
{
    Method = HttpMethod.Post,
    RequestUri = new Uri("https://myServerUrl/i/pushes/prepare?api_key=api_key"),
    Headers =
    {
        { "accept", "application/json" },
    },
    Content = new FormUrlEncodedContent(new Dictionary<string, string>
    {
        { "args", "{"apps":["12345678"],"platforms":["a"]}" },
    }),
};

I tryed several urls but noone is working. Among them for example :
https://myServerUrl/i/pushes/prepare?api_key=00a1b2c3d4e5f600&args:(apps=12345678&platforms=a)

Could anybody tell me how to set the 'content' part in the uri ?

Thank you in advance.
Best Regards,

0

Comments

5 comments
  • Official comment

    Hello,

    The easiest way would be to check which requests your browser makes when you create a message from dashboard. Other than that, you seem to use old deprecated APIs, here's a link to new API docs: https://countly.github.io/countly-server/apidoc/index.html#api-Push_Notifications-message/create 

    Comment actions Permalink
  • Hello Artem,
    Thank you for your quick answer !

    I finally succeeded in using my browser and also with using Postman.
    The right request would be for example:
    https://myServerUrl/i/pushes/create?api_key=00a1b2c3d4e5f600&args={"apps":["12345678"],"platforms":["a"],"type":"data","badge":123}

    Concerning API, up to now, I used : https://api.count.ly/reference/ipushesaudience.

    I just tried to use the new one you gave to me, but without success for the moment (for the same 'create' request).
    The 'platforms' parameter is invalid : I put ["a"] for Androïd (as with depreciated API) but it isn't accepted (as 'a', a, ...) so I don't know how to set this 'platforms' parameter for the moment.
    I have the same problem with 'triggers' and 'contents' parameters.

    I also saw the there is no more 'prepare' request in it ?

    Is there any example anywhere concerning the use of the new API ?

    Thank you in advance.
    Best Regards,

    0
    Comment actions Permalink
  • Hi Patrick,

    Sorry, I missed your reply. Yes, there's no prepare method anymore. Unfortunately there're no examples either, but like I said, just create a message from your browser and look at request in developer tools. Platforms didn't change, I guess you still use `args` parameter while we switched to application/json in request body.

    0
    Comment actions Permalink
  • Hello Artem,
    Thank you for your answer. No problem for the delay.

    I finally succeeded using new API for creating push requests. I'm currently testing the different possibilities offerred by the API.
    Push notifications are well sent when using "plain" kind for triggers, but they stay scheduled (and are unfortunately never sent) when using "api" kind for triggers.

    Is there anything else to set anywhere so that these kind of notifications are also sent ?


    Thank you in advance.
    Best Regards,

     
    0
    Comment actions Permalink
  • Hello Artem,

    I also finally managed to send push notifications when using "api" kind for triggers.
    In that case, we need not only to handle 'create' message, but also to handle 'push' message (API / add users).

    Nevertheless, the status of the message remains at 'Scheduled' state instead of changing to 'Sent' state. 



    I think it's just a display issue, isn't it ?

    Thank you in advance.
    Best Regards,
    Patrick

    0
    Comment actions Permalink

Please sign in to leave a comment.