# Search Communities

## Search Communities

<mark style="color:blue;">`GET`</mark> `https://api.whisk.com/community/v2/search`

You can append the following query parameters to the base URL to search communities:

#### Query Parameters

| Name                             | Type    | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| -------------------------------- | ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| query                            | string  | Keywords to match communities.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| filter\_diets                    | array   | <p>A list of available diet labels to choose from for filtering search results.<br>You can choose one or more of these diet labels:<br>- <code>DIET\_VEGETARIAN</code><br>- <code>DIET\_VEGAN</code><br>- <code>DIET\_OVO\_VEGETARIAN</code><br>- <code>DIET\_LACTO\_VEGETARIAN</code><br>- <code>DIET\_OVO\_LACTO\_VEGETARIAN</code><br>- <code>DIET\_PESCATARIAN</code><br>- <code>DIET\_KETOGENIC</code><br>- <code>DIET\_DETOX</code><br>- <code>DIET\_PALEO</code><br>- <code>DIET\_DAIRY\_FREE</code><br>- <code>DIET\_GLUTEN\_FREE</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| filters.cuisines                 | array   | <p>A list of available cuisine labels to choose from for filtering search results.<br>You can choose one or more of these cuisine labels:<br>- <code>CUISINE\_AFRICAN</code><br>- <code>CUISINE\_AMERICAN</code><br>- <code>CUISINE\_ASIAN</code><br>- <code>CUISINE\_AUSTRALIAN</code><br>- <code>CUISINE\_BRITISH</code><br>- <code>CUISINE\_CAJUN\_AND\_CREOLE</code><br>- <code>CUISINE\_CANADIAN</code><br>- <code>CUISINE\_CARIBBEAN</code><br>- <code>CUISINE\_CHINESE</code><br>- <code>CUISINE\_CUBAN</code><br>- <code>CUISINE\_EASTERN\_EUROPEAN</code><br>- <code>CUISINE\_EUROPEAN</code><br>- <code>CUISINE\_FRENCH</code><br>- <code>CUISINE\_GERMAN</code><br>- <code>CUISINE\_GREEK</code><br>- <code>CUISINE\_INDIAN</code><br>- <code>CUISINE\_ISRAELI</code><br>- <code>CUISINE\_ITALIAN</code><br>- <code>CUISINE\_JAPANESE</code><br>- <code>CUISINE\_KOREAN</code><br>- <code>CUISINE\_LATIN\_AMERICAN</code><br>- <code>CUISINE\_MEDITERRANEAN</code><br>- <code>CUISINE\_MEXICAN</code><br>- <code>CUISINE\_MIDDLE\_EASTERN</code><br>- <code>CUISINE\_MOROCCAN</code><br>- <code>CUISINE\_PORTUGUESE</code><br>- <code>CUISINE\_SOUTHERN</code><br>- <code>CUISINE\_SPANISH</code><br>- <code>CUISINE\_TEX\_MEX</code><br>- <code>CUISINE\_THAI</code><br>- <code>CUISINE\_VIETNAMESE</code><br>- <code>CUISINE\_WORLD\_CUISINE</code></p> |
| filters.meal\_types              | array   | <p>A list of available meal type labels to choose from for filtering search results.<br>You can choose one or more of these meal type labels:<br>- <code>MEAL\_TYPE\_APERITIF</code><br>- <code>MEAL\_TYPE\_APPETIZERS</code><br>- <code>MEAL\_TYPE\_BEVERAGES</code><br>- <code>MEAL\_TYPE\_BREADS</code><br>- <code>MEAL\_TYPE\_BREAKFAST</code><br>- <code>MEAL\_TYPE\_BRUNCH</code><br>- <code>MEAL\_TYPE\_COCKTAILS</code><br>- <code>MEAL\_TYPE\_CONDIMENTS\_AND\_SAUCES</code><br>- <code>MEAL\_TYPE\_DESSERTS</code><br>- <code>MEAL\_TYPE\_DINNER</code><br>- <code>MEAL\_TYPE\_JUICES</code><br>- <code>MEAL\_TYPE\_LUNCH</code><br>- <code>MEAL\_TYPE\_MAIN\_COURSE</code><br>- <code>MEAL\_TYPE\_SALADS</code><br>- <code>MEAL\_TYPE\_SIDE\_DISHES</code><br>- <code>MEAL\_TYPE\_SMOOTHIES</code><br>- <code>MEAL\_TYPE\_SNACKS</code><br>- <code>MEAL\_TYPE\_SOUPS\_AND\_STEWS</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| filters.ingredients              | array   | One or more ingredients to filter search results. This parameter takes each ingredient as a separate value. For example, to add butter and milk to the ingredients filter, your URL should look something like this: `"https://api.whisk.com/community/v2/search?filters.ingredients=butter&filters.ingredients=milk"`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| filters.apply\_user\_preferences | boolean | Determines if the search should consider the user preferences for finding communities. When set to `True`, it takes user preferences like - diets, disliked ingredients, etc., into account while searching for communities and ordering the search results based on relevance.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| sorting.by                       | string  | <p>Determines if the search results should be sorted by a particular attribute. You can use one of these available values:<br>- <code>SEARCH\_SORT\_INVALID</code><br>- <code>SEARCH\_SORT\_BY\_NAME</code><br>- <code>SEARCH\_SORT\_BY\_CREATED\_AT</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| sorting.direction                | string  | <p>Determines the sorting order of the search results when the <code>sorting.by</code> parameter is being used. You can use one of these available values:<br>- <code>SORTING\_DIRECTION\_INVALID</code><br>- <code>SORTING\_DIRECTION\_ASC</code><br>- <code>SORTING\_DIRECTION\_DESC</code><br><br><strong>Note</strong>: The sorting parameters can be left to their default value <code>SEARCH\_SORT\_INVALID</code> and <code>SORTING\_DIRECTION\_INVALID</code> to sort the search results based on relevance.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| paging.limit                     | string  | The maximum number of communities to retrieve.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| paging.cursors.after             | string  | This parameter is used for cursor-based pagination. It takes a community ID as its value and performs a search on only those communities that appear after it in the database.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| paging.cursors.before            | string  | This parameter is used for cursor-based pagination. It takes a community ID as its value and performs a search on only those communities that appear before it in the database.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| fields                           | array   | <p>Any additional community details to retrieve. You can choose one or more of these supported values:<br>- <code>COMMUNITY\_FIELD\_DESCRIPTION</code><br>- <code>COMMUNITY\_FIELD\_TOPICS</code><br>- <code>COMMUNITY\_FIELD\_SOCIAL\_SETTINGS</code><br>- <code>COMMUNITY\_FIELD\_PERMISSIONS</code><br>- <code>COMMUNITY\_FIELD\_MEMBERS\_COUNT</code><br>- <code>COMMUNITY\_FIELD\_RECIPES\_COUNT</code><br>- <code>COMMUNITY\_FIELD\_SPONSORED</code><br><br><strong>Note</strong>: For performance reasons, we recommend using this parameter only when required.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |

