Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .env-example
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,9 @@ BRAND_NAME=Acme, Inc.
CODE=
NUMBER=
REQUEST_ID=
WORKFLOW_ID=4
WORKFLOW_ID=4

# Reports API
ACCOUNT_ID=
FILE_ID=
REQUEST_ID=
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ vendor
private.key
.env
.DS_Store
composer.phar
report.zip
composer-setup.php
23 changes: 23 additions & 0 deletions reports/create-async-report.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
require_once __DIR__ . '/../config.php';
require_once __DIR__ . '/../vendor/autoload.php';

$auth = base64_encode(NEXMO_API_KEY . ":" . NEXMO_API_SECRET);

$url = "https://api.nexmo.com/v2/reports";
$data = ["product" => "SMS",
"account_id" => ACCOUNT_ID,
"direction" => "outbound"
];
$body = json_encode($data);
$options = ["http" => [
"method" => "POST",
"header" => ["Authorization: Basic " . $auth,
"Content-Type: application/json"],
"ignore_errors" => true,
"content" => $body
]];
$context = stream_context_create($options);
// make the request
$response = file_get_contents($url, false, $context);
var_dump($response);
16 changes: 16 additions & 0 deletions reports/get-report-status.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
require_once __DIR__ . '/../config.php';
require_once __DIR__ . '/../vendor/autoload.php';

$auth = base64_encode(NEXMO_API_KEY . ":" . NEXMO_API_SECRET);

$url = 'https://api.nexmo.com/v2/reports/' . REQUEST_ID;
$options = ["http" => [
"method" => "GET",
"header" => ["Authorization: Basic " . $auth],
"ignore_errors" => true
]];
$context = stream_context_create($options);
// make the request
$response = file_get_contents($url, false, $context);
var_dump($response);
21 changes: 21 additions & 0 deletions reports/get-report.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
require_once __DIR__ . '/../config.php';
require_once __DIR__ . '/../vendor/autoload.php';

$auth = base64_encode(NEXMO_API_KEY . ":" . NEXMO_API_SECRET);

$url = 'https://api.nexmo.com/v3/media/' . FILE_ID;
$options = ["http" => [
"method" => "GET",
"header" => ["Authorization: Basic " . $auth],
"ignore_errors" => true
]];
$context = stream_context_create($options);
// stream to download
$stream = fopen($url, 'rb', false, $context);
// stream to local file
$fp = fopen("report.zip", 'wb');
// connect the hoses together
stream_copy_to_stream($stream, $fp);
fclose($stream);
fclose($fp);