0
async function apiCall(KEY_1, KEY_2) {

let result = {}

await axios.get('https://cococloud-drive.com/api/v2/authorize', { params: { key1: KEY_1, key2: KEY_2 } })
    .then((res) => {

        result.accountId = res.data.data.account_id
        result.accessToken = res.data.data.access_token
        result.status = 'success'

    })
    .catch((e) => {
        result.status = 'error'
    })

return result

}

const result = apiCall(KEY_1, KEY_2)

console.log(result) if (result.status === 'success') { console.log(result) }`

I am calling this function and when I console.log inside the function, it returns the value but when I console.log(result) calling the API, it returns promise.

I want to access result.accountId and result.accessToken

0 Answers0