如何使用Kentico Cloud Management API将链接的项目正确添加到已存在的链接项目的列表中

时间:2019-06-24 13:18:47

标签: kentico-cloud

在Kentico Cloud中,我得到了一个包含链接项目列表的项目。但是,应该使用Kentico Cloud Management API从外部编辑此列表。有没有一种方法可以简单地将项目添加到此列表中而不更新整个列表?

我正在使用C#中的Kentico Cloud SDK,到目前为止,我尝试的是使用新的ContentItemIdentifier.byId数组来添加语言变体,但是每当我调用它时,它都会覆盖我已经存在的列表。

private async Task AddOrderToDay(string orderItemExternalId, Guid dayId)
{
    ContentItemVariantIdentifier ident = new ContentItemVariantIdentifier(
        ContentItemIdentifier.ById(dayId),
        LanguageIdentifier.DEFAULT_LANGUAGE);

    UpdateOrdersDay update = new UpdateOrdersDay
    {
        Orders = 
           new[]{ContentItemIdentifier.ByExternalId(orderItemExternalId)}
    };

    ContentItemVariantModel<UpdateOrdersDay> response =
        await this._cmclient.UpsertContentItemVariantAsync(ident, update);
}

我希望我的新元素被添加到Cloud中现有的元素列表中。

目前,它只是覆盖了它们。 我尝试了一种解决方法:我调用传递Api来接收当前商品,并将其添加到新的新[] {old1,old2,new ItemIdentifier}中。但是,这种解决方案不是很有效。

1 个答案:

答案 0 :(得分:0)

当前,CM API(包括v2)不支持一一添加/删除链接项。

当您从Delivery API(而不是CM API)获取商品时,当前正在执行的操作是最有效的方法。

将来可能会改变,但是现在您必须先提出其他请求,然后再保存该项目。