API - Uploading Art
This page gives a full guide on how to use the API + Python to upload your art/media

API Bulk Upload

Note - this guide is currently under construction

Overview

Before we get into the step by step guide, lets cover a general overview of the approach, from here, we are making the assumption that you have the image/video/3D files already created and the metadata is stored in a format that you already know how to interact with. This then reduces our challenge to:
  • Create a method than can upload one NFT to NMKR Studio
    • Construct the API Call
    • Convert the source media into Base64 (unless you have already uploaded to IPFS
    • Build the JSON object
    • Make the API Call, with the JSON appended
  • Iterate through all media and metadata to upload the whole collection
Note - when you upload to NMKR Studio, we also then automatically store your art on Immutable IPFS storage.
You may (this is rare) have already uploaded your art to your own IPFS storage, which makes this a slightly more simple process.

Writing the Script (Python)

To use the API, you will simply need any programming or scripting language that allows you to make HTTP POST requests and work with the JSON format. For this guide, we will demonstrate how this can be done using a very popular language - Python.
We will be mainly utilising the UploadNFT API call from the NMKR PRO API

Construct the API call

First, import the requests library:
import requests
Next, create a helper function that will upload a single NFT, if provided with correct JSON data. This method below takes in the already built JSON data (see further into this guide) and the ID of the project. You will need to replace the 'xxxxxxxxxxxxx' with your API Key. This method works by creating the base API call, which is comprised of the base URL, your API Key and your project ID.
The 'uploadPost' variable then makes a HTTP POST call and pushes the JSON data, to the base API URL.
def uploadSingleNFT(finalJson, projectID):
baseApiCall = 'https://api.nmkr.io/UploadNft/xxxxxxxxxxxx/'
baseApiCall = baseApiCall + str(projectID)
uploadPost = requests.post(baseApiCall,json=finalJson)
#print(uploadPost.content)
Note - the next part requires you to match your metadata to your own project, this is a working example only.
The NMKR Studio Metadata template for this example looks like:
{
"721": {
"<policy_id>": {
"<asset_name>": {
"name": "<asset_name>",
"image": "<ipfs_link>",
"SerialNumber": "<serial_num>",
"mediaType": "<mime_type>",
"description": "<description>",
"Website": "<website>",
"Twitter": "<twitter>"
}
},
"version": "1.0"
}
}
An example JSON Builder, to match the above Metadata template would look like:
Note that, as mentioned above, this assumes you have the raw metadata in an accessible format, hence this method takes in an array of data, where the first item (item 0) is the file name and item 1 is the serial number.
Some variables are more static (such as the website and twitter links, so these can be hard-coded). These are then added into variables, that get added to the JSON template at runtime. You can see how adding in new elements can be done for the additional data you want to implement.
def buildJSON(arrayIN):
FILENAME = arrayIN[0]
NO = arrayIN[1]
WEBSITE = "www.boocrewnft.co.uk"
TWIITER = "www.twitter.com/boocrewnft"
TARGET = pngToBase64("Complete/B/" + FILENAME + ".png")
finalJson = {
"assetName": FILENAME,
"previewImageNft": {
"name": FILENAME,
"mimetype": "image/png",
"fileFromBase64": TARGET,
"description": "BooCrew " + "Series A #" + str(NO),
"metadataPlaceHolder": [
{
"name": "series_code",
"value": "A"
},
{
"name": "website",
"value": str(WEBSITE)
},
{
"name": "twitter",
"value": str(TWIITER)
},
{
"name": "serial_num",
"value": str(NO)
}
]
},
}
return finalJson

Already Uploaded to IPFS

Note - on line 6, you will see the variable 'TARGET', in this case we are converting a locally stored PNG image into Base64 for uploading.
If you have already uploaded your media to another file storage like IPFS, you can simply reference the URL here and don't need to do any converting.
Line 6 will become (where element 2 of the array is the location ID of the media):
TARGET = arrayIN[2]
Line 13 will become:
"fileFromIPFS": TARGET,

PNG to Base64

Assuming (like most projects) you have decided to let us handle the IPFS storage for you, you will need to include the raw, Base64 data for your art in the JSON that you upload. Below is some python code you can copy, which will convert a PNG file into Base64.

Iterating

The final task is now to iterate through all of your raw metdata and media, running the 'uploadSingleNFT' method.
Copy link
On this page
API Bulk Upload
Overview
Writing the Script (Python)
Already Uploaded to IPFS
PNG to Base64
Iterating