Emi Jerochim
Emi Jerochim

Reputation: 3

JSON Async/Await Uncaught SyntaxError: missing ) after argument list

When I hardcode a value it works perfectly

username = "leomessi";
let id = await (await fetch(`https://www.instagram.com/${username}/?__a=1`)).json();
console.log(id.graphql.user.id);

But when I make it a function

const userToID = (username) => {
    let id = await (await fetch(`https://www.instagram.com/${username}/?__a=1`)).json();
    return id.graphql.user.id;
}

it says Uncaught SyntaxError: missing ) after argument list

Upvotes: 0

Views: 760

Answers (2)

richytong
richytong

Reputation: 2462

You need to use the async keyword for functions where you want to await

const userToID = async (username) => {
    let id = await (await fetch(`https://www.instagram.com/${username}/?__a=1`)).json();
    return id.graphql.user.id;
}

Upvotes: 0

Chase
Chase

Reputation: 3126

So first of all, you are using await. This means you should expect to define your wrapping function as async.

const userToID = async (username) => {
    let id = await (await fetch(`https://www.instagram.com/${username}/?__a=1`)).json();
    return id.graphql.user.id;
}

Upvotes: 2

Related Questions