Answers.Body: <p>OK, so through some trial and error, figured out the following syntax for the filters value to limit the discount to specific event types:</p>
  <pre><code>-&gt;addValue('filters', [
      'event' =&gt; ['event_type_id' =&gt; ['IN' =&gt; ['1', '2', '11']]],
    ])
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-11-03T22:13:24.550Z
Answers.LastActivityDate: 2024-11-03T22:13:24.550Z
Answers.UserDisplayName: MtnPavlas
Body: <p>What is the proper syntax for the 'filters' value in API4? Trying to create a discount item that is applicable to certain membership types and event types.
  E.g., here's what I've got, but it doesn't work, and the filters is the culprit (i.e., if I omit the filters line, it creates the discount item just fine, but without the event types, obviously... which I need for this use case):</p>
  <pre><code>$results = \Civi\Api4\DiscountCode::create(TRUE)
    -&gt;addValue('code', $gcCode)
    -&gt;addValue('description', 'gift certificate')
    -&gt;addValue('amount', $gcAmount)
    -&gt;addValue('amount_type', 2)
    -&gt;addValue('count_max', 1)
    -&gt;addValue('active_on', date(&quot;Y-m-d&quot;))
    -&gt;addValue('is_active', TRUE)
    -&gt;addValue('memberships', [
      1,
      3,
      7,
    ])
    -&gt;addValue('filters.event.event_type_id', [
      1,
      2,
      11,
    ])
    -&gt;execute();
  </code></pre>
  <p>Thank you for any pointers.</p>
  
Tags: <api4>
Title: Syntax for 'Filters' value when creating a discount item with API4
ThreadText: # Syntax for 'Filters' value when creating a discount item with API4
  
  (Asked by: username_0 on 2024-11-03)
  
  What is the proper syntax for the 'filters' value in API4? Trying to create a discount item that is applicable to certain membership types and event types.
  E.g., here's what I've got, but it doesn't work, and the filters is the culprit (i.e., if I omit the filters line, it creates the discount item just fine, but without the event types, obviously... which I need for this use case):
  
  ```
  $results = \Civi\Api4\DiscountCode::create(TRUE)
    ->addValue('code', $gcCode)
    ->addValue('description', 'gift certificate')
    ->addValue('amount', $gcAmount)
    ->addValue('amount_type', 2)
    ->addValue('count_max', 1)
    ->addValue('active_on', date("Y-m-d"))
    ->addValue('is_active', TRUE)
    ->addValue('memberships', [
      1,
      3,
      7,
    ])
    ->addValue('filters.event.event_type_id', [
      1,
      2,
      11,
    ])
    ->execute();
  
  ```
  
  Thank you for any pointers.
  
  **Tags:** api4
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2024-11-03. Score: 3 | Accepted answer
  
  OK, so through some trial and error, figured out the following syntax for the filters value to limit the discount to specific event types:
  
  ```
  ->addValue('filters', [
      'event' => ['event_type_id' => ['IN' => ['1', '2', '11']]],
    ])
  
  ```
  
  
  ---
  
  