Get all nft owners through contract address

Hello I have used this python code for getting all the nft owners.I got a response in the form of a couple of api’s but that api’s was giving this error

{“message”:“API KEY missing from x-api-key header”}

Here is my python code:

import requests
import pandas as pd
import time
from tqdm import tqdm
pd.set_option(‘display.max_colwidth’, None)

import moralis

print(moralis.utils.web3_api_version(api_key=‘6vOnQdQcX1bobkZdmXaOmpHqShIJBxIJB12clWUu9TLX5XXWXtz1O4uiaxkuIsLf’))

it prints {‘version’: ‘0.0.53’}

import requests
import time

def get_nft_owners(offset, cursor):
print(“offset”, offset)
url = ‘https://deep-index.moralis.io/api/v2/nft/0x63e2938F85AC8C21F8099458A73A19fe4a33Ce00/owners?chain=polygon&format=decimal
if cursor:
url = url + “&cursor=%s” % cursor

print("api_url", url)
headers = {
    "Content-Type": "application/json",
    "X-API-Key": "6vonqdqcx1bobkzdmxaomphqshijbxijb12clwuu9tlx5xxwxtz1o4uiaxkuislf"
}
statusResponse = requests.request("GET", url, headers=headers)
data = statusResponse.json()
print("HTTP headers:", statusResponse.headers)
try:
    print("nr results", len(data['result']))
except:
    print(repr(data))
    print("exiting")
    raise SystemExit

cursor = data['cursor']
print(data['page'], data['total'])
return cursor

cursor = None
for j in range(0, 10):
cursor = get_nft_owners(j*5000, cursor)
print()
time.sleep(1.1)

what is the error that you get on the second python script? the one that makes http requests directly without the sdk

the code that you used is from this example?
https://v1docs.moralis.io/misc/rate-limit#example-of-how-to-use-cursor-python

The code is executing properly.But when I clicked on the api this is appearing.
{“message”:“API KEY missing from x-api-key header”}.I have also attached a screenshot.

Screenshot (33)|690x387

That error is expected fi you open that url in the browser, it needs the api key set in the http header in order to work.

Yes then where to exactly place that api key in the http header. I am directly opening it in the google chrome browser.

Now this is one of the url’s

https://deep-index.moralis.io/api/v2/nft/0x63e2938F85AC8C21F8099458A73A19fe4a33Ce00/owners?chain=polygon&format=decimal&cursor=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjdXN0b21QYXJhbXMiOnsidG9rZW5BZGRyZXNzIjoiMHg2M2UyOTM4Zjg1YWM4YzIxZjgwOTk0NThhNzNhMTlmZTRhMzNjZTAwIn0sImtleXMiOlsiMTY4MjAwNTY4Ny42OTciLCIxNjgyMDE4MzIyLjc3NSIsIjE2ODIxMDQyNTMuNDMzIiwiMTY4MjM1NjAyOC4wMjIiLCIxNjgyNDU0MjM2Ljc2MyIsIjE2ODI2MTcxOTIuMjAxIiwiMTY4MjY5MjE1Ny44MiIsIjE2ODI5NDcyODkuODI0IiwiMTY4MzU1NzcyMi4wMjkiXSwid2hlcmUiOnsidG9rZW5fYWRkcmVzcyI6IjB4NjNlMjkzOGY4NWFjOGMyMWY4MDk5NDU4YTczYTE5ZmU0YTMzY2UwMCJ9LCJsaW1pdCI6MTAwLCJvZmZzZXQiOjAsIm9yZGVyIjpbXSwiZGlzYWJsZV90b3RhbCI6dHJ1ZSwidG90YWwiOm51bGwsInBhZ2UiOjksInRhaWxPZmZzZXQiOjEsImlhdCI6MTY4NDEzMzQzMn0.3BbpoBxin7CNeMxqJ8_qLvvqaXoZitCMCCmoUXW1QWg

Exactly where to place the api key?

In the http header, not in the url, you will have to use postman or other tool that can add a field in the http header

Ok I got this kind of a response by using postman which I am attaching in the attachments.Is this correct?I also wanted to know in one response I will be getting 500 records right.

That looks ok, that response, the number of results in a page is 100, you have to use pagination (that cursor parameter) to get the other results if there are more than 100 results

Well its giving me the results but it can’t be automated.I got a couple of api’s and each api I have to compy and paste it in postman.From one api I will get 100 records only.So its does become a manual process in the end.

you can write a script to do that automation

But how will I be able to that. If you have such a script please do help me.

There is a python example in documentation for how to use pagination.