Answered

Get user id

  • 5 November 2020
  • 2 replies
  • 869 views

Userlevel 2
Badge +3

Hi,

I have tried a few ways to get the current user id, but I always encounter a error in one way or another. What is the most basic way to get a user id? So far I have mainly tried this:

 

async function getUser() {

        const proxyurl = "https://cors-anywhere.herokuapp.com/" // getting cors error without this

        const url = "https://api.miro.com/v1/users/me"

 

        const options = {

            "method": "GET",

            "headers": {

                “Authorization”: `Bearer ${token}`,

                "Content-Type": "application/json"

            }

        }

 

        fetch(proxyurl + url, options)

        .then(response => {

        console.log(response)

        })

        .catch(err => {

        console.error(err)

        })

    }

I’m currently getting error 401 “Not Authorized”

I’ve seen a few discussions in here about a direct miro dot command that can get the user id but can’t find it anywhere in the documentation. Will be thankful for any suggestions as I ran out of ideas of what to try or where to search anymore

icon

Best answer by Viktor Razumov 5 November 2020, 13:59

View original

2 replies

Userlevel 1

Hi Sami,

 

Please use `miro.currentUser.getId()` to acquire an id of the current user. Please note, that this method returns a promise.

 

Hope this helps.

Userlevel 2
Badge +3

Hi Viktor,

Yes this solved my issue. Thanks a lot

Reply