> 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

## Resource: Find Premium Billing Issues and Unassigned Subscriptions

## Article: Find Premium Billing Issues and Unassigned Subscriptions

## Article Link: https://dev.wix.com/docs/api-reference/account-level/premium/skills/find-premium-billing-issues-and-unassigned-subscriptions.md

## Article Content:

# Find Premium Billing Issues and Unassigned Subscriptions

Always run the script below for billing-problem questions and for questions about subscriptions that aren't connected to a site. It takes no input. Run it as its own call, unchanged; never answer from memory or from a previous reply.

The script is an account call: run it as an account-level script, with no site ID. It calls [Query Premium Assets](https://dev.wix.com/docs/api-reference/account-level/premium/premium-platform/core-services/premium-asset-v2/query-premium-assets.md) (`POST https://www.wixapis.com/premium-assets/v2/premium-assets/query`) for this account's active subscriptions and follows the cursor for at most 5 calls. It returns two lists:

- `billingIssues`: the subscriptions whose last payment is `CHARGE_ATTEMPT_FAILED`, `IN_PROGRESS` or `NOT_BILLABLE`;
- `unassignedSubscriptions`: the subscriptions with no site (`siteData.metasiteId` is empty), shown with "—" in the Site/Role column of Premium Subscriptions.

Both lists cover recurring subscriptions (plans, domains, business email, apps and other catalog products), not digital goods or one-time purchases; when you say there are none, say "on your Premium subscriptions" rather than an unqualified "none". For a question only about domains (which domains aren't connected to a site, or a domain's connection), use the Analyse Domain recipe instead.

If you cannot run a script, make the same Query Premium Assets calls one by one (account scope, the body shown in the script) and apply the same `keepAsset` and `ISSUE_STATUSES` filters.

```javascript
async function () {
  const MAX_CALLS = 5;
  // CHARGE_ATTEMPT_FAILED: a failed or declined charge. IN_PROGRESS: a payment retry is pending.
  // NOT_BILLABLE: the payment can't be collected automatically and must be made manually.
  const ISSUE_STATUSES = ["CHARGE_ATTEMPT_FAILED", "IN_PROGRESS", "NOT_BILLABLE"];

  // Subscriptions to plans, domains, business email, apps and other catalog products; not digital goods or one-time purchases.
  function keepAsset(a) {
    if (a.digitalGoodsData) return false;
    const cycle = String(((a.billingCycle || {}).cycleType) || "").toUpperCase();
    return cycle !== "ONE_TIME";
  }

  function productName(a) {
    const p = a.productData || {};
    return p.productName || (a.domainsData || {}).domain || (a.mailboxesData || {}).domainName || p.productTypeName || "";
  }

  function cycleLabel(a) {
    const d = (a.billingCycle || {}).cycleDuration || {};
    if (!d.count || !d.unit) return "";
    const u = String(d.unit).toLowerCase();
    if (u.indexOf("year") >= 0) return Number(d.count) === 1 ? "Yearly" : d.count + " years";
    if (u.indexOf("month") >= 0) return Number(d.count) === 1 ? "Monthly" : d.count + " months";
    return d.count + " " + u;
  }

  function issueRow(a) {
    const s = a.siteData || {};
    const b = a.wixBillingDetails || {};
    const last = b.lastInvoiceDetails || {};
    const next = b.nextInvoiceDetails || {};
    const pm = b.paymentMethod || {};
    return {
      productName: productName(a),
      productTypeName: (a.productData || {}).productTypeName || "",
      siteName: s.siteName || "",
      assignment: s.metasiteId ? "assigned" : "unassigned",
      status: a.status || "",
      renewalType: a.renewalType || "",
      lastPaymentStatus: last.paymentStatus || "",
      lastPaymentDate: last.date || "",
      lastPaymentAmount: [last.amount, last.currencyCode].filter(Boolean).join(" "),
      nextPaymentDate: next.date || "",
      paymentMethodLabel: pm.displayLabel || "",
      updatePaymentMethodUrl: "https://manage.wix.com/account/subscriptions?referralInfo=sidebar&premiumId=" + encodeURIComponent(a.premiumId || "")
    };
  }

  function unassignedRow(a) {
    const b = a.wixBillingDetails || {};
    const last = b.lastInvoiceDetails || {};
    const next = b.nextInvoiceDetails || {};
    const pm = b.paymentMethod || {};
    return {
      productName: productName(a),
      productTypeName: (a.productData || {}).productTypeName || "",
      status: a.status || "",
      renewalType: a.renewalType || "",
      billingCycle: cycleLabel(a),
      subscriptionEndDate: a.subscriptionEndDate || "",
      customCharges: Boolean(b.customCharges),
      lastInvoiceStatus: last.paymentStatus || "",
      lastInvoiceDate: last.date || "",
      nextInvoiceDate: next.date || "",
      paymentMethodLabel: pm.displayLabel || ""
    };
  }

  const billingIssues = [];
  const unassignedSubscriptions = [];
  let cursor = "";
  let includePermitted = true;
  for (let call = 0; call < MAX_CALLS; call++) {
    const cursorQuery = cursor
      ? { cursorPaging: { cursor: cursor, limit: 100 } }
      : { cursorPaging: { limit: 100 }, filter: { status: { $eq: "ACTIVE" } } };
    let res;
    try {
      res = await wix.request({
        scope: "account",
        method: "POST",
        url: "https://www.wixapis.com/premium-assets/v2/premium-assets/query",
        body: { cursorQuery: cursorQuery, includePermitted: includePermitted }
      });
    } catch (e) {
      // A caller with no signed-in user (an API key) can't read plans shared with the account: check its own plans.
      if (!includePermitted || String((e && e.message) || e).indexOf("subject is missing") < 0) throw e;
      includePermitted = false;
      call--;
      continue;
    }
    const data = res.premiumAssets ? res : res.data || {};
    for (const a of data.premiumAssets || []) {
      if (String(a.status || "").toUpperCase() !== "ACTIVE") continue;
      if (!keepAsset(a)) continue;
      const paymentStatus = String(((a.wixBillingDetails || {}).lastInvoiceDetails || {}).paymentStatus || "").toUpperCase();
      if (ISSUE_STATUSES.indexOf(paymentStatus) >= 0) billingIssues.push(issueRow(a));
      if (!(a.siteData || {}).metasiteId) unassignedSubscriptions.push(unassignedRow(a));
    }
    cursor = ((data.pagingMetadata || {}).cursors || {}).next || "";
    if (!cursor) break;
  }
  return {
    incomplete: Boolean(cursor),
    note: "Answer only what the user asked: a billing or payment question uses billingIssues; an unassigned or not-connected subscription question uses unassignedSubscriptions.",
    billingIssuesNote: billingIssues.length === 0
      ? (cursor
        ? "No billing issues in the subscriptions checked, but the account has more than were read: say that and offer to check further."
        : "No billing issues: say there are no billing issues. Never claim the check failed.")
      : "Present each row: plan, site, last payment status and date, next payment date and payment method. Suggest updating the payment method for CHARGE_ATTEMPT_FAILED rows. Never tell the user to check the billing dashboard instead.",
    billingIssues: billingIssues,
    unassignedNote: unassignedSubscriptions.length === 0
      ? (cursor
        ? "None in the subscriptions checked, but the account has more than were read: say that and offer to check further."
        : "Say the account has no unassigned subscriptions.")
      : "List every subscription below, once each: plan, status, renewal type, subscription end date, next payment date and payment method; leave out the site name, since none is assigned.",
    unassignedSubscriptions: unassignedSubscriptions
  };
}
```

Answer only what the user asked: use `billingIssues` for a billing or payment problem and `unassignedSubscriptions` for subscriptions that aren't connected to a site.

## Dashboard links

Premium pages are account-level (no metaSiteId); see [Dashboard Navigation](https://dev.wix.com/docs/api-reference/business-solutions/bookings/skills/dashboard-navigation.md) for the general URL contract.

| Page | URL | Use |
|---|---|---|
| Premium Subscriptions | `https://manage.wix.com/account/subscriptions` | All the account's subscriptions (the Site/Role column shows "—" for unassigned ones) |
| One subscription on Premium Subscriptions | `https://manage.wix.com/account/subscriptions?referralInfo=sidebar&premiumId={premiumId}` | Opens that subscription, where the user updates its payment method; the script builds it as `updatePaymentMethodUrl` |

## Billing issues: how to answer

Flag CHARGE_ATTEMPT_FAILED (failed/declined charge), IN_PROGRESS (payment retry pending), and NOT_BILLABLE statuses.
Present plan, site, last payment status/date, next payment date, and payment method.
If the script returns and `billingIssues` is empty, say there are no billing issues — never claim the script failed.
If the script call itself fails (an error, not an empty list), say the billing check couldn't run right now and offer to try again. Never say there are no billing issues in that case.
If `incomplete` is true, the account has more subscriptions than the script read (500): say the answer covers only those and offer to check further, instead of a flat "no billing issues".

Suggest updating the payment method for CHARGE_ATTEMPT_FAILED results.
If the user then asks for help updating the payment method, or says "can you help me do that?", "can you do that for me?", "update it", or similar — do NOT give Billing & Payments / dashboard steps, and do NOT say you cannot update the payment method. If your client has its own update-payment-method action, hand the request to it. Otherwise give the row's `updatePaymentMethodUrl`: it opens that subscription on the account's Premium Subscriptions page, where the user updates its payment method.

Never tell the user to check the billing dashboard instead.

Don't mention field or status names such as `CHARGE_ATTEMPT_FAILED` or `renewalType`: say "the last charge failed", "a payment retry is pending" or "this payment must be made manually".

Out of scope: refunds, cancelling a subscription, and making a payment for the user.

## Unassigned subscriptions: how to answer

1. List every subscription in `unassignedSubscriptions`. For each one, show: plan (from productName), status, renewal type, subscription end date, next payment date, and payment method. Include the billing cycle when it helps.
2. Format them the same way as site-connected subscriptions, but leave out the site name, since none is assigned.
3. If a field is missing for a subscription, leave it out or say it isn't available. Don't guess.

### Rules

- If `unassignedSubscriptions` has any rows, list them. Never say there are none when results are present.
- If it has no rows, say the account has no unassigned subscriptions; when `incomplete` is true, say the check covered only the first 500 subscriptions instead.
- If the script fails, say you couldn't load the subscriptions right now and offer to try again. Do not make up a list.
- Do not show internal identifiers such as the subscription ID.
- Be brief and factual. Show only what the script returned.