Answers.Body: <p>After a bit of research I added documentation which explains how to write <code>_spec</code> functions: </p>
  
  <p><a href="https://docs.civicrm.org/dev/en/latest/framework/api-architecture/#spec" rel="nofollow noreferrer">https://docs.civicrm.org/dev/en/latest/framework/api-architecture/#spec</a></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-11-17T02:16:14.933Z
Answers.LastActivityDate: 2017-11-17T02:16:14.933Z
Answers.UserDisplayName: Sean
Answers.Body: <p>As per <a href="https://github.com/civicrm/civicrm-core/blob/master/api/v3/Dashboard.php#L64" rel="nofollow noreferrer">https://github.com/civicrm/civicrm-core/blob/master/api/v3/Dashboard.php#L64</a> you can set default values, You can also specify the type and even limit to specific options see <a href="https://github.com/civicrm/civicrm-core/blob/master/api/v3/Contribution.php#L552" rel="nofollow noreferrer">https://github.com/civicrm/civicrm-core/blob/master/api/v3/Contribution.php#L552</a> also <a href="https://github.com/civicrm/civicrm-core/blob/master/api/v3/Contribution.php#L723" rel="nofollow noreferrer">https://github.com/civicrm/civicrm-core/blob/master/api/v3/Contribution.php#L723</a>. Also as per <a href="https://github.com/civicrm/civicrm-core/blob/master/api/v3/Contribution.php#L360" rel="nofollow noreferrer">https://github.com/civicrm/civicrm-core/blob/master/api/v3/Contribution.php#L360</a> you can specify aliases or alternate field names for legacy or similar handling</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-07-10T00:41:40.203Z
Answers.Text: These are useful examples, but what I'm really looking for is a *comprehensive list*, in part because I'd like to write new documentation for on this subject to help other developers in the future.
Answers.UserDisplayName: Sean
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-07-11T21:12:51.323Z
Answers.Text: Hi Sean i looked around and i struggled to build a comprehensive list for myself, However it seems to do similar things to getFields, So my hunch is that you can put in anything that the xml files would accept, + api.required and api.default to specify if you need the field or not and what the default value of the field is
Answers.UserDisplayName: Seamus Lee
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-07-11T21:47:28.263Z
Answers.Text: Seamus, yeah I had the same thought. But even that rule of thumb doesn't seem "complete" to me because I've also noticed `'api.unique'` and `'api.aliases'`, `'api.filter'`, `'api.return'`, `'description'`, `'FKClassName'`, `'FKApiName'`, `'supports_joins'`, `'options'`, ... yada yada. Personally it's very important to me that documentation be [complete](http://www.writethedocs.org/guide/writing/docs-principles/#complete), so I'm searching for some sort of authoritative way to verify a complete list here.
Answers.UserDisplayName: Sean
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-07-11T22:58:16.300Z
Answers.Text: Sean i think apart from checking in with the folks in the API channel there really isn't much other documentation on the _spec functions. Eileen probably knows as much as anyone else
Answers.UserDisplayName: Seamus Lee
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-07-09T22:33:53.673Z
Answers.LastActivityDate: 2017-07-09T22:33:53.673Z
Answers.UserDisplayName: Seamus Lee
Body: <p>When I run...</p>
  
  <pre><code>civix generate:api foo bar
  </code></pre>
  
  <p>...civix generates the following code:</p>
  
  <pre><code>function _civicrm_api3_foo_Bar_spec(&amp;$spec) {
    $spec['magicword']['api.required'] = 1;
  }
  </code></pre>
  
  <p>From this example, I can see how to make fields <em>required</em> when writing APIs. Cool. But <em>what else</em> can I do with this <code>$spec</code> array? Can I set default values? Can I indicate what <em>type</em> of value to accept? Can I specify an array of valid values? Or a regex pattern to test for validity? </p>
  
  <p>Really, I'm not looking for answers to those specific questions, <strong>I'm looking for a comprehensive list</strong> of <em>everything</em> I can type in place of <code>'api.required'</code> above (and an explanation of how each one works).</p>
  
Tags: <api><developer><civix>
Title: How do I write the _spec function for my custom API?
ThreadText: # How do I write the _spec function for my custom API?
  
  (Asked by: username_0 on 2017-07-09)
  
  When I run...
  civix generate:api foo bar
  
  ...civix generates the following code:
  function _civicrm_api3_foo_Bar_spec(&$spec) {
    $spec['magicword']['api.required'] = 1;
  }
  
  From this example, I can see how to make fields required when writing APIs. Cool. But what else can I do with this $spec array? Can I set default values? Can I indicate what type of value to accept? Can I specify an array of valid values? Or a regex pattern to test for validity? 
  Really, I'm not looking for answers to those specific questions, I'm looking for a comprehensive list of everything I can type in place of 'api.required' above (and an explanation of how each one works).
  
  **Tags:** api, developer, civix
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_0 on 2017-11-17. Score: 2 | Accepted answer
  
  After a bit of research I added documentation which explains how to write `_spec` functions:
  
  <https://docs.civicrm.org/dev/en/latest/framework/api-architecture/#spec>
  
  
  ---
  
  ### Answer by username_1 on 2017-07-09. Score: 1
  
  As per <https://github.com/civicrm/civicrm-core/blob/master/api/v3/Dashboard.php#L64> you can set default values, You can also specify the type and even limit to specific options see <https://github.com/civicrm/civicrm-core/blob/master/api/v3/Contribution.php#L552> also <https://github.com/civicrm/civicrm-core/blob/master/api/v3/Contribution.php#L723>. Also as per <https://github.com/civicrm/civicrm-core/blob/master/api/v3/Contribution.php#L360> you can specify aliases or alternate field names for legacy or similar handling
  
  > **Comments:**
  > **username_0**: These are useful examples, but what I'm really looking for is a *comprehensive list*, in part because I'd like to write new documentation for on this subject to help other developers in the future.  
  > **username_1**: Hi username_0 i looked around and i struggled to build a comprehensive list for myself, However it seems to do similar things to getFields, So my hunch is that you can put in anything that the xml files would accept, + api.required and api.default to specify if you need the field or not and what the default value of the field is  
  > **username_0**: Seamus, yeah I had the same thought. But even that rule of thumb doesn't seem "complete" to me because I've also noticed `'api.unique'` and `'api.aliases'`, `'api.filter'`, `'api.return'`, `'description'`, `'FKClassName'`, `'FKApiName'`, `'supports_joins'`, `'options'`, ... yada yada. Personally it's very important to me that documentation be [complete](http://www.writethedocs.org/guide/writing/docs-principles/#complete), so I'm searching for some sort of authoritative way to verify a complete list here.  
  > **username_1**: username_0 i think apart from checking in with the folks in the API channel there really isn't much other documentation on the _spec functions. Eileen probably knows as much as anyone else  
  
  ---
  
  