googleapis / googleapis/google-api-nodejs-client
tagmanager receiving 404 when setting "type: 'jsm'"
- Dominant language
- TypeScript
- Stars
- 12.2k
- Forks
- 2k
- Avg merge
- 1d 9h
- Merged PRs (30d)
- 24
Description
I’m using a service account to access tagmanager API but getting 404 error for some functions.
After authorising the service account by using credentials.json file, I could access most of the tagmanager API v2 functions except for variable update for custom javascript(jsm) type variable.
The code returned 404 permission denied error. The same code works for other variable types, eg, DataLayer (v) variable (returns 200 code).
The service account has admin access at the GTM account level, and publish access at the container level. (The container itself was created by the same service account).
I have tried the same configuration via [API explorer](https://developers.google.com/tag-manager/api/v2/reference/accounts/containers/workspaces/variables/update), it uses OAth2 flow to auth my personal email address(has the same access level at account and container level as the service account) and returned 200. I then copied the Auth token generated by the API explorer page and forced the node module oauth2client.js to use this token on /node_modules/google-auth-library/build/src/auth/oauth2client.js:337.
from:
```
if (r.headers && r.headers.Authorization) {
opts.headers.Authorization = r.headers.Authorization;
}
```
to:
```
if (r.headers && r.headers.Authorization) {
opts.headers.Authorization =
}
```
After this, the custom javascript variable can be updated by my code. which means the issue is caused by the auth token generated for the service account.
Error log:
```
//node_modules/gaxios/build/src/gaxios.js:113
throw new common_1.GaxiosError(`Request failed with status code ${translatedResponse.status}`, opts, translatedResponse);
^
GaxiosError: Not found or permission denied.
at Gaxios._request (//node_modules/gaxios/build/src/gaxios.js:113:23)
at processTicksAndRejections (node:internal/process/task_queues:94:5)
at async JWT.requestAsync (//node_modules/google-auth-library/build/src/auth/oauth2client.js:344:18)
at async testVar (//test.js:220:22)
```
Auth function used in code
```
const auth = new google.auth.GoogleAuth({
scopes: ['https://www.googleapis.com/auth/tagmanager.publish','https://www.googleapis.com/auth/tagmanager.readonly']
});
const authClient = await auth.getClient();
const tagmanager = google.tagmanager({
version: 'v2',
auth: authClient
});
```
Contributor guide
Assessment
This issue has not been assessed yet.