首页 > 解决方案 > wix-events-backend createEvent() 代码在 eventInfo 上失败

问题描述

尝试为 Wix 事件创建程序化事件。

遵循此处详述的步骤: https ://www.wix.com/velo/reference/wix-events-backend/wixevents/createevent

IE,

import { wixEvents } from "wix-events-backend";

const eventInfo = {
  title: "Healthy Living Series: Exercise and You",
  location: {
    name: "Community Hall",
    address: {
      formatted: "100 Gansevoort St, New York, NY 10014, USA",
      city: "New York City",
      subdivision: "New York",
      country: "USA",
      postalCode: "10014",
      streetAddress: {
        number: "100",
        name: "Gansevoort Street",
        apt: "10"
      }
    },
    type: 'VENUE',
  },
  scheduling: {
    startDate: "2021-09-14T13:30:00.000Z",
    endDate: "2021-09-14T15:30:00.000Z",
    timeZoneId: "America/New_York"
  },
  registration: {
    initialType: 'RSVP'
  }
};

const options = {
  language: "en"
};

export function myCreateEventFunction() {
  return wixEvents.createEvent(eventInfo, options)
    .then((result) => {
      return result;
    })
    .catch((error) => {
      console.error(error);
    });
}

提供的代码片段在 eventInfo 参数上失败并出现此错误: wix createEvent()事件信息错误

Argument of type '{ title: any; description: any; about: any; location: { name: any; address: { formatted: any; city: any; subdivision: any; country: any; postalCode: any; streetAddress: { number: string; name: string; apt: string; }; }; type: string; }; scheduling: { ...; }; registration: { ...; }; }' is not assignable to parameter of type 'WixEventInfo'. Type '{ title: any; description: any; about: any; location: { name: any; address: { formatted: any; city: any; subdivision: any; country: any; postalCode: any; streetAddress: { number: string; name: string; apt: string; }; }; type: string; }; scheduling: { ...; }; registration: { ...; }; }' is missing the following properties from type 'WixEventInfo': locationInfo, schedulingInfo

任何人都有任何线索如何克服这个问题?

标签: javascriptbackendvelo

解决方案


我在编辑器中看到了同样的错误,但如果你实际运行代码,你可能会得到不同的错误,通过 .catch((error) 传递到 console.log。

我能够通过 a) 更改不正确的位置国家/地区字段来使用测试代码创建事件

    country: "USA",

    country: "US",

b) 删除调度字段的开始和结束日期并改用 TBD:

  scheduling: {
    tbd: true,
    tbdMessage: "pending my dates",
    timeZoneId: "EST"
  }

我尝试了许多不同的开始日期和结束日期格式,但无法让它们中的任何一个工作,包括示例中的那些

    startDate: "2021-09-14T13:30:00.000Z",
    endDate: "2021-09-14T15:30:00.000Z",

Wix 文档也没有多大帮助,例如在定义输入参数 eventInfo 时 - 它说结构包含名称为“schedulingInfo”的对象,但这是不正确的,它必须是“调度”;奇怪的是,如果您在代码中将其更改为 scheduleInfo(以及将位置更改为 locationInfo),您不会收到您发布的静态错误,但您确实会收到运行时错误。

我将在 Wix 的论坛中提出这个问题,所以要小心。


推荐阅读