Answers.Body: <p>you are almost there: instead of using the tag name, use the tag id (eg 5 for Volunteers)</p>
  
  <pre><code>CRM.api3('Contact', 'get', {
    "debug": 1,
    "sequential": 1,
    "return": ["tag"],
    "tag": "5"
  }).done(function(result) {
    console.log(result);
  });
  </code></pre>
  
  <p>And for performance reasons, we recommend to always set the return param with the list of fields you actually need (by default, it returns way too many that you don't need)</p>
  
  <p>Otherwise, yes, it should work with the name of the tag instead of the id, but given that tags are one of the few entities that don't have an internal name that only the dev can change, I'd rather rely on the id rather than on the visible name that your users can alter</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-02-22T15:50:16.897Z
Answers.Text: Thanks!  This is super helpful.  I was afraid we would have to go through and add a new custom field and search by that.  
  Is there any extensive documentation of the API? Something that might contain a little more in-depth info like this? What exists on the Civi site right now is pretty sparse.  Thanks again.
Answers.UserDisplayName: Brad Xanti
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-02-22T21:24:46.560Z
Answers.Text: In addition, do you know of a way to do an AND on the tags?  For example, if I wanted to find any contact that had `tag: 5` and `tag: 7`, is there any way to do that with just 1 Ajax request?  It seems to me that it defaults to `OR` functionality.  It returns all contacts with either `tag: 5` or `tag: 7`.
Answers.UserDisplayName: Brad Xanti
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-02-23T08:07:24.237Z
Answers.Text: hi, the api explorer and all the generated examples from the unit tests are pretty extensive. as for new questions, could you create them as new questions, the comment format is aweful as soon as it's more than a line or two ;)
Answers.UserDisplayName: Xavier
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-02-19T10:50:18.387Z
Answers.LastActivityDate: 2016-02-19T10:50:18.387Z
Answers.UserDisplayName: Xavier
Body: <p>I'm working with the CiviCRM API and it's been great--I've been able to make a very useful tool for our team.  However, I've encountered a problem.  </p>
  
  <p>I would like to do a search on contacts based on a tag.  However, whenever I make a call to the database asking for a particular tag, I get an error.  The following is an example I used on the <a href="http://dmaster.demo.civicrm.org/civicrm/api#explorer" rel="noreferrer">demo site</a>:</p>
  
  <pre><code>CRM.api3('Contact', 'get', {
    "sequential": 1,
    "tag": "Company"
  }).done(function(result) {
    // do something
  });
  </code></pre>
  
  <p>I receive the following error in the response:</p>
  
  <pre><code>{
    "error_code": "no such field",
    "tip": "add debug=1 to your API call to have more info about the error",
    "is_error": 1,
    "error_message": "DB Error: no such field"
  }
  </code></pre>
  
  <p>Now, I receive a <em>different</em> error in test use on my own site, but is it possible in some way to do a search in the API for a contact based on tag?</p>
  
Tags: <api><tags><javascript>
Title: CiviCRM Ajax API - Searching by Tag
ThreadText: # CiviCRM Ajax API - Searching by Tag
  
  (Asked by: username_0 on 2016-02-18)
  
  I'm working with the CiviCRM API and it's been great--I've been able to make a very useful tool for our team. However, I've encountered a problem.
  
  I would like to do a search on contacts based on a tag. However, whenever I make a call to the database asking for a particular tag, I get an error. The following is an example I used on the [demo site](http://dmaster.demo.civicrm.org/civicrm/api#explorer):
  
  ```
  CRM.api3('Contact', 'get', {
    "sequential": 1,
    "tag": "Company"
  }).done(function(result) {
    // do something
  });
  
  ```
  
  I receive the following error in the response:
  
  ```
  {
    "error_code": "no such field",
    "tip": "add debug=1 to your API call to have more info about the error",
    "is_error": 1,
    "error_message": "DB Error: no such field"
  }
  
  ```
  
  Now, I receive a *different* error in test use on my own site, but is it possible in some way to do a search in the API for a contact based on tag?
  
  **Tags:** api, tags, javascript
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-02-19. Score: 6 | Accepted answer
  
  you are almost there: instead of using the tag name, use the tag id (eg 5 for Volunteers)
  
  ```
  CRM.api3('Contact', 'get', {
    "debug": 1,
    "sequential": 1,
    "return": ["tag"],
    "tag": "5"
  }).done(function(result) {
    console.log(result);
  });
  
  ```
  
  And for performance reasons, we recommend to always set the return param with the list of fields you actually need (by default, it returns way too many that you don't need)
  
  Otherwise, yes, it should work with the name of the tag instead of the id, but given that tags are one of the few entities that don't have an internal name that only the dev can change, I'd rather rely on the id rather than on the visible name that your users can alter
  
  > **Comments:**
  > **username_0**: Thanks!  This is super helpful.  I was afraid we would have to go through and add a new custom field and search by that.   Is there any extensive documentation of the API? Something that might contain a little more in-depth info like this? What exists on the Civi site right now is pretty sparse.  Thanks again.  
  > **username_0**: In addition, do you know of a way to do an AND on the tags?  For example, if I wanted to find any contact that had `tag: 5` and `tag: 7`, is there any way to do that with just 1 Ajax request?  It seems to me that it defaults to `OR` functionality.  It returns all contacts with either `tag: 5` or `tag: 7`.  
  > **username_1**: hi, the api explorer and all the generated examples from the unit tests are pretty extensive. as for new questions, could you create them as new questions, the comment format is aweful as soon as it's more than a line or two ;)  
  
  ---
  
  