jamiehollern / eventbrite

A lightweight PHP library for interacting with version 3 of the Eventbrite API.
GNU General Public License v2.0
19 stars 6 forks source link

POST - Can't update event. #8

Open joshbruce opened 7 years ago

joshbruce commented 7 years ago

Hate to be a bother...sorry the other ticket had some of my extensions in there...still think I'm missing something.

$eb = new Eventbrite('OAUTH');
$event = $eb->get('events/:id');

Return (note capacity):

{  
   "code":200,
   "headers":{  
      "Server":[  
         "nginx"
      ],
      "Date":[  
         "Sun, 16 Apr 2017 20:28:46 GMT"
      ],
      "Content-Type":[  
         "application\/json"
      ],
      "Transfer-Encoding":[  
         "chunked"
      ],
      "Connection":[  
         "keep-alive"
      ],
      "x-xss-protection":[  
         "1; mode=block"
      ],
      "x-content-type-options":[  
         "nosniff"
      ],
      "Vary":[  
         "Accept, Accept-Encoding"
      ],
      "X-Rate-Limit":[  
      ],
      "Allow":[  
         "GET, POST, DELETE, HEAD, OPTIONS"
      ],
      "X-Frame-Options":[  
         "SAMEORIGIN"
      ],
      "Access-Control-Allow-Origin":[  
         "*"
      ],
      "Access-Control-Allow-Headers":[  
         "Authorization, Content-Type"
      ],
      "P3P":[  
         "CP=\"NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM\""
      ],
      "X-UA-Compatible":[  
         "IE=edge"
      ],
      "Set-Cookie":[  
      ]
   },
   "body":{  
      "name":{  
         "text":"TESTINGAPIINTEGRATIONWITHOURSITE",
         "html":"TESTINGAPIINTEGRATIONWITHOURSITE"
      },
      "description":{  
         "text":"This is the description. Looks like it can take images. Links...And horizontal rules.",
         "html":"<P>This is the description. Looks like it can take images. Links...<\/P><HR><P><BR><\/P><P>And horizontal rules.<\/P>"
      },
      "id":":id",
      "url":"https:\/\/www.eventbrite.com\/e\/testingapiintegrationwithoursite-tickets-:id",
      "start":{  
         "timezone":"America\/New_York",
         "local":"2017-09-01T19:00:00",
         "utc":"2017-09-01T23:00:00Z"
      },
      "end":{  
         "timezone":"America\/New_York",
         "local":"2017-09-30T22:00:00",
         "utc":"2017-10-01T02:00:00Z"
      },
      "created":"2017-04-15T19:36:08Z",
      "changed":"2017-04-16T17:55:41Z",
      "capacity":40,
      "capacity_is_custom":true,
      "status":"draft",
      "currency":"USD",
      "listed":false,
      "shareable":true,
      "invite_only":false,
      "password":"Testing the API and Integration with our site.",
      "online_event":false,
      "show_remaining":true,
      "tx_time_limit":480,
      "hide_start_date":false,
      "hide_end_date":false,
      "locale":"en_US",
      "is_locked":false,
      "privacy_setting":"unlocked",
      "is_series":false,
      "is_series_parent":false,
      "is_reserved_seating":false,
      "source":"create_2.0",
      "is_free":false,
      "version":"3.0.0",
      "logo_id":null,
      "organizer_id":":id",
      "venue_id":":id",
      "category_id":null,
      "subcategory_id":null,
      "format_id":null,
      "resource_uri":"https:\/\/www.eventbriteapi.com\/v3\/events\/:id\/",
      "logo":null
   }
}
// Would expect capacity to update     
$update = $eb->post('events/:id', ['event.capacity' => 30]);

Return is the same as above. Verify by recalling.

$event2 = $eb->get('events/:id');

Return is the same as above.

Again, Postman works just fine - as long as I have it set to form-data.

Thoughts? What am I missing?

Also tried

$update = $eb->post('events/:id', [
    'event' => [
        'capacity' => 30
    ]
]);

