ISSUE | return only WebinarJam Object
Opened this issue · 5 comments
Hi,
I always have as return :
WebinarJam Object
(
[apiKey:protected] => 904b5bee-2389
)
My test files below.
TEST.PHP:
`<?php
echo ('Begin
');
require_once dirname(DIR) . DIRECTORY_SEPARATOR . 'biopharm' . DIRECTORY_SEPARATOR . 'class' . DIRECTORY_SEPARATOR . 'WebinarJam.php';
$detail = new WebinarJam('XXX_my_key_XXX');
$detail->getWebinars();
echo '
';';
print_r($detail);
echo '
echo ('END
');
`
WebinaJam CLASS:
`<?php
class WebinarJam
{
protected const API_URL = 'https://api.webinarjam.com/everwebinar';
protected const CURL_OPTIONS = [
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 60,
];
/**
* WebinarJam API Key
* @var string
*/
protected $apiKey;
/**
* WebinarJam Class Constructor
*
* @param string $apiKey WebinarJam API Key
*/
public function __construct(string $apiKey)
{
$this->apiKey = $apiKey;
}
/**
* Call to API URL through curl extension
*
* @param string $endpoint WebinarJam API EndPoint
* @return array $jsonResults
*/
protected function authenticatedCall(string $endpoint, array $params = []): array
{
$curl = curl_init(self::API_URL . $endpoint);
if (empty($this->apiKey)) {
throw new \Exception('You must specify a valid WebinarJam API Key');
}
if (is_resource($curl)) {
$params['api_key'] = $this->apiKey;
curl_setopt_array($curl, self::CURL_OPTIONS);
curl_setopt($curl, CURLOPT_POSTFIELDS, $params);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
$result = curl_exec($curl);
if (false === $result) {
$error = curl_error($curl);
curl_close($curl);
throw new \Exception($error);
}
curl_close($curl);
$jsonResults = is_string($result) ? json_decode($result, true) : null;
if (!is_array($jsonResults)) {
throw new \Exception($result);
}
return $jsonResults;
}
return [];
}
/**
* Retrieve a full list of all webinars published in your account
* @return array Webinar List
*/
public function getWebinars(): ?array
{
return $this->authenticatedCall('webinars');
}
/**
* Get details about one particular webinar from your account
*
* @param string $webinarId Webinar ID
* @return array $webinar Webinar Details
*/
public function getWebinar(string $webinarId): ?array
{
return $this->authenticatedCall('webinar', ['webinar_id' => $webinarId]);
}
/**
* Register a person to a specific webinar
*
* @param string $webinarId Webinar ID (required)
* @param string $first_name First Name (required)
* @param string $email E-mail (required)
* @param int $schedule Schedule (required)
* @param string|null $last_name Last Name (optional)
* @param string|null $ipAddress IP Address (optional)
* @param int|null $countryCode Country Code (optional)
* @param int|null $phone Phone (optional)
* @return array $webinar Webinar Details
*/
public function addToWebinar(
string $webinarId,
string $first_name,
string $email,
int $schedule = 0,
string $last_name = null,
string $ipAddress = null,
int $countryCode = null,
int $phone = null
): array {
$params = [
'webinar_id' => $webinarId,
'first_name' => $first_name,
'email' => $email,
'schedule' => $schedule
];
$params['last_name'] = $last_name ?? null;
$params['ip_address'] = $ipAddress ?? null;
$params['phone_country_code'] = $countryCode ?? null;
$params['phone'] = $phone ?? null;
return $this->authenticatedCall('register', $params);
}
}
`
When i use false API_KEY i have 404 error, with the good key it return WebinarJam Object, have SSL issue ? (my website is HTTPS hosted by SITEGROUND)
Hello!
You are trying the wrong way to debug your code, because, you are printing the variable instance of your class. Let me show you through an examples, try with this:
$webinarJam = new WebinarJam('YOUR_KEY'); $webinars = $webinarJam->getWebinars(); print_r($webinars);
OR wit your own example:
$detail = new WebinarJam('XXX_my_key_XXX'); print_r($detail->getWebinars());
Please, let me know if this works.
Best regards.
Hello!
You are trying the wrong way to debug your code, because, you are printing the variable instance of your class. Let me show you through an examples, try with this:
$webinarJam = new WebinarJam('YOUR_KEY'); $webinars = $webinarJam->getWebinars(); print_r($webinars);
OR wit your own example:
$detail = new WebinarJam('XXX_my_key_XXX'); print_r($detail->getWebinars());
Please, let me know if this works.
Best regards.
with this code :
$detail = new WebinarJam('XXX_my_key_XXX'); print_r($detail->getWebinars());
I have this return:
Array ( [status] => error [errors] => Array ( [api_key] => You don't have permission to access this resource ) )
with this code :
$detail = new WebinarJam('XXX_my_key_XXX'); print_r($detail->getWebinars());
I have this return:
Array ( [status] => error [errors] => Array ( [api_key] => You don't have permission to access this resource ) )
Did you check your API Key?
Please, verify this https://documentation.webinarjam.com/category/webinarjam-api/
Let me know!
I found the issue for the methods getWebinar and getWebinars, its come from wrong api url, the good one is :
https://api.webinarjam.com/webinarjam/
But the register method dont work, in the API documentation the API adress is:
https://api.webinarjam.com/webinarjam/register
But when i try its always return:
Fatal error: Uncaught Exception: <!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <meta http-equiv="refresh" content="0;url=https://home.webinarjam.com/404" /> <title>Redirecting to https://home.webinarjam.com/404</title> </head> <body> Redirecting to <a href="https://home.webinarjam.com/404">https://home.webinarjam.com/404</a>. </body> </html> in /opt/lampp/htdocs/webinar/class/WebinarJamOneClick.php:70 Stack trace: #0 /opt/lampp/htdocs/webinar/class/WebinarJamOneClick.php(113): WebinarJamOneClick->authenticatedCall('register', Array) #1 /opt/lampp/htdocs/webinar/register.php(21): WebinarJamOneClick->addToWebinar('4', 'Slimus', 'slim@gmail.com', 26) #2 {main} thrown in /opt/lampp/htdocs/webinar/class/WebinarJamOneClick.php on line 70