> Portal Navigation: > > - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version. > - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages). > - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`). > - Top-level index of all portals: https://dev.wix.com/docs/llms.txt > - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt # InsertDataItemReferences # Package: externalDatabases # Namespace: ExternalDatabaseService # Method link: https://dev.wix.com/docs/api-reference/business-solutions/cms/external-databases/external-database-service-plugin/insert-data-item-references.md ## Introduction Inserts one or more item references into a referring field of the specified item. --- ## REST API ### Schema ``` Method: insertDataItemReferences Description: Inserts one or more item references into a referring field of the specified item. URL: null Method: POST # Note: If the parameter `a.b` is listed under required parameters, `b` is only required if `a` is also present. Required parameters: collectionId, referringFieldKey, references Method parameters: param name: collectionId | type: collectionId | description: GUID of the referring collection. | required: true param name: references | type: array | description: References to insert. | required: true - name: referringItemId | type: string | description: GUID of the item in the referring collection. - name: referencedItemId | type: string | description: GUID of the item in the referenced collection. param name: referringFieldKey | type: referringFieldKey | description: Field GUID of the field in the referring collection to insert references into. | required: true Return type: InsertDataItemReferencesResponse - name: results | type: array | description: Response must include either the inserted reference or an error. - ONE-OF: - name: reference | type: ReferenceId | description: Reference that was inserted or removed. - name: referringItemId | type: string | description: GUID of the item in the referring collection. - name: referencedItemId | type: string | description: GUID of the item in the referenced collection. - name: error | type: Error | description: Error indicating why the operation failed for a particular item. Learn more about [error types](https://dev.wix.com/docs/rest/assets/data/external-database-spi/understanding-error-types-in-the-external-database-connections-spi.md) in the External Database Connections service plugin. - name: errorCode | type: string | description: Error code. - name: errorMessage | type: string | description: Error description. - name: data | type: object | description: Additional error data specific to the error code. ``` ### Examples ### Insert an item reference Creates a reference from one item to another. ```curl curl -X POST https://external-db.example.com/v3/items/insert-references \ -H 'Content-Type: application/json;charset=UTF-8' \ -H 'Authorization: ' \ -d '{ "collectionId": "cities", "referringFieldKey": "pointsOfInterest", "references": [{ "referringItemId": "c285e77c-a86b-4361-a55f-c6b934d70187", "referencedItemId": "faa17edb-2d88-488d-8e95-24b9364c3284" }] }' ``` ### Insert multiple item references Creates two item references, one of which succeeds while the other fails. ```curl curl -X POST https://external-db.example.com/v3/items/insert-references \ -H 'Content-Type: application/json;charset=UTF-8' \ -H 'Authorization: ' \ -d '{ "collectionId": "cities", "referringFieldKey": "pointsOfInterest", "references": [{ "referringItemId": "c285e77c-a86b-4361-a55f-c6b934d70187", "referencedItemId": "faa17edb-2d88-488d-8e95-24b9364c3284" }, { "referringItemId": "c285e77c-a86b-4361-a55f-c6b934d70187", "referencedItemId": "0348998e-48d7-463e-96c3-a571d4a568a8" }] }' ``` --- ## JavaScript SDK ### Schema ``` Method: wixClientAdmin.externalDatabases.ExternalDatabaseService.insertDataItemReferences(request, metadata) Description: Inserts one or more item references into a referring field of the specified item. Method parameters: param name: metadata | type: Context | description: this message is not directly used by any service, it exists to describe the expected parameters that SHOULD be provided to invoked Velo methods as part of open-platform. e.g. SPIs, event-handlers, etc.. NOTE: this context object MUST be provided as the last argument in each Velo method signature. Example: ```typescript export function wixStores_onOrderCanceled({ event, metadata }: OrderCanceledEvent) { ... } ``` - name: requestId | type: string | description: A unique identifier of the request. You may print this GUID to your logs to help with future debugging and easier correlation with Wix's logs. - name: currency | type: string | description: [ISO 4217](https://en.wikipedia.org/wiki/ISO_4217) 3-letter currency code. - name: identity | type: IdentificationData | description: An object that describes the identity that triggered this request. - ONE-OF: - name: anonymousVisitorId | type: string | description: GUID of a site visitor that has not logged in to the site. - name: memberId | type: string | description: GUID of a site visitor that has logged in to the site. - name: wixUserId | type: string | description: GUID of a Wix user (site owner, contributor, etc.). - name: appId | type: string | description: GUID of an app. - name: languages | type: array | description: A string representing a language and region in the format of `"xx-XX"`. First 2 letters represent the language code according to ISO 639-1. This is followed by a dash "-", and then a by 2 capital letters representing the region according to ISO 3166-2. For example, `"en-US"`. - name: instanceId | type: string | description: The service provider app's instance GUID. param name: request | type: InsertDataItemReferencesRequest - name: collectionId | type: string | description: GUID of the referring collection. - name: referringFieldKey | type: string | description: Field GUID of the field in the referring collection to insert references into. - name: references | type: array | description: References to insert. - name: referringItemId | type: string | description: GUID of the item in the referring collection. - name: referencedItemId | type: string | description: GUID of the item in the referenced collection. Return type: PROMISE - name: results | type: array | description: Response must include either the inserted reference or an error. - ONE-OF: - name: reference | type: ReferenceId | description: Reference that was inserted or removed. - name: referringItemId | type: string | description: GUID of the item in the referring collection. - name: referencedItemId | type: string | description: GUID of the item in the referenced collection. - name: error | type: Error | description: Error indicating why the operation failed for a particular item. Learn more about [error types](https://dev.wix.com/docs/rest/assets/data/external-database-spi/understanding-error-types-in-the-external-database-connections-spi.md) in the External Database Connections service plugin. - name: errorCode | type: string | description: Error code. - name: errorMessage | type: string | description: Error description. - name: data | type: object | description: Additional error data specific to the error code. ``` ### Examples ### Example of a `results` return value ```javascript import { externalDatabase } from '@wix/data/service-plugins'; externalDatabase.provideHandlers({ insertDataItemReferences: async ( payload ) => { const {request, metadata} = payload; // Use the `request` and `metadata` received from Wix and // apply custom logic. return { // Return your response exactly as documented to integrate with Wix. // Return value example: results: [ { reference: { referringItemId: "c285e77c-a86b-4361-a55f-c6b934d70187", referencedItemId: "faa17edb-2d88-488d-8e95-24b9364c3284" } } ] } } }); ``` ### insertDataItemReferences (self-hosted) Self-hosted SDK calls require you to [create a client](https://dev.wix.com/docs/sdk/articles/work-with-the-sdk/about-the-wix-client.md). ```javascript import { createClient } from '@wix/sdk'; import { externalDatabase } from '@wix/data/service-plugins'; // Import the auth strategy for the relevant access type // Import the relevant host module if needed const myWixClient = createClient ({ modules: { externalDatabase }, // Include the auth strategy and host as relevant }); async function insertDataItemReferences(request,metadata) { const response = await myWixClient.externalDatabase.insertDataItemReferences(request,metadata); }; ``` ---