Skip to main content

Workflows

createVendorCampaignWorkflow

This documentation provides a reference to the createVendorCampaignWorkflow. It belongs to the @mercurjs/b2c-core package. This workflow creates a new campaign and links it to the seller creating it. This allows for seller-specific campaigns within the marketplace. Source code

Examples

packages/modules/b2c-core/src/api/vendor/campaigns/route.ts
import { AuthenticatedMedusaRequest, MedusaResponse } from "@medusajs/framework";
import { createVendorCampaignWorkflow } from "../../../workflows/campaigns/workflows";
import { VendorCreateCampaignType } from "./validators";
import { fetchSellerByAuthActorId } from "../../../shared/infra/http/utils";

export const POST = async (
  req: AuthenticatedMedusaRequest<VendorCreateCampaignType>,
  res: MedusaResponse
) => {
  const seller = await fetchSellerByAuthActorId(
    req.auth_context?.actor_id,
    req.scope
  );

  const { result } = await createVendorCampaignWorkflow(req.scope).run({
    input: { 
      campaign: req.validatedBody, 
      seller_id: seller.id 
    },
  });

  res.status(201).json({ campaign: result[0] });
};

Steps

  • createCampaignsWorkflow: Creates the campaign using Medusa’s core workflow.
  • createRemoteLinkStep: Links the created campaign to the seller (using SELLER_MODULE) and the promotion module.

Input

input
object
required

Output

CampaignDTO[]
CampaignDTO[]
The created campaigns.