Your workflow is unique 👨‍💻 -  tell us how you use Dropbox here.

Forum Discussion

jkdev's avatar
jkdev
Explorer | Level 3
4 years ago

Cannot get Access Token via https://api.dropboxapi.com/oauth2/token!

When I try to get an access Token using Fetch in JavaScript via the in the title specified endpoint, it returns this:

 

{"webSocket":null,"url":"https://api.dropboxapi.com/oauth2/token","redirected":false,"ok":true,"headers":{},"statusText":"OK","status":200,"bodyUsed":false,"body":{"locked":false}}

 

 

My Code is this:

 

    async function getInitial() {
      let dropBoxConnection = await fetch(`https://api.dropboxapi.com/oauth2/token`, {
        body: new URLSearchParams({
          code: dropToken,
          grant_type: 'authorization_code',
          redirect_uri: DropBoxData.redirect,
          client_id: DropBoxData.key,
          client_secret: DropBoxData.secret
        }),
        method: "POST"
      }).then((response) => {
        return response;
      }).catch((error) =>  {
        return new Error(error);
      });

      return await dropBoxConnection;
    }

    if(dropToken) var DropboxReturn = await getInitial();

    return new Response("Old Token: " + dropToken + ";" + " API-Response: " + JSON.stringify(DropboxReturn));

 

2 Replies

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    4 years ago

    I see you're getting a 200 status code which should indicate that the call completed, but I don't see the actual response body here. Can you print out the response body? I can't offer help with fetch itself so you may need to refer to the fetch documentation for information on using it.

  • jkdev's avatar
    jkdev
    Explorer | Level 3
    4 years ago

    I figured it out.. I used the wrong method to print out the response body. I printed out the Response, when I should've printed out Response.json().

About Discuss Dropbox Developer and API

Node avatar for Discuss Dropbox Developer and API
Explore Dropbox Developer & API discussions with developers like you.

The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.

If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X, Facebook or Instagram.

For more info on available support options for your Dropbox plan, see this article.

If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!