> To build or manage a Wix site with an AI agent, follow https://www.wix.com/headless/skill.md
> It builds a new Wix site or puts your own site online, from a prompt, and keeps changing it afterwards. The pages are code in any web technology, and Wix runs the backend.
> It works through the Wix plugin (the Wix MCP and the Wix skills), the Wix CLI or no Wix login, and puts the site live on Wix hosting or on another host.
> Business features include a store, bookings, events and tickets, a restaurant, a blog, forms, members and many more.
> Read the Wix skills online at https://www.wix.com/skills
> 
> Portal Navigation:
> 
> - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version.
> - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages).
> - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`).
> - If a reference page seems to be missing its schema (parameters, return types, or type definitions), append `?schema=true` to its `.md` URL (e.g. `https://dev.wix.com/docs/contexts/contexts/stores/category-info/use-category-info-context.md?schema=true`).
> - Top-level index of all portals: https://dev.wix.com/docs/llms.txt
> - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt

# Method name: assignMembers(badgeId: string, memberIds: Array<string>)

# Method package: wixMembersBackend

# Method menu location: wixMembersBackend --> Badges --> assignMembers

# Method Link: https://dev.wix.com/docs/velo/apis/wix-members-backend/badges/assign-members.md

# Method Description:

Assigns a badge to site members.

The `assignMembers()` function returns a Promise
that resolves when the specified badge is assigned to the specified members.

The `badgeId` parameter must be an ID from your site's `Members/Badges` collection.
Typically, you retrieve the ID from the collection using a query or through a dataset.



# Method Code Examples:

*** Note: do not assume any prop names or enum values other than the ones in the example.

## Assign a badge to members

```javascript
import { Permissions, webMethod } from 'wix-web-module';
import { badges } from 'wix-members-backend';

export const myAssignMembersFunction = webMethod(Permissions.Anyone, () => {
  const badgeId = "3fcaacc0-a3a7-464f-9ba9-f211bdcec9fc";
  const memberIds = [
    "efab296e-2687-4751-9956-ee73200dd4bb",
    "3403e13b-8826-4af6-aa19-18784bb84a8e",
    "28d35f86-6694-4455-9dff-aff5d450b482"
  ];

  return badges.assignMembers(badgeId, memberIds)
    .then((assignedMembers) => {
      return assignedMembers;
    })
    .catch((error) => {
      console.error(error);
    });
});

/* Promise resolves to:
 * {
 *   "memberIds": [
 *     "efab296e-2687-4751-9956-ee73200dd4bb",
 *     "3403e13b-8826-4af6-aa19-18784bb84a8e",
 *     "28d35f86-6694-4455-9dff-aff5d450b482"
 *   ]
 * }
 */
```

## Assign a badge to forum members with a top post

```javascript
/*****************************
 * Backend code - badges.web.js *
 *****************************/

import { Permissions, webMethod } from 'wix-web-module';
import { badges } from 'wix-members-backend';

export const assignMembersBackendFunction = webMethod(Permissions.Anyone, (badgeId, memberIds) => {
  return badges.assignMembers(badgeId, memberIds);
});

/*************
 * Page code *
 ************/

import wixData from 'wix-data';
import { assignMembersBackendFunction } from 'backend/badges.web';

// ...

// Get the "Top Poster" badge ID from the Members/Badges collection
// Must be placed in an async function
const badges = await wixData.query("Members/Badges")
  .contains("title", "Top Poster")
  .find();
const topPosterBadgeId = wixData.query("Members/Badges")
  .contains("title", "Top Poster")
  .find()
  .then((results) => {
    return results.items[0]._id;
  }).catch((error) => {
    console.log(error);
  });

wixData.query("Forum/Posts")
  .gt("likeCount", 50)
  .find()
  .then((results) => {
    if (results.items.length > 0) {
      const topPosts = results.items;

      // Assign post owner IDs to the topPostOwners array
      const topPostOwners = topPosts.map(post => post._ownerId);
      assignMembersBackendFunction(topPosterBadgeId, topPostOwners);
    } else {
      console.log("No top posts");
    }
  })
  .catch((error) => {
    console.log(error);
  });
```

---