# Get NFT metadata

This API endpoint allows you to retrieve metadata for a specific NFT based on the `contractId` and `nftTokenId`. It also supports optional parameters for token ID formatting.

## Endpoint Details

| Description | Data                                                                               |
| ----------- | ---------------------------------------------------------------------------------- |
| API Name    | [getNftMetadata](https://sandbox.api.labs.zelus.io/docs/#/NFT/get_v1_nft_metadata) |
| HTTP Method | GET                                                                                |
| URL         | `/v1/nft/metadata`                                                                 |

{% tabs %}
{% tab title="Request" %}

#### Headers

| Key          | Value              |
| ------------ | ------------------ |
| Content-Type | `application/json` |
| x-api-key    | API\_KEY           |

#### Query Parameters

| Parameter         | Type             | Description                                                                                            |
| ----------------- | ---------------- | ------------------------------------------------------------------------------------------------------ |
| **contractId**    | string           | Contract ID to get metadata for                                                                        |
| **nftTokenId**    | string           | the smart contract that the NFT belongs to (See the note above)                                        |
| **tokenIdFormat** | string, optional | NFT token id format. Possible values `decimal` or `hex`. Defaults to `decimal` if it is not specified. |

As a prerequisite, you must have one or more NFT contracts that can be managed by your account (see [getAccountContracts](https://github.com/zelusio/alpha-api-docs/blob/master/getAccounContracts.md).
{% endtab %}

{% tab title="Response" %}
The response will contain the metadata of the specified NFT.

```tsx
{
    result: INftMetadata
    | error?: IResponseError   // Optional error information
}

export interface INftTraits {
  displayType: number,
  traitType: string,
  value?: any
}

export interface INftMetadata {
  externalUrl?: string;
  traits: INftTraits[];
  name: string;
  description: string;
  imageUrl: string;
  thumbnailUrl?: string;
  imageMimeType: string;
  thumbnailMimeType?: string;
}
```

#### Success result

```json
{
  "result": {
    "traits": [
      {
        "displayType": "number",
        "traitType": "Member Since",
        "value": 2023
      },
      {
        "displayType": "string",
        "traitType": "Member Tier",
        "value": "Pearl"
      }
    ],
    "name": "SMOOTH Pass",
    "description": "This pass is your key to unlock rewards and more through Smooth's cutting-edge loyalty platform",
    "imageUrl": "https://assets.nft.zelus.io/Smooth-Collectibles-dev/1/image1.png",
    "imageMimeType": "image/png",
    "externalUrl": "https://zelus.io"
  }
}

```

#### Error Messages

* Incorrect or missing `contractId`
  * `{ "code": 400, "message": "Contract not found" }`
* Missing `nftTokenId` or invalid format based on `tokenIdFormat`
  * `{ "code": 404, "message": "NFT not found!" }`
    {% endtab %}
    {% endtabs %}

## Examples

{% tabs %}
{% tab title="CURL" %}

```bash
curl -X GET 'https://sandbox.api.labs.zelus.io/v1/nft/metadata?contractId=yourContractId&nftTokenId=yourTokenId' \
     -H "x-api-key: YOUR_API_KEY"
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = "https://sandbox.api.labs.zelus.io/v1/nft/metadata"
headers = {
    "x-api-key": "YOUR_API_KEY"
}
params = {
    "contractId": "yourContractId",
    "nftTokenId": "yourTokenId"
}

response = requests.get(url, headers=headers, params=params)
nft_metadata = response.json() # Assuming INftMetadata format
print(f"NFT Metadata: {nft_metadata}")
```

{% endtab %}

{% tab title="NodeJS" %}

```javascript
const axios = require('axios');

const url = "https://sandbox.api.labs.zelus.io/v1/nft/metadata";
const headers = {
    "x-api-key": "YOUR_API_KEY"
};
const params = {
    contractId: "yourContractId",
    nftTokenId: "yourTokenId"
};

axios.get(url, { headers: headers, params: params }).then(response => {
    const nft_metadata = response.data; // Assuming INftMetadata format
    console.log(`NFT Metadata: ${JSON.stringify(nft_metadata)}`);
}).catch(error => {
    console.error('Error:', error.response.data);
});
```

{% endtab %}
{% endtabs %}

## Notes

* Make sure to either provide a `contractId` when making the request.
* Token ID is always required and its format can be controlled using the `tokenIdFormat` parameter.
* If using the `hex` format for the token ID, ensure it's a valid hexadecimal value.
* If a `contractId` is used, the base metadata URL retrieved from it combined with the token ID will be used to fetch the metadata.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.labs.zelus.io/zelus-labs-api/reference/nft/getnftmetadata.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
