You tried the following (also unverified):
function getMe(accessToken) { return Rx.Observable.fromPromise(axios.get({ url: 'https://api.spotify.com/v1/me', })); } Rx.Observable.fromPromise(axios(config)) .map((res) => { return { accessToken: res.data.access_token, refreshToken: res.data.refresh_token } }) .flatMap((res) => { return getMe(res.accessToken).map((res2) => { res.me = res2; return res; } }) .subscribe((data) => console.log(data));
As mentioned in a previous post, flatMap returns the observable. map then used to combine res with the result res2 returned from the second promise.
Also note that fromPromise is an observable cold. This means that you must have a subscription to initiate things. In your case, I suppose you already have something like this:
someFunction = () => { return Rx.Observable.fromPromise(axios(config)) ... ... } someFunction.subscribe((data) => console.log(data));
source share