We have a process where we use the API to create events, tickets and assign People as owners to the event. I have the API working fine to create the event and tickets, but I am struggling with assigning People to the group. I need to first search if a People object exists based on email. If it does, then I assign that People. If it doesn’t then I create a new People object and assign that.
the Person custom post type requires authentication to access, so if you ONLY enter a query like the above, you should see something like:
{
"code": "rest_people_cannot_list",
"message": "Sorry, you are not allowed to list people. Missing permissions: ee_read_peoples,ee_read_others_peoples,ee_read_private_peoples",
"data": {
"status": 403
}
}
so there are two very important aspects of this that are required to make things work:
1. the user wishing to pull Person data via the REST API needs to have one or more of the following capabilities:
– ee_read_peoples
– ee_read_others_peoples
– ee_read_private_peoples
Thank you so much for replying! We are using a submitted form to create events and I would prefer doing all of the API calls internally so I don’t have to deal with authentication.
I have WP_REST_Request working great with POST calls, but I cannot get it to work with the GET. If I do this call, it returns all People objects, not the one that matches the specific email:
$request = new WP_REST_Request(‘GET’, ‘/ee/v4.8.36/people’);
$request->set_query_params([‘where[PER_email]’=>’some_email@gmail.com’]);
$response = rest_do_request($request);
We are using a submitted form to create events and I would prefer doing all of the API calls internally so I don’t have to deal with authentication.
Oh… uhh… if the form is submitted to the same server that Event Espresso is installed on, then using the REST API to obtain the data is extremely inefficient since you are essentially sending a second request to get it.
But to answer your question, the request needs to be formatted like this:
Now that said, you should seriously consider looking into using Event Espresso’s model system for retrieving the data you need because it will be easier and more efficient than making additional REST requests.
To get a single Person object based on their email address, you simply need to do something like:
Plus our model system will automagically resolve relations for you, so let’s say you then wanted to get a list of events associated with that person, you could simply do something like:
$event = $person->get_many_related('Event');
echo $event->name();
echo $event->description();
echo $event->phone();
// gets an array of EE_Ticket objects
$tickets = $event->tickets();
Thank you both!!! Josh, that is exactly what I needed to make that statement work. However Brent, I didn’t even think of using the model system. I will switch over to that right away.
Thank you again!
Viewing 8 reply threads
The support post ‘Using API – Pulling People records by email’ 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.
Support forum for Event Espresso 3 and Event Espresso 4.