0

I am using ci framework, and i try to create notification using onesignal API. I have hosted the website using https. But why my JSON received is always false using onesignal API, but if i test using postman it runs fine without error.

This is my code

function send_message($id, $nama) {
    $content      = array(
        "en" => $nama
    );
    $heading =array(
        "en" => $id
    );

    $fields = array(
        'app_id' => "2cd5ad24-a2d9-4e7d-ac66-7494cebd8e84",
        'included_segments' => array(
            'Active Users'
        ),
        'contents' => $content,
        'headings' => $heading,
        'url' => "https://esop.matahariled.com"
    );



    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "https://onesignal.com/api/v1/notifications");
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'Content-Type: application/json; charset=utf-8',
        'Authorization: Basic MDQ0NjY0ZmYtZjQ2Yi00ODVmLTkzZjgtZmVkZDBkODk0MDFl'
    ));
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ch, CURLOPT_HEADER, FALSE);
    curl_setopt($ch, CURLOPT_POST, TRUE);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
    curl_setopt($ch, CURLOPT_CAINFO, $_SERVER['DOCUMENT_ROOT']."/cacert.pem");
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);

    $response = curl_exec($ch);
    curl_close($ch);

    return $response;
}
Towsif
  • 337
  • 2
  • 12
  • 1
    Does this answer your question? [PHP - Debugging Curl](https://stackoverflow.com/questions/3757071/php-debugging-curl) – ArSeN Feb 08 '20 at 19:03
  • Actually, when i try using postman it work. In tutorials what i see, i dont see the additional of curl class or curl library. but almost all the tutorials that I have seen, mostly use http://localhost. I have not seen the website that has been hosted. I have seen documentation of https setup, and i follow that. But still dont work – Muhamad Ramadhan Feb 08 '20 at 19:51
  • 1
    Did you try and follow the debug suggestions in the linked post? What output does it show? – ArSeN Feb 08 '20 at 20:00
  • array (size=26) 'url' => string 'https://onesignal.com/api/v1/notifications' (length=42) 'content_type' => null 'http_code' => int 0 'header_size' => int 0 'request_size' => int 0 'filetime' => int -1 'ssl_verify_result' => int 0 'redirect_count' => int 0 'total_time' => float 0.000576 'namelookup_time' => float 0.007065 'connect_time' => float 0 'pretransfer_time' => float 0 'size_upload' => float 0 'size_download' => float 0 – Muhamad Ramadhan Feb 09 '20 at 08:35
  • 1
    Can you add the debug info to the question? It is not very well readable as a comment and I think there is probably a part missing. Also, please explain what exactl you did so other people understand where your debug info comes from. Thanks. – ArSeN Feb 09 '20 at 14:45

0 Answers0