googleapis / googleapis/google-api-nodejs-client
tagmanager receiving 404 when setting "type: 'jsm'"
- Vorherrschende Sprache
- TypeScript
- Sterne
- 12.2k
- Forks
- 2k
- Ø Merge
- 1 T. 9 Std.
- Gemergte PRs (30 T.)
- 24
Beschreibung
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
});
```
Beitragsleitfaden
Rechercherichtung
Beginne mit der GoogleAuth-Konfiguration im Issue und dem Request-Pfad in google-auth-library/build/src/auth/oauth2client.js:337. Untersuche anschließend test.js:220 und reproduziere die Aktualisierung einer Tag Manager v2-Variable mit dem Service-Account-Token. Vergleiche diesen Request mit dem API-Explorer-Token-Fall; abgeschlossen ist die Aufgabe, wenn festgestellt wurde, ob der Client-Authentifizierungspfad den 404 verursacht, und das bestätigte Verhalten dokumentiert oder getestet wurde.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- nodejs, typescript
- Bereich
- api, authentication
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Muss geklärt werden
- Anfängerfreundlichkeit
- 25/100