Eventbrite duplicate event entry

192 views Asked by At

I am trying to code a page to insert an event into eventbrite via PHP Curl

After a bit of trial and error, I have got it working, but instead of inserting one event, 2 are inserted.

Quite new to this, so grateful for any advice/tips...

$token = '######';
$organizerid = '#####';
$timezone = 'Europe/London';
$currency = 'GBP';

$tokenURL = 'https://www.eventbriteapi.com/v3/events/?token='.$token.'&';
$postData = array(
    'event.name.html'=>'Curl New Event',
    'event.description.html'=>'Test event Eventbrite',
    'event.organizer_id'=> $organizerid,
    'event.start.utc'=>'2014-11-26T18:00:00Z',
    'event.start.timezone'=> $timezone,
    'event.end.utc'=>'2014-11-26T19:04:00Z',
    'event.end.timezone'=> $timezone,
    'event.currency'=> $currency,
    'event.venue_id'=>'*****',
    'event.online_event'=>'',
    'event.listed'=>'',
    'event.logo.id'=>'*****',
    'event.category_id'=>'',
    'event.subcategory_id'=>'',
    'event.format_id'=>'',
    'event.shareable'=>'on',
    'event.invite_only'=>'',
    'event.password'=>'',
    'event.capacity'=>'25',
    'event.show_remaining'=>'on'
);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $tokenURL);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);//need this otherwise you get an ssl error
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postData));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);

// Check for errors and display the error message
if(curl_exec($ch) === false)
{
  echo 'Curl error: ' . curl_error($ch);
}
  else
{
  echo $result;
}

curl_close($ch);
1

There are 1 answers

0
Aleksei Matiushkin On BEST ANSWER

You execute your request twice:

$result = curl_exec($ch); // 1st

// Check for errors and display the error message
if(curl_exec($ch) === false) // 2nd

Change the latter to:

if($result === false)

Hope it helps.