$update = $eb->post('events/:id', [
    'body' => [
        'event' => [
            'capacity' => 30
        ]
    ]
]);

$update = $eb->patch(
    'events/:id',
    ['event.capacity' => 30]
);

$update = $eb->put(
    'events/:id',
    ['event.capacity' => 30]
);

// Error because body is array
$update = $eb->call('POST', 'events/:id', [
    'body' => [
        'event' => [
            'capacity' => 30
        ]
    ]
]);

$update = $eb->call('POST', 'events/:id', [
    'event' => [
        'capacity' => 30
    ]
]);

$update = $eb->call('POST', 'events/:id', ['event.capacity' => 30]);

$update = $eb->makeRequest('POST', 'events/:id', ['event.capacity' => 30]);

// Error because body is array
$update = $eb->makeRequest(
    'POST',
    'events/:id',
    null,
    ['event.capacity' => 30]
);

$update = $eb->makeRequest(
    'POST',
    'events/:id',
    null,
    null,
    ['event.capacity' => 30]
);

$update = $eb->makeRequest(
    'POST',
    'events/:id',
    null,
    null,
    null,
    ['event.capacity' => 30]
);

See also #7

joshbruce commented 7 years ago

This works - instead of using send()

// Eventbrite.php
$response = $this->client->post('https://www.eventbriteapi.com/v3/events/:id/?token=:token', [
    'headers' => ['Content-Type' => 'application/json'],
    'body' => json_encode([
        'event.capacity' => 20
    ])
]);
CaioBianchi commented 7 years ago

Also not able to send POST requests via the SDK.

CaioBianchi commented 7 years ago

The tests currently do not cover basic parameter input https://github.com/jamiehollern/eventbrite/blob/master/tests/src/EventbriteTest.php#L140

joshbruce commented 7 years ago

@CaioBianchi: I don't know if this is bad form or not; so, I do apologize if this is breaking GitHub social norms. Created: https://github.com/8fold/eventbrite-sdk-php

Not as thoroughly tested through PHPUnit and I'm not sure if it covers all the use cases yet. The main project I'm using it in has deviated slightly on priorities, and Eventbrite integration is not it.

CaioBianchi commented 7 years ago

Looks good @joshbruce but I see that there's still a lot to be implemented still on the Events SDK. I might be able to help, if you're open to contributions/pull requests.

joshbruce commented 7 years ago

@CaioBianchi: If the assessment is based on the documentation, it is out of date as well (believe most of the get functionality is there - using magic methods)...sorry about that. Always open for contributions and collaborations!

CaioBianchi commented 7 years ago

Just an update on the issue here:

I was trying to POST to the access_code endpoint: https://www.eventbrite.ca/developer/v3/endpoints/events/#ebapi-post-events-id-access-codes

Which logically would be something like this:

return $this->client->post(sprintf('events/%s/access_codes/', $event_id), $options);

But that was throwing me an error. Once I removed the trailing slash (non-compliant to the documentation) it started working:

return $this->client->post(sprintf('events/%s/access_codes', $event_id), $options);
joshbruce commented 7 years ago

@CaioBianchi: Don't want to hijack this project. Can we move this to a new issue on the 8fold SDK project?

jamiehollern commented 7 years ago

I'm trying to debug this but I think there could be a few issues going on here:

I appreciate you have the other project up and running but if anyone manages to figure this out before I do, please let me know.

joshbruce commented 7 years ago

@jamiehollern: https://github.com/8fold/eventbrite-sdk-php/blob/develop/src/Classes/Core/ApiClient.php

If you take a look at the __construct - there's a Guzzle header added on line 94:

$this->config['headers']['Content-Type'] = 'application/json';

I think this alone helped me before I effectively modified the base class here. As to the nesting of JSON, I don't think I had to do anything there json_encode worked without issue.

Update: I think that single change was enough to make the library more consistent in returning data.

CaioBianchi commented 7 years ago

@jamiehollern @joshbruce As mentioned before, it worked for me once I removed the trailing slash, for some reason. Without having to json_encode my params.