Skip to content
Advertisement

Send Onesignal notification using php api : The parameter “send_after” of onesignal’s notification is not taken into consideration

Im working on a project using php/symfony 4, and after the creation of an object, I send a push notification, normaly without specifying the delivery parameter “send_after”, it is working perfectly, and mobile devices receive the notification in the real time. but whe I specify the date of delivery, they dont take it into consideration, and it is sent right at the moment of creation of my object, here is my snippet of code :

$fields = array(
        'app_id' => $this->api_key,
        'include_player_ids' => $devices,
        'data' => array(
            "type" => $type,
            "url" => $url
        ),
        'contents' => $content
    );

    if (null != $dateTime) {
        date_time_set($dateTime, 9, 0, 0);

        array_push($fields, [
            'send_after' => $dateTime->format('Y-m-d H:i:s TO')] );
    }

    $fields = json_encode($fields);

so I try to respect this format mentioned in the doc : “2015-09-24 14:00:00 GMT-0700”

plz if someone has already encountered this issue, how could I resolve it?

Thanks in advance.

Advertisement

Answer

This should work:

    $fields = array(
        'app_id' => $this->api_key,
        'include_player_ids' => $devices,
        'data' => array(
            "type" => $type,
            "url" => $url
        ),
        'contents' => $content
    );

  /* $dateTime=date_create("2020-08-12"); */

    if (null != $dateTime) {
        date_time_set($dateTime, 9, 0, 0);

       /* $send_after = date_format($dateTime,'Y-m-d H:i:s TO'); */

       $fields['send_after'] = $dateTime->format('Y-m-d H:i:s TO')] ); /* $send_after */
    }

    $fields = json_encode($fields);
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement