# NFCService Data Types

NFCService defines and uses several data types.

## NFCMessage

An object returned by an NFC `read()` operation.

| Property Name     | Type                 | Description                                                                                                  | Example                                                                     |
| ----------------- | -------------------- | ------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------- |
| `totalByteLength` | Number               | The size, in number of bytes, of the data received by the `read()` operation.                                | 256                                                                         |
| `records`         | `NFCMessageRecord[]` | An array containing a single `NFCMessageRecord` object, which in turn contains the payload from the NFC tag. | `[NFCMessageRecord]`                                                        |
| `tagInfo`         | `NFCTagInfo`         | The metadata about the tag. See [`NFCTagInfo`](#nfctaginfo).                                                 | `{ serialNumber: "04:EE:A0:5A", isNdefWritable: false, ndefCapacity: 512 }` |

## NFCTagInfo

An object within an `NFCMessage` object, containing the metadata read from an NFC tag.

| Property Name    | Type    | Description                                                                                                                                          | Example       |
| ---------------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- | ------------- |
| `serialNumber`   | String  | The serial number of the tag.                                                                                                                        | "04:EE:A0:5A" |
| `isNdefWritable` | Boolean | For a tag that can contain NDEF data, indicates whether the tag’s NDEF data can be overwritten. If the tag doesn’t support NDEF, this value is null. | false         |
| `ndefCapacity`   | Number  | The maximum NDEF message size, in bytes, that the tag can hold. If the tag doesn’t support NDEF, this value is null.                                 | 512           |

## NFCMessageRecord

An object within an `NFCMessage` object, containing the payload read from an NFC tag.

| Property Name | Type        | Description                                                                                                                                                                                                                           | Example |
| ------------- | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- |
| `parsed`      | `NFCRecord` | Contains the parsed values of the raw data read from the NFC tag. The parsing operation only occurs if the value of the `typeNameFormat` property on the `NFCRecord` object is "WELLKNOWN". Otherwise, this property’s value is null. |         |
| `raw`         | `NFCRecord` | Contains the raw base64 data string read from the NFC tag.                                                                                                                                                                            |         |

## NFCRecord

An object containing one record of data from an NFC tag scan.

| Property Name    | Type             | Description                                                                                                                           | Example                                                                                                                               |
| ---------------- | ---------------- | ------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
| `typeNameFormat` | `TypeNameFormat` | The Type Name Format field of the payload, as defined by the NDEF specification.                                                      | "WELLKNOWN" See [TypeNameFormat](/docs/platform/lwc/guide/reference-lightning-nfcservice-constants.md) for a list of possible values. |
| `type`           | String           | The type of the payload, as defined by the NDEF specification.                                                                        | "T" (when payload is of type text); "U" (when payload is of type URI)                                                                 |
| `identifier`     | String           | The identifier of the payload, as defined by the NDEF specification, or an empty string if no identifier data was present in the tag. |                                                                                                                                       |
| `payload`        | String           | The content of the record, encoded in base64 format.                                                                                  | "V2XigJlyZSBTYWxlc2ZvcmNlLCBG9tZXIgY29tcGFueS4"                                                                                       |

## TextPayload

An object containing raw text input, to be converted into an `NFCRecord`.

| Property Name | Type   | Description                                                                                          | Example                                   |
| ------------- | ------ | ---------------------------------------------------------------------------------------------------- | ----------------------------------------- |
| `text`        | String | The raw text payload to be converted.                                                                | "We’re Salesforce, the customer company." |
| `langId`      | String | The [ISO 639-1](https://quickref.me/iso-639-1.html#list-of-iso-639-1-codes) language ID of the text. | "en"                                      |

## NFCServiceOptions

An object containing configuration details for an NFC interaction.

| Property Name     | Type    | Description                                                                                                                                                                                                                                                                                                                                                                   | Example                                 |
| ----------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------- |
| `instructionText` | String  | Optional. Provides instructions to display in the user interface. Defaults to no text.                                                                                                                                                                                                                                                                                        | "Hold your phone near the tag to read." |
| `successText`     | String  | Optional. Provides a message to display in the user interface when an NFC operation is successfully completed. Defaults to no text.                                                                                                                                                                                                                                           | "Tag read successfully!"                |
| `allowEmptyTags`  | Boolean | Optional. Indicates whether reading from an empty tag is considered an error. Defaults to `false`, so attempting to read an empty tag returns a `TAG_EMPTY` error. To get the tag metadata even for empty tags, set this property to `true`. The `read()` operation then returns an `NFCMessage` object whose `tagInfo` property is populated instead of a `TAG_EMPTY` error. | true                                    |

## NFCServiceFailure

An object representing an error that occurred when accessing NFCService features.

| Property Name | Type                    | Description                                                                                                                                                                                              |
| ------------- | ----------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `code`        | `NFCServiceFailureCode` | A value representing the reason for an error. See [`NFCServiceFailureCode`](/docs/platform/lwc/guide/reference-lightning-nfcservice-constants.md#nfcservicefailurecode) for the list of possible values. |
| `message`     | String                  | A string value describing the reason for the failure. This value is suitable for use in user interface messages. The message is provided in English and isn’t localized.                                 |

**See Also**

- [NFCService Constants](/docs/platform/lwc/guide/reference-lightning-nfcservice-constants.md)
