Can I send a notification with custom content in code?

To clarify, I would like to send a custom admin notification without a specific form attached to it, populated with content generated from certain conditions in code. For example, a user submits a form, some code is run based on the content of the form entry which is ultimately used to make a REST API call. Then based on the result of that REST API call, let’s say receiving a list of resources available to that user, is it then possible to trigger a Gravityforms notification populated with that data?

I see that there is a GFCommon::send_notification function, but looking at the code I’m not sure how I would apply it to this situation. Any thoughts?

You can use the following filter to add your own custom Event for notifications: gform_notification_events

That will allow you create a notification in your form as usual, and select your custom event for the Event setting in the notification.

You can hook your code for the API call to gform_after_submission, which gives you access to $form and $entry, then once you’re ready to trigger the notification, you would include your custom event as part of the function call, example:

GFAPI::send_notifications( $form, $entry, 'your_custom_event' );

If you would like a less code intensive solution, I would recommend you look at Gravity Flow.

  • The outgoing webhook step includes response mapping into fields (including reading from within arrays or complex structures - such as translations\0\text). If the API is particular about structures it receives that the raw body format isn’t enough gravityflow_webhook_args lets you customize through code. On the response side there is also gravityflow_entry_webhook_response_mapping

  • Notification steps (and all steps) can define conditions on whether to execute or not - with similar UI as you are used to for defining conditional logic to show/hide fields on a form.

  • If following the notification you want them to approve a choice or provide more details the approval step or user input steps may be of use to cover a larger part of your business process than just the initial form submission.

Cheers,
Jamie