November 1

Developer guide: REST API, hooks and events

0  comments

The extension API is simply the set of hooks below. There is no separate registration function.

REST API

All routes are under /wp-json/wphd/v1/. The main ones:

RouteUse
tickets, tickets/{id}List, create, read and update tickets
tickets/{id}/replies, tickets/{id}/notesReplies and internal notes
tickets/{id}/merge, tickets/{id}/watchMerge and watch
tickets/{id}/presenceWho is viewing or typing
tickets/{id}/fields, tags, teams, views, timeRoutes added by modules: custom fields, tags, teams, saved views, time entries
tickets/{id}/teamMove a ticket to a team
departments, priorities, statusesLists
agents, assignees, customers/searchPeople
canned-responsesCanned responses
kb/searchKnowledge base search
message-threadsAgent messaging
ai/*AI Assistant (agents only)
tickets/{id}/credentialsPrivate credentials (module)

Authentication

HelpDesk WP adds no login system of its own. Every route checks the permissions of the logged-in WordPress user. The plugin's own pages use cookie login with the X-WP-Nonce header (the wp_rest nonce). Because these are ordinary WordPress REST routes, WordPress Application Passwords also work (HTTP Basic, normally over HTTPS) with the same permissions as that user. The private-credentials write routes need the cookie nonce, so Application Passwords do not work for them.

Some routes are public: GET departments, GET priorities, GET kb/search and POST kb/articles/{id}/feedback. POST tickets is public when guest tickets are on. Time entries are only available to agents and are never part of the ticket data customers receive.

To bring in data from elsewhere, you can create tickets through the API. Each one runs the normal flow: auto-assignment, status Open, today's date and confirmation emails. You cannot set historical dates.

PHP actions

HookFires
wphd_ticket_createdWhen a ticket is created, with ($ticket_id, $data, $author_id).
wphd_new_ticketAfter the new ticket is set up, with ($ticket_id).
wphd_ticket_updatedAfter an agent changes status, priority, department, assignment or tags. It does not fire for replies. Arguments: ($ticket_id, $changes, $user_id).
wphd_new_replyAfter a reply, with ($ticket_id, $comment_id, $user_id).
wphd_new_noteAfter an internal note, with ($ticket_id, $comment_id, $user_id).
wphd_tickets_mergedAfter a merge, with ($primary_id, $secondary_id, $user_id).

Also available: wphd_privacy_erase_ticket, wphd_privacy_erase_comment, wphd_admin_menu_items, wphd_enqueue_public_assets, and template actions such as wphd_ticket_form_top, wphd_ticket_form_before_submit, wphd_single_ticket_after_header, wphd_single_ticket_before_replies, wphd_reply_form_actions, wphd_agent_dashboard_before_search and wphd_my_tickets_before_search.

PHP filters

FilterUse
wphd_can_submit_ticketAllow or block a submission
wphd_ticket_submission_allowedThe spam or CAPTCHA check, after the honeypot and rate limit
wphd_ticket_data_validExtra validation
wphd_rest_create_ticket_dataChange the data before a ticket is created
wphd_format_ticketChange ticket data returned
wphd_list_tickets_argsChange ticket list queries
wphd_allowed_attachment_extensionsThe attachment file type allow-list
wphd_max_attachment_sizeThe upload size limit, in bytes
wphd_grantable_capabilitiesAdd a permission tick box to the Agents screen
wphd_notification_recipientsChange who gets an email
wphd_submitter_ipThe IP address used for the rate limit
wphd_ticket_rate_limit, wphd_ticket_rate_limit_windowChange the rate limit
wphd_closed_status_slugs, wphd_dashboard_open_viewsWhich statuses count as closed, and the dashboard views
wphd_ticket_form_render, wphd_ticket_form_settings, wphd_ticket_form_show_fieldChange the ticket form
wphd_kb_page_id, wphd_kb_base, wphd_kb_articles_per_page, wphd_kb_default_category_name, wphd_kb_seo_plugin_activeKnowledge base settings
wphd_business_hours_configBusiness hours setup
wphd_is_licensedThe licence state

Business hours also has PHP helper functions: wphd_business_hours_enabled(), wphd_is_open_now( $department_id ), wphd_business_add_seconds() and wphd_business_seconds_between().

JavaScript events

The events are jQuery events on document, not native DOM events:

  • wphd_ticket_loaded fires when a ticket loads in the portal: $(document).on('wphd_ticket_loaded', function (e, ticket, $wrap) { … });
  • Others include wphd_reload_ticket, wphd_reload_list, wphd_list_params and wphd_ticket_row.

Webhook payloads are described in "Sending ticket events with Webhooks".

Still stuck? Open a ticket on the support page on ABC and a real person will help.

Was this article helpful?

  • developers
  • filters
  • HelpDesk WP
  • hooks
  • JavaScript
  • REST API

← Helpdesk WP


Tags


You may also like

Hello world!

Hello world!
{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

Get in touch

Name*
Email*
Message
0 of 350