I'm quite new to making my own API's and backend. I've set up an express server that has an API call to Salesforce that returns (in the terminal):
{
attributes: {
type: 'Opportunity',
url: '/services/data/v42.0/sobjects/Opportunity/xxxxxxxxxxxx'
},
Id: 'xxxxxxxxxxxx',
Name: 'United Oil Standby Generators',
StageName: 'Closed Won'
}
However, when I try to call the API from inside Nuxt using asyncData, it returns nothing. Here is my asyncData:
asyncData ({ params, error, $http }) {
return $http
.$get('/api/salesforce/' + params.id)
.then((res) => {
console.log('here we go')
console.log(res.json)
return { opp: res }
})
.catch((e) => {
error({ statusCode: 404, message: 'User not found, ' + e })
})
},
When I run the page, my terminal console returns results (since I've asked the express server to do that), but when I use the Vue tools on Chrome or try to access the data, there is nothing in Opp. If I return res.json - it returns as undefined. It should be returning as .json already since I've set it in the backend.
Could anyone see where I'm going wrong here? Like I said - I'm pretty new to working with my own API's.