Support

Home Forums Event Espresso Premium People Addon REST API

People Addon REST API

Posted: November 20, 2019 at 11:47 am

Viewing 7 reply threads


Daniel

November 20, 2019 at 11:47 am

I’ve been using the EE4 API and the ACF API and the WP API and now I’d like to use the People Addon REST API.

Does it exist?
Is there any example code?
I see that it is a post_type=espresso_people of wp_posts but I’d love to see some working code I can build on.

Thank you in advance for any help!


Josh

  • Support Staff

November 20, 2019 at 12:20 pm

Hi,

Data related to EE4 like the people post type can be accessed via the EE4 REST API. If you have the People add-on activated its discovery endpoints will be included in a request to the EE4 api.

One thing to keep in mind about getting people-related data with the REST API is since there’s personal information in those posts, it requires an authenticated REQUEST.

So for example if you want to request people post ID 1, you send an authenticated request to your site to:

/wp-json/ee/v4.8.36/person_posts/1/person

or to get people data specific to an event:

/wp-json/ee/v4.8.36/events/{the event ID}/people


Daniel

November 21, 2019 at 12:57 pm

Thank you!

I was able to access these GET endpoints and now I am writing some POST code.

I use JWT auth endpoint (/jwt-auth/v1/token) so my requests carry the Bearer token.

My test code in curl:


curl -H "Authorization: Bearer jwt_token_here" -H "Content-type: application/json" "https://example.com/wp-json/ee/v4.8.36/people/1"


Daniel

November 21, 2019 at 1:35 pm

I am trying to POST to add a person to an event. I tried this… and a few other things and it didn’t work.

Is there example code anywhere for using the People Addon EE REST API?

curl -X POST -H "Authorization: Bearer jwt_token_here" -H "Content-type: application/json" "https://example.com/wp-json/ee/v4.8.36/people/5640/events" -d '{"EVT_ID":"5139"}'

I can’t quite figure out what the data for the POST should look like.

Thank you!


Daniel

November 21, 2019 at 2:20 pm

I was able to write to the db with this:


curl -X POST -H "Authorization: Bearer tokenhere" -H "Content-type: application/json" "https://example.com/wp-json/ee/v4.8.36/people/5640/events/5139" -d '{"OBJ_ID":5139,"OBJ_type":"Event","PER_OBJ_order":0,"PT_ID":8}'

But the database row is malformed (has 0 where I sent value) and I see this in the REST response. What is the correct formation of the data that will avoid this? I have tried a lot of different combinations including using PUT and wrapping the JSON in an “args” field.


{
  "code": "error_occurred",
  "message": "There is no model named 'EVT_ID' related to EEM_Person_Post. Query param type is 0 and original query param is EVT_ID",
  "data": null
}


Josh

  • Support Staff

November 21, 2019 at 5:58 pm

There may be a bug in the models, it’s a bit of an unusual relationship between an event and a person because both are stored in the posts table. So no foreign key on a second table, which is the usual way to do a relationship with the models. I can check with Mike on this (he developed the models and the REST API for EE4).

This should work though:
In one POST request do:

wp-json/ee/v4.8.36/people/5640/events/5139
then get the ID of the new entity that was just created
then in a PUT or PATCH do:
wp-json/ee/v4.8.36/person_posts/{the ID of the entity} and include a param with key PT_ID value 8


Daniel

November 21, 2019 at 7:32 pm

Thanks for the info and confirmation that there may be a bug lurking in there.

I tried the first POST and got a 400 and a warning about security. Checked my jwt – it was good, I can hit other people endpoints with it.

So, I don’t think the workaround will work.

When do you think Mike will be able to have a look at this? I am eager to batch import a bunch of people and assign them to events!

As always, thanks for the support and if you have any ideas for workarounds or other ways of doing a bulk event-people connection I am open to trying.


Josh

  • Support Staff

November 22, 2019 at 7:24 am

You could use PHP to bulk assign people to events. There’s a method in the People add-on that you could either use directly or if need be use it as a starting point for your own PHP method. Here’s a link to its source:

https://github.com/eventespresso/eea-people-addon/blob/master/admin/people/espresso_events_People_Hooks.class.php#L230

Viewing 7 reply threads

The support post ‘People Addon REST API’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso