How i can set a Data Entity with MDV2 for unique register by field (DNI and Email)

How i can set a Data Entity with MDV2 for unique register by field (DNI and Email)

I have a Data Entity call Embajadora, this receives records of a form in the frontend but I have to validate that only new email and documents (DNI) must be register, if email or document exists the record must be denied.

i don’t will that in any case a user can be registrar several times.

My intention is, that seting a number of DNI and email that unique fields, in the moment that user try register in second or third time, VTEX return a error.

I use this API to create index but it doesn’t not work for me:

Endpoint

https://{{accountNameVDNEWQA}}.{{environmentVDNEWQA}}/api/dataentities/Embajadora/indices

Request body

[
    {
        "name": "AlternateKeyUsernumDocumento",
        "acronym": "Embajadora",
        "isGlobal": true,
        "multiple": false,
        "fields": "numDocumento"
    },
    {
        "name": "AlternateKeyUserEmail",
        "acronym": "Embajadora",
        "isGlobal": true,
        "multiple": false,
        "fields": "email"
    }
]

When you say it doesn’t work, what do you mean? Do you:

  1. Get an error response (like a status code 4xx / 5xx)
  2. You aren’t able to get documents using alternate keys?

If it’s option 1, you can use the Get indices endpoint to check whether your changes were saved. If they weren’t saved, please share the error you get and any additional context you may have.

If it’s option 2, it is important to note that the index of a document is created when the document is created or modified, so changes will only impact documents that are created/updated after you change the index (as described in the documentation).

Dear george brindeiro, i don’t will that in any case a user can be registrar several times.

My intention is, that seting a number of DNI and email that unique fields, in the moment that user try register in second or third time, VTEX return a error.

But i dont know how.

I use this API to create an index, it works for me, but I have to wait for some time

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.