Reputation: 18
I'm trying to send a user deletion request to the Google Analytics userDeletionAPI in node.js. I'm using the node.js client: https://github.com/google/google-api-nodejs-client/
My code looks like this:
'use strict';
require('dotenv').config()
const {google} = require('googleapis')
const scopes = 'https://www.googleapis.com/auth/analytics.user.deletion'
const jwt = new google.auth.JWT(process.env.CLIENT_EMAIL, null, process.env.PRIVATE_KEY.replace(/\\n/g, '\n'), scopes)
const analytics = google.analytics({
version: 'v3',
auth: jwt
})
async function deleteUser() {
const res = await analytics.userDeletion.userDeletionRequest.upsert({
'kind': 'analytics#userDeletionRequest',
'id': {
'type': 'CLIENT_ID',
'userId': '555'
},
'webPropertyId': 'xxxxxxxxxx'
},
(err, result) => {
console.log(err, result)
}
)
}
deleteUser()
The error respose I get looks like this: "Error: Field id.type is required."
errors:
[ { domain: 'global',
reason: 'required',
message: 'Field id.type is required.' } ]
It might be some really silly problem but I can't figure out why it's saying that id.type required. How should I change the request to make it work?
Upvotes: 0
Views: 204
Reputation: 431
I don't know anything about the node.js client. But my guess is you need to wrap the request in requestBody. The values are send in the post body and not in the URL parameters. So something like this:
const res = await analytics.userDeletion.userDeletionRequest.upsert({
'requestBody': {
'kind': 'analytics#userDeletionRequest',
'id': {
'type': 'CLIENT_ID',
'userId': '555'
},
'webPropertyId': 'xxxxxxxxxx'
},
},
(err, result) => {
console.log(err, result)
}
)
I hope that works.
Upvotes: 1