Posted: 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? Thank you in advance for any help! |
|
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:
or to get people data specific to an event:
|
|
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:
|
|
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?
I can’t quite figure out what the data for the POST should look like. Thank you! |
|
I was able to write to the db with this:
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.
|
|
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:
|
|
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. |
|
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: |
|
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.