Contentful - get all assets

contentful - getAssets

by pj_js15

HTML

<script src="https://npmcdn.com/[email protected]/browser-dist/contentful.js"></script>
<script src="https://npmcdn.com/[email protected]/marked.min.js"></script>
<body>
  <div id="content" class="content-container"></div>
</body>

CSS

body {
  padding: 0;
  margin: 0;
  border: none;
  font-family: 'Avenir', sans-serif;
}

a {
  border-bottom: 1px dotted #5B9FEF;
  color: #4A90E2;
  text-decoration: none;
}

.products {
  display: flex;
  flex-direction: column;
  margin-top: 20px;
}

.product-in-list {
  display: flex;
  margin-bottom: 60px;
}

.product-image a {
  border-bottom: none;
}

.product-header h2 {
  display: inline;
}

.product-header h2 a {
  border-bottom: none;
}

.product-details {
  padding-left: 10px;
}

.product-details > * {
  margin-bottom: 10px;
}

.product-categories {
  font-weight: bold;
}

.product-tags span {
  font-weight: bold;
}

JavaScript

//const contentful = require('contentful')

const client = contentful.createClient({
  space: '3191dnj4thnr',
  environment: 'master', // defaults to 'master' if not set
  accessToken: '_Khr8XbIiqAQKhXEJpD2jd6TwMX7hdD4K9TygBtp60A'
});

/*
client.getAssets()
.then((response) => console.log(response.items))
.catch(console.error);
*/

client.getAssets()
.then((response) => {
	
	console.log(response.items);
  response.items.forEach(function(elem){
  	console.log(elem.fields.title);
    //debugger;
    //console.log(elem.fields["title"]);
  });
  //debugger;
})
.catch(console.error)