# Revoke oauth token with Node.js SDK

**URL:** <https://developer.squareup.com/forums/t/revoke-oauth-token-with-node-js-sdk/14065>\
**Category:** Questions\
**Tags:** oauth-api, node-js\
**Created:** [March 29, 2024, 7:52am UTC](https://developer.squareup.com/forums/t/revoke-oauth-token-with-node-js-sdk/14065 "2024-03-29T07:52:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![akmicro](https://avatars.discourse-cdn.com/v4/letter/a/7cd45c/32.png) [@akmicro](https://developer.squareup.com/forums/u/akmicro)\
**Post date:** [March 29, 2024, 7:52am UTC](https://developer.squareup.com/forums/t/revoke-oauth-token-with-node-js-sdk/14065/1 "2024-03-29T07:52:19Z")

</div>

I am using the Node.js SDK successfully for several API calls, but cannot get oAuthApi.revokeToken to work . This is my code -

const newclient = client.withConfiguration({  
accessToken: 'Client '+process.env.SQUARE\_APPLICATION\_SECRET,  
});

const response = await newclient.oAuthApi.revokeToken({  
clientId: process.env.SQUARE\_APPLICATION\_ID,  
accessToken: square.access\_token, // token to be revoked  
revokeOnlyAccessToken: false,  
});

I get the following error -

“Argument for ‘authorization’ failed validation.\n\nExpected value to be of type ‘string’ but found ‘undefined’.\n\nGiven value: undefined\nType: ‘undefined’\nExpected type: ‘string’”

It works in API Explorer with identical values if I input Client + the application secret in the “Access token” field at the top of the page.

But using the same Client + application secret in the .withconfiguration function call in my code does not work.

I am using sandbox mode.

Please advise what I am doing wrong.

Thanks.

---

<div class="post-metadata">

**Author:** ![Bryan-Square](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/bryan-square/32/38_2.png) [@Bryan-Square](https://developer.squareup.com/forums/u/Bryan-Square)\
**Post date:** [March 29, 2024, 4:35pm UTC](https://developer.squareup.com/forums/t/revoke-oauth-token-with-node-js-sdk/14065/2 "2024-03-29T16:35:22Z")

</div>

Based on the error message you provided, it looks like the issue is with the ‘authorization’ parameter that is being passed to the oAuthApi.revokeToken function. The error message indicates that the expected value for ‘authorization’ should be a string, but it is receiving ‘undefined’.

In your code, you are setting the ‘accessToken’ in the configuration to 'Client '+process.env.SQUARE\_APPLICATION\_SECRET, which should be correct. However, it seems that the ‘authorization’ parameter is not being set correctly in the revokeToken function call.

One potential issue could be with the way you are setting the ‘accessToken’ parameter in the revokeToken function call. You are using square.access\_token, but it’s not clear where this value is coming from. If square.access\_token is undefined, that could be causing the issue.

To fix this, make sure that the value for square.access\_token is defined and is the correct token that you want to revoke. Alternatively, you can try passing the ‘accessToken’ directly as a string in the revokeToken function call, like this:

```auto
const response = await newclient.oAuthApi.revokeToken({
  clientId: process.env.SQUARE_APPLICATION_ID,
  accessToken: 'Client '+process.env.SQUARE_APPLICATION_SECRET, // token to be revoked
  revokeOnlyAccessToken: false,
});

```

If that still doesn’t work, double-check that your environment variables (SQUARE\_APPLICATION\_ID and SQUARE\_APPLICATION\_SECRET) are set correctly and are being accessed properly in your code. 🙂

---

<div class="post-metadata">

**Author:** ![akmicro](https://avatars.discourse-cdn.com/v4/letter/a/7cd45c/32.png) [@akmicro](https://developer.squareup.com/forums/u/akmicro)\
**Post date:** [March 30, 2024, 2:50am UTC](https://developer.squareup.com/forums/t/revoke-oauth-token-with-node-js-sdk/14065/3 "2024-03-30T02:50:20Z")

</div>

Thanks for the quick reply.

I have checked that all the parameters to the revokeToken call are correct by cut and pasting them into the API Explorer, where it subsequently revoked successfully.

I do not understand your suggestion to replace the accessToken in the revokeToken call with 'Client '+ application secret. Where do I then put the accessToken to be revoked?

However, after looking at the SDK source I tried the following which worked.

const newclient = client.withConfiguration({  
accessToken: 'Client '+process.env.SQUARE\_APPLICATION\_SECRET,  
});

const response = await newclient.oAuthApi.revokeToken({  
clientId: process.env.SQUARE\_APPLICATION\_ID,  
accessToken: square.access\_token, // token to be revoked  
revokeOnlyAccessToken: false,  
},  
'Client '+process.env.SQUARE\_APPLICATION\_SECRET // \<\<\<\<this is not documented!  
);

The authorization parameter referred to in the error is in fact a required second parameter for the revokeToken call. This is not mentioned in the API reference or shown in the API explorer.
