0

Hello I am having difficulty returning an api end point in Gridsome via the Gridsome documented way. I think it is because what is returned is xml insead of pure json.

Does anyone have any ideas as to how to get this data into the graphql layer in Gridsome. This is the documented way to return the data this works for pure json i.e. https://jsonplaceholder.typicode.com/posts but not for http://balfourmanson.master.d8digital.com/umbraco/api/NewsAndEventsApi/getall

const axios = require('axios')
module.exports = function (api) {
api.loadSource(async actions => {
const collection = actions.addCollection('News')
const {
  data
} = await 
axios.get('http://balfourmanson.master.d8digital.com/umbraco/api/NewsAndEventsApi/getall')
for (const item of data) {
  collection.addNode({
    id: item.id,
    title: item.title,
    content: item.content
  })
}
})
 }

Thanks in advance

Adam Adams
  • 63
  • 10

1 Answers1

-1

have a look into this post: Parse XML from Axios response, pushing to Vue data array

This should do the trick. Afterwards you can map your fields. If you have problems come back here.

ewatch
  • 136
  • 4
  • Thank - I will try this and let you know - Im a slow worker so might be a while. Thanks. – Adam Adams Jan 10 '20 at 13:49
  • thanks for your feedback here - turns out it was a different problem or me just being dumb. the errors I was getting were due to me misunderstanding things. I was trying to call items that didnt exist in the collection bit and not having unique ids. – Adam Adams Jan 10 '20 at 15:24
  • You're welcome and no worries. I see. Good if you're making progress. – ewatch Jan 10 '20 at 16:30