kontent-ai / management-sdk-net

Kontent.ai Management .NET SDK
https://www.nuget.org/packages/Kontent.Ai.Management
MIT License
7 stars 31 forks source link

ExternalID for existing contentitem isnt updated #239

Closed Domitnator closed 1 year ago

Domitnator commented 1 year ago

Brief bug description

I am retrieving an existing item, then set the externalID and then upsert the content item but the externalID is null after the upsert

Repro steps

var internalIdentifier = Reference.ById(Guid.Parse(internalItem.System.Id));
cim = await _managementClient.GetContentItemAsync(internalIdentifier);

if (cim != null)
{
    cim.ExternalId = externalItem.System.Id;

    cim = await _managementClient.UpsertContentItemAsync(internalIdentifier, cim);
}

After the upsertContentItemAsync the cim.ExternalId is null. Also i am not able to retrieve it by its external id:

 cim = await _managementClient.GetContentItemAsync(externalItem.System.Id);

Expected behavior

After calling the UpsertContentItemAsync the externalID should be set.

Test environment

Additional context

Add any other context about the problem here.

Screenshots

Before UpsertContentItemAsync:

image

Aftter UpsertContentItemAsync:

image

Enngage commented 1 year ago

This is a correct behavior from the API's point of view as you cannot set external_id to already existing items:

(https://kontent.ai/learn/reference/openapi/management-api-v2/#operation/add-a-content-item)

upsert

Simply007 commented 1 year ago

Hello @Domitnator,

thanks for reaching out. As @Enngage wrote, the inability to update the External ID is on the API, so we can't really do anything more. If you want to request the feature directly to the product, feel free to do so via Intercom (easiest it from the Roadmap page, or via Feedback portal).

I am more curious about your use case. What are you trying to achieve by syncing the system ID and External ID? My hunch says it might be connected with environments and the inability of MAPI API to get the External ID/codename as an identification in responses.

Domitnator commented 1 year ago

Hi @Simply007

Thanks for your answer! It felt like a bug but as @Enngage pointed out, it is documented in the documentation! So i should have read more carefully haha.

About the use case:

So there needs to be a connection between some of the FAQ-items, that's why we use the ExternalID. For newly created FAQ-items (created in the secure project) this works perfecly. When the webhook is triggered i can check if the public faq-item already exists (based on the externalID), if yes then update the item..otherwise, create the item.

But those 200 which already exist in the public project i cannot retrieve by the externalID, therefor i wanted to update the externalID. So as a fallback i try to retrieve it by the codename (but then the codename in the public and secure project always need to be the same, which can be tricky).

I hope my usecase is clear? Otherwise feel free to contact me!

Simply007 commented 1 year ago

Thank you for the sum up. As I said this is the API limitation currently and feel free to submit feedback to get this attention from the product. I will try to pass the scenario as well.

But I am afraid there is not much we can do without changing the identification mechanism drastically in the product. To give you a bit of context the External ID is tightly bound to System.ID. The main use case is to ensure consistency but allows to import of circular dependencies, or not to care whether some dependent entities being imported first - https://kontent.ai/learn/tutorials/set-up-kontent-ai/import-content/linked-content/#a-2-use-external-ids-to-reference-items

Unfortunately, I can offer you not a straightforward workaround from the SDK/API offering point of view.

  1. There is a unification scenario

    • use a separate text field/custom_element and merge the external ID in there.
  2. And then the OLD FAQ migration to their clones (which might be easy if you are not linking the FAQs from many places)

    • Get the items + item variants linking the old FAQs
    • Get old FAQs items (without external ID) and their item variants
    • Create their clones of the items with External ID and their variants + create a map - old FAQ => new FAQ (upsert with a different identifier)
    • Update the items linking the FAQs
    • Archive/delete the old ones