#### Headers

| Name           | Type   | Description                                                                      |
| -------------- | ------ | -------------------------------------------------------------------------------- |
| Authentication | string | User token to authorize the API usage. For more information, see Authentication. |

```graphql
{
  "communities": [
    {
      "community": {
        "id": "string",
        "name": "string",
        "image": {
          "url": "string",
          "width": 0,
          "height": 0,
          "selection": {
            "x": 0,
            "y": 0,
            "width": 0,
            "height": 0
          }
        },
        "description": "string",
        "topics": [
          {
            "id": "string",
            "display_name": "string"
          }
        ],
        "social_settings": {
          "website_url": "string",
          "instagram_username": "string",
          "youtube_channel_url": "string",
          "tiktok_username": "string"
        },
        "permissions": {
          "role": "COMMUNITY_ROLE_INVALID",
          "mode": "COMMUNITY_CONTRIBUTION_PERMISSION_MODE_INVALID",
          "visibility": "COMMUNITY_VISIBILITY_INVALID"
        },
        "members": {
          "count": 0
        },
        "recipes": {
          "count": 0
        },
        "is_sponsored": true
      },
      "is_member": true
    }
  ],
  "paging": {
    "cursors": {
      "after": "string",
      "before": "string"
    },
    "total": "string"
  }
}
```

```yaml
{
  "error_code": "REAL_CODES_ARE_IN_ENDPOINT_DESCRIPTION",
  "message": "Additional details about error are not static and can be changed"
}
```

{% tab title="401 This failed response appears due to API authentication failure. The possible error codes that may appear are: auth.tokenNotFound , auth.tokenExpired, auth.tokenInvalid, auth.tokenRequired." %}

```yaml
{
  "code": "auth.tokenNotFound"
}
```

