> 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`). > - 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: upsertMarketingConsent(marketingConsent: MarketingConsent) # Method package: wixMarketingV2 # Method menu location: wixMarketingV2 --> marketingConsent --> upsertMarketingConsent # Method Link: https://dev.wix.com/docs/velo/apis/wix-marketing-v2/marketing-consent/upsert-marketing-consent.md # Method Description: Creates or updates a marketing consent. Required fields: - `details.type`. - `details.email` OR `details.phone`. - `state`. When a marketing consent's `state` is `PENDING` or `CONFIRMED`, the `info.lastConfirmationActivity` field is required. When a marketing consent's `state` is `REVOKED`, the `info.lastRevokeActivity` field is required. >**Note:** For existing marketing consents with `{"type": "EMAIL"}`, you can't update the `state` to `UNKNOWN_STATE`. Trying to do so maintains the current state. However, you can create a new marketing consent and set the `state` to `UNKNOWN_STATE`. Note that you can't create more than a single consent per email or phone number. # Method Code Examples: *** Note: do not assume any prop names or enum values other than the ones in the example. ## upsertMarketingConsent example for dashboard page code ```javascript import { marketingConsent } from 'wix-marketing.v2'; async function upsertMarketingConsent(marketingConsent) { try { const result = await marketingConsent.upsertMarketingConsent(marketingConsent); return result; } catch (error) { console.error(error); // Handle the error } } ``` ## upsertMarketingConsent example for exporting from backend code ```javascript import { marketingConsent } from 'wix-marketing.v2'; import { webMethod, Permissions } from 'wix-web-module'; import { elevate } from 'wix-auth'; const elevatedUpsertMarketingConsent = elevate(marketingConsent.upsertMarketingConsent); export const upsertMarketingConsent = webMethod( Permissions.Anyone, async (marketingConsent) => { try { const result = await elevatedUpsertMarketingConsent(marketingConsent); return result; } catch (error) { console.error(error); // Handle the error } } ); ``` ---