i am sending a request to opensea api and trying to log the trait data. an example of the entire response is in pastebin url. thank you for taking the time to review this.
https://pastebin.com/ugQHjbn1
var axios = require("axios").default;
var r = {
method: 'GET',
url: 'https://api.opensea.io/api/v1/assets',
params: { order_direction: 'desc', offset: '0', limit: '1', collection:`enter code here` 'brotchain' }
};
axios.request(r).then(function (response) {
console.log(JSON.stringify(response.data.assets.token_id));
}).catch(function (error) {
console.error(error);
});
your problem is that the assets inside the data is an array, basically, you can not do response.data.assets.token_id because there is no token_id on an Array [].
In order to display each one of the assets, you need to loop over the array and then show the asset info or whatever property inside of it.
here is your code showing all the token_id of each entry and their traits
note: in the future it will help to see the full response and act using the different structures that are defined there.
var r = {
method: 'GET',
url: 'https://api.opensea.io/api/v1/assets',
params: {
order_direction: 'desc',
offset: '0',
limit: '1',
collection: 'brotchain'
}
};
axios.request(r).then(response => {
const assets = response.data.assets;
assets.forEach(asset => {
console.log("token id of the asset", asset.token_id);
console.log("now we will show all the traits for this asset")
console.log(asset.traits);
console.log("end of the asset");
})
}).catch(error => {
console.error(error);
});
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>