```yaml
This is unexpected response, something is wrong on our side, please contact: help@whisk.com
```

Here are a few examples of communities search:

### Example 1 - Top 3 Oldest Vegan Communities on Whisk

Let's assume that you need to find the top 3 oldest vegan communities on Whisk. You can find it easily using a combination of `filter.diets`*,* `sorting.by`, `sorting.direction` and `paging.limit` parameters.\
\
Here is how a curl request would look and the sample response you may get:

{% hint style="info" %}
With time, the response results may differ due to the activity that may have happened on the Whisk platform.
{% endhint %}

{% tabs %}
{% tab title="Curl Request" %}

```bash
curl -X GET "https://api.whisk.com/community/v2/search?filters.diets=DIET_VEGAN&sorting.by=SEARCH_SORT_BY_CREATED_AT&sorting.direction=SORT_DIRECTION_ASC&paging.limit=3"
    -H "Accept: application/json" 
    -H "Authorization: Bearer <YOUR-API-ACCESS-KEY>"
```

{% hint style="info" %}
Whisk allows you to discover and understand its API capabilities on the Swagger interface with the ability to try out the API calls directly in your browser. You can call this endpoint [here](https://api.whisk.com/spec/#/CommunityAPI/CommunityAPI_SearchCommunities).
{% endhint %}
{% endtab %}

{% tab title="Response" %}

```graphql
{
  "communities": [
    {
      "community": {
        "id": "fa204a9ef7514c80bba62f82df7075c2",
        "name": "Vegan Friendly",
        "image": {
          "url": "https://image-cdn.whisk.com/image/upload/v1589451153/community/6e133ad3158b0132b57adddc99b6fbf0.jpg",
          "width": 1670,
          "height": 1000
        }
      }
    },
    {
      "community": {
        "id": "ae706a9d537a498190a13162f0cce1e2",
        "name": "Our Noble Kitchen",
        "image": {
          "url": "https://image-cdn.whisk.com/image/upload/v1594381200/community/1767be32befdd0e53846e50bf08d37fc.jpg",
          "width": 1280,
          "height": 1280
        }
      }
    },
    {
      "community": {
        "id": "b4751be96ee148d7a66d36c5d3b6f895",
        "name": "The Yogic Diet",
        "image": {
          "url": "https://image-cdn.whisk.com/image/upload/v1594560620/community/fab98c92432f14360b714e45f415ac5d.jpg",
          "width": 1280,
          "height": 853
        }
      }
    }
  ],
  "paging": {
    "cursors": {
      "after": "eyJpZCI6ImI0NzUxYmU5NmVlMTQ4ZDdhNjZkMzZjNWQzYjZmODk1IiwiaW5kZXgiOjJ9"
    }
  }
}
```

{% hint style="info" %}
Note: To understand the data structure of a community definition, see [Community Object](https://docs.whisk.com/api/community/..#community-object).
{% endhint %}
{% endtab %}
{% endtabs %}

### Example 2 - Communities for Asian Cuisine containing Seafood recipes

Let's assume that you want to find communities created specifically for **Asian** cuisine and has **Seafood** recipes. Additionally, for each community found, you would like to retrieve its **Description** and **Recipe Count**. You can perform this search using the `query`, `filters.cuisines` and `fields` parameters.\
\
Here is how a curl request would look and the sample response you may get:

{% hint style="info" %}
**Note**: With time, the response results may differ due to the activity that may have happened on the Whisk platform.
{% endhint %}

{% tabs %}
{% tab title="Curl Request" %}

```bash
curl -X GET "https://api.whisk.com/community/v2/search?query=seafood&filters.cuisines=CUISINE_ASIAN&sorting.by=SEARCH_SORT_BY_INVALID&sorting.direction=SORT_DIRECTION_INVALID&fields=COMMUNITY_FIELD_DESCRIPTION&fields=COMMUNITY_FIELD_RECIPES_COUNT"
    -H "Accept: application/json"
    -H "Authorization: Bearer <YOUR-API-ACCESS-KEY>"
```

{% hint style="info" %}
Whisk allows you to discover and understand its API capabilities on the Swagger interface with the ability to try out the API calls directly in your browser. You can call this endpoint [here](https://api.whisk.com/spec/#/CommunityAPI/CommunityAPI_SearchCommunities).
{% endhint %}
{% endtab %}

{% tab title="Response" %}

```graphql
{
  "communities": [
    {
      "community": {
        "id": "375bc4135e784d6d80b5cd8b6db65ffe",
        "name": "Barramundi recipes",
        "description": "Mild tasting Asian sea bass is the perfect versatile fish to try out with these recipes",
        "recipes": {
          "count": 18
        }
      }
    },
    {
      "community": {
        "id": "c62d83682c644144989cffc8813692c4",
        "name": "Contemporary Asian",
        "description": "Vietnamese, Japanese, Malaysian and many other asian cuisine staples with a modern twist",
        "recipes": {
          "count": 20
        }
      }
    },
    {
      "community": {
        "id": "96e140fec4da4a1485e5aadcccad6808",
        "name": "The Taste Of Asia",
        "description": "Popular Asian cuisine recipes ",
        "recipes": {
          "count": 20
        }
      }
    },
    {
      "community": {
        "id": "b37ecdecb5d34990ad24a27ef6cdbeb0",
        "name": "Asian cravings",
        "image": {
          "url": "https://image-cdn.whisk.com/image/upload/v1611022873/community/cde7d6a5a56b843a45ac81fb28b4e299.jpg",
          "width": 1000,
          "height": 686
        },
        "recipes": {
          "count": 9
        }
      }
    },
    {
      "community": {
        "id": "013acb8e9fc84c64afedc6c770de9908",
        "name": "Xanthe’s Food Book",
        "image": {
          "url": "https://image-cdn.whisk.com/image/upload/v1601322812/community/1ea6efb30c8c53cd003c0c042cfff416.jpg",
          "width": 1280,
          "height": 1707
        },
        "description": "Asian, Fusion, Mediterrean and Mexican food",
        "recipes": {
          "count": 26
        }
      }
    }
  ],
  "paging": {
    "cursors": {}
  }
}
```

{% hint style="info" %}
Note: To understand the data structure of a community definition, see [Community Object](https://docs.whisk.com/api/community/..#community-object).
{% endhint %}
{% endtab %}
{% endtabs %}

### Example 3 - Communities for Salad Recipes filtered by User Preferences

Let's assume that you want to find communities created for **Salad** recipes containing one or more recipes that include **Chicken Breast** as an ingredient. Additionally, you would also like the search to consider your **User Preferences** while filtering communities. You can perform this search using the `filters.meal_types`, `filters.ingredients` and `filters.apply_user_preferences` parameters.\
\
Here is how a curl request would look and the sample response you may get:

{% hint style="warning" %}
Depending on your user preferences and time, the results in the response may differ.
{% endhint %}

{% tabs %}
{% tab title="Curl Request" %}

```bash
curl -X GET "https://api.whisk.com/community/v2/search?filters.meal_types=MEAL_TYPE_SALADS&filters.ingredients=chicken%20breast&filters.apply_user_preferences=true&sorting.by=SEARCH_SORT_BY_INVALID&sorting.direction=SORT_DIRECTION_INVALID"
    -H "Accept: application/json" 
    -H "Authorization: Bearer <YOUR-API-ACCESS-KEY>"
```

{% hint style="info" %}
Whisk allows you to discover and understand its API capabilities on the Swagger interface with the ability to try out the API calls directly in your browser. You can call this endpoint [here](https://api.whisk.com/spec/#/CommunityAPI/CommunityAPI_SearchCommunities).
{% endhint %}
{% endtab %}

{% tab title="Response" %}

```graphql
{
  "communities": [
    {
      "community": {
        "id": "f986a96282e84ec4ae036420a0a2a676",
        "name": "Lebanese Cooking & Recipes",
        "image": {
          "url": "https://image-cdn.whisk.com/image/upload/v1610196239/community/3632afe4f7977ce76cf5012b02a834b1.jpg",
          "width": 1125,
          "height": 1317
        }
      }
    },
    {
      "community": {
        "id": "b52c6c3de979401ebd68337ef7c90538",
        "name": "21 Days of Happy Salads 🥗abbycooksdinner",
        "image": {
          "url": "https://image-cdn.whisk.com/image/upload/v1609904874/community/3864da8890e316330cfc67eb1d832873.jpg",
          "width": 1280,
          "height": 1405
        }
      }
    }
  ],
  "paging": {
    "cursors": {}
  }
}
```

{% hint style="info" %}
Note: To understand the data structure of a community definition, see [Community Object](https://docs.whisk.com/api/community/..#community-object).
{% endhint %}
{% endtab %}
{% endtabs %}
