> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mangopay.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Create a Hook

> Set up a URL to receive notifications of an event type

<Warning>
  **Caution – Setting email for consecutive failures after April 2026**

  In Production, if your platform had `VALID` Hook objects before April 2, 2026, then Mangopay automatically populates the `Email` property on new Hooks with the previously used global address **unless and until** you set it proactively using this endpoint.

  If you send the `Email` on a POST or PUT request, other new Hooks created without the `Email` do not populate the `Email` automatically and do not emit alerts in case of consecutive failed notifications or if the Hook becomes `INVALID`.

  Platforms integrating after April 2, 2026 **must** proactively set the `Email` to receive alerts.

  [Read more about this change](/webhooks#transition-from-default-email-april-2026) **→**
</Warning>

### Body parameters

<ParamField body="EventType" type="string" required>
  **Allowed values:** An `EventType` listed in the <a href="/webhooks/event-types">event types list</a>

  The type of the event.
</ParamField>

<ParamField body="Url" type="string" required>
  Max. length: 255 characters

  The URL to which the notification is sent.
</ParamField>

<ParamField body="Tag" type="string">
  Max. length: 255 characters

  Custom data that you can add to this object.
</ParamField>

<ParamField body="Email" type="string | null">
  Format: A valid email address

  The `Email` address to which alerts are sent in case of [consecutive failed notification attempts](/webhooks#notification-retries-and-failure).

  **Caution:** Mangopay may populate this property automatically if your platform had webhooks integrated in Production before April 2, 2026. If so, setting the `Email` on a single Hook stops this automatic population for any new Hooks you create - [read more](/webhooks#transition-from-default-email-april-2026).

  For all platforms, if this property is returned `null` then no alerts are sent but the Hook still becomes `INVALID` after 100 consecutive failed notifications.
</ParamField>

### Responses

<Accordion title="200">
  <ResponseField name="Url" type="string">
    Max. length: 255 characters

    The URL to which the notification is sent.
  </ResponseField>

  <ResponseField name="Status" type="string">
    **Returned values:** `DISABLED`, `ENABLED`

    Whether the hook is enabled or not.
  </ResponseField>

  <ResponseField name="Validity" type="string">
    **Returned values:** `VALID`, `INVALID`

    Whether the hook is valid or not. Once `INVALID` (following unsuccessful retries) the hook must be disabled and re-enabled.
  </ResponseField>

  <ResponseField name="EventType" type="string">
    **Returned values:** An `EventType` listed in the <a href="/webhooks/event-types">event types list</a>

    The type of the event.
  </ResponseField>

  <ResponseField name="Id" type="string">
    Max length: 128 characters (see [data formats](/api-reference/overview/data-formats) for details)

    The unique identifier of the object.
  </ResponseField>

  <ResponseField name="Tag" type="string">
    Max. length: 255 characters

    Custom data that you can add to this object.
  </ResponseField>

  <Email11Response />

  <ResponseField name="CreationDate" type="Unix timestamp">
    The date and time at which the object was created.
  </ResponseField>
</Accordion>

<Accordion title="400 - Hook already exists for this EventType">
  ```json theme={null}
  {
      "Message": "One or several required parameters are missing or incorrect. An incorrect resource ID also raises this kind of error.",
      "Type": "param_error",
      "Id": "829f2782-85a9-45b1-a2bd-993b0978c5bc",
      "Date": 1690295313.0,
      "errors": {
          "EventType": "A hook has already been registered for this EventType"
      }
  }  
  ```
</Accordion>

<ResponseExample>
  ```json 200   theme={null}
  {
      "Url": "https://example.com",
      "Status": "ENABLED",
      "Validity": "VALID",
      "EventType": "PAYIN_REFUND_SUCCEEDED",
      "Id": "hook_m_01J8F5RK4R43AYWD8XVG9RSYDT",
      "Tag": "Created using the Mangopay API Postman Collection",
      "CreationDate": 1727086218
  }
  ```
</ResponseExample>

<RequestExample>
  ```json REST   theme={null}
  {
      "Url": "https://example.com",
      "EventType" : "PAYIN_REFUND_SUCCEEDED",
      "Tag": "Created using the Mangopay API Postman Collection"
  }  
  ```

  ```php PHP theme={null}
  <?php 

  require_once 'vendor/autoload.php';

  use MangoPay\MangoPayApi;
  use MangoPay\Libraries\ResponseException as MGPResponseException;
  use MangoPay\Libraries\Exception as MGPException;

  $api = new MangoPayApi();

  $api->Config->ClientId = 'your-client-id';
  $api->Config->ClientPassword = 'your-api-key';
  $api->Config->TemporaryFolder = 'tmp/';

  try {
      $hook = new \MangoPay\Hook();

      $hook->EventType = \MangoPay\EventType::MandateFailed;
      $hook->Url = 'http://example.com';
      $hook->Tag = 'Created using Mangopay PHP SDK';

      $response = $api->Hooks->Create($hook);

      print_r($response);
  } catch(MGPResponseException $e) {
      print_r($e);
  } catch(MGPException $e) {
      print_r($e);
  }  
  ```

  ```javascript NodeJS   theme={null}
  const mangopayInstance = require('mangopay4-nodejs-sdk')
  const mangopay = new mangopayInstance({
    clientId: 'your-client-id',
    clientApiKey: 'your-api-key',
  })

  let myHook = {
    EventType: 'TRANSFER_SETTLEMENT_CREATED',
    Url: 'http://example.com',
    Tag: 'Created using Mangopay NodeJS SDK',
  }

  const createHook = async (hook) => {
    return await mangopay.Hooks.create(hook)
      .then((response) => {
        console.info(response)
        return response
      })
      .catch((err) => {
        console.log(err)
        return false
      })
  }

  createHook(myHook)  
  ```

  ```ruby Ruby   theme={null}
  require 'mangopay'

  MangoPay.configure do |client|
      client.preproduction = true
      client.client_id = 'your-client-id'
      client.client_apiKey = 'your-api-key'
      client.log_file = File.join(Dir.pwd, 'mangopay.log')
  end

  def createHook(hookObject)
      begin
          response = MangoPay::Hook.create(hookObject)
          puts response
          return response
      rescue MangoPay::ResponseError => error
          puts "Failed to create Hook: #{error.message}"
          puts "Error details: #{error.details}"
          return false
      end
  end

  myHook = {
      EventType: 'PAYOUT_NORMAL_SUCCEEDED',
      Url: 'http://example.com',
      Tag: 'Created using Mangopay Ruby SDK'
  }

  createHook(myHook)  
  ```

  ```java Java  theme={null}
  import com.google.gson.Gson;
  import com.google.gson.GsonBuilder;
  import com.mangopay.MangoPayApi;
  import com.mangopay.core.enumerations.EventType;
  import com.mangopay.entities.Hook;

  public class CreateHook {
      public static void main(String[] args) throws Exception {
          MangoPayApi mangopay = new MangoPayApi();
          mangopay.getConfig().setClientId("your-client-id");
          mangopay.getConfig().setClientPassword("your-api-key");

          Hook hook = new Hook();
          hook.setEventType(EventType.USER_KYC_LIGHT);
          hook.setUrl("http://example.com");
          hook.setTag("Create using the Mangopay Java SDK");

          Hook createHook = mangopay.getHookApi().create(hook);

          Gson prettyPrint = new GsonBuilder().setPrettyPrinting().create();
          String prettyJson = prettyPrint.toJson(createHook);

          System.out.println(prettyJson);   
      }
  }
  ```

  ```python Python   theme={null}
  from pprint import pprint
  import mangopay

  mangopay.client_id='your-client-id'
  mangopay.apikey='your-api-key'

  from mangopay.api import APIRequest
  handler = APIRequest(sandbox=True)

  from mangopay.resources import Notification

  hook = Notification(
      event_type = 'USER_KYC_REGULAR',
      url = 'http://example.com',
      tag = 'Create using the Mangopay Python SDK'
  )

  create_hook = hook.save()

  pprint(create_hook)  
  ```

  ```csharp .NET  theme={null}
  using MangoPay.SDK;
  using MangoPay.SDK.Core.Enumerations;
  using MangoPay.SDK.Entities.POST;
  using Newtonsoft.Json;

  class Program
  {
      static async Task Main(string[] args)
      {
          MangoPayApi api = new MangoPayApi();

          api.Config.ClientId = "your-client-id";
          api.Config.ClientPassword = "your-api-key";

          var eventType = EventType.DISPUTE_CREATED;
          var url = "https://www.example.com/";
          

          var hook = new HookPostDTO(url, eventType) {
              Tag = "Created using the Mangopay .NET SDK"
          };

          var createHook = await api.Hooks.CreateAsync(hook);

          string prettyPrint = JsonConvert.SerializeObject(createHook, Formatting.Indented);
          Console.WriteLine(prettyPrint);
      }
  }
  ```
</RequestExample>
