Google Analytics API - bad request for Ecommerce activity - google-analytics

I am running the following for our GA reporting v4 API - it works fine without the Ecommerce portion but once I add "ecommerce", it gave me an error.
def get_client_report(analytics):
return analytics.userActivity().search(
body=
{
"viewId": VIEW_ID,
"user": {
"type": "CLIENT_ID",
"userId": "REDACTED"
},
"activityTypes": [
"ECOMMERCE"
],
"dateRange": {
"startDate": "2020-04-02",
"endDate": "2020-04-02"
},
"ecommerce": {
"transaction": {
"transactionId" : "REDACTED"
}
}
}
).execute()
and I get the following error:
https://analyticsreporting.googleapis.com/v4/userActivity:search?alt=json returned "Invalid JSON payload received. Unknown name "ecommerce": Cannot find field.". Details: "[{'#type': 'type.googleapis.com/google.rpc.BadRequest', 'fieldViolations': [{'description': 'Invalid JSON payload received. Unknown name "ecommerce": Cannot find field.'}]}]">
Can you help me what is wrong here? Thank you!

your request body doesn't match the expected format. Take a closer look at docs.
only activityTypes field is supported and you cannot filter for a specific transactions ID. you'll have to perform filtering on your side after receiving a response in that case.

Related

Google Calendar API Freebusy query returns "notFound" error

I'm trying to learn how to use this query; I created an API key and used Postman to
Post https://www.googleapis.com/calendar/v3/freeBusy?key="THE_API_KEY"
with this request body:
{
"timeMin": "2022-11-16T00:00:31-00:00",
"timeMax": "2022-11-16T14:00:00-00:00",
"groupExpansionMax": 100,
"calendarExpansionMax": 50,
"items": [
{
"id": "MY_OWN_GMAIL_ADDRESS"
},
{
"id": "OTHER_GMAIL_ADDRESS"
}
]
}
and got this response:
{
"kind": "calendar#freeBusy",
"timeMin": "2022-11-16T00:00:31.000Z",
"timeMax": "2022-11-16T14:00:00.000Z",
"calendars": {
"MY_OWN_GMAIL_ADDRESS": {
"errors": [
{
"domain": "global",
"reason": "notFound"
}
],
"busy": []
},
"OTHER_GMAIL_ADDRESS": {
"errors": [
{
"domain": "global",
"reason": "notFound"
}
],
"busy": []
}
}
}
What am I missing?
The Freebusy: query returns information about weither or not there is an event at the time of the request.
This method does not require authorization when being used against a public google calendar. There are a number of such calendars the holiday calendars are all public. You could also set your own calendar to public if you wish and then you would be able to use use an api key to access it.
API keys give you access to public methods only.
In order to access private user data. You need to be authorized using oauth2 with one of the following scopes.
If you do not have access to a calendar then it will return not found as you cant see it so your not going to be able to find it.
The solution i your case to fix your issue would be to either set the calendar to public and continue to use the api key. You will only be able to preform read actions against the calendar.
Or to switch to using oauth2 and send an authorization header with a bearer token.
Your post didnt include the Authorization header. Did you include it in your Postman Request?
Your need to send your Access Token as a Bearer Token in the Authorization Header
You can see an example for a request here:
https://developers.google.com/calendar/api/v3/reference/freebusy/query?apix=true#try-it

Graph API Create new Group and Team - 'Invalid bind property name members in request' issue in Graph Explorer

I am trying to create a new group and team via the Graph API. I am trying to run the POST a request in Graph Explorer (https://developer.microsoft.com/en-us/graph/graph-explorer) as below but get a bad request.
Request: POST
Version: v1.0
URL: https://graph.microsoft.com/v1.0/teams/groups
Request Body:
{
"displayName":"Flight 157",
"mailNickname":"flight157",
"description":"Everything about flight 157",
"visibility":"Private",
"groupTypes":["Unified"],
"mailEnabled":true,
"securityEnabled":false,
"members#odata.bind":[
"https://graph.microsoft.com/v1.0/users/957c07af-dcad-4b72-9306-1c4ee7d04e1f"
],
"owners#odata.bind":[
"https://graph.microsoft.com/v1.0/users/957c07af-dcad-4b72-9306-1c4ee7d04e1f"
]
}
I get the below response error:
{
"error": {
"code": "BadRequest",
"message": "Invalid bind property name members in request.",
"innerError": {
"request-id": "fee10382-5112-44f8-a8c9-683453bdf050",
"date": "2020-03-05T01:08:19"
}
}
}
I am not quite sure what I am doing wrong. Can anyone please help me with this?

Google Analytics Reporting API - Get Activity with User ID

I can't get User Activity from the Google Analytics Reporting API (v4) using a User ID.
Client ID (in a different, non-User ID view) works, however.
Am I missing something?
--
For Client ID
I go here in my Google Analytics web interface:
https://analytics.google.com/analytics/web/#/report/visitors-user-activity/a45743608w76484324p79062844/_u.date00=20190327&_u.date01=20190402&_r.userId=1142688158.1525244974
I get user activity details as expected:
--
I call the following:
POST https://analyticsreporting.googleapis.com/v4/userActivity:search?key={YOUR_API_KEY}
{
"viewId": "79062844",
"dateRange": {
"startDate": "2019-03-27",
"endDate": "2019-04-02"
},
"user": {
"type": "CLIENT_ID",
"userId": "1142688158.1525244974"
}
}
I get the expected response:
{
"sessions": [
…
],
"totalRows": 14,
"sampleRate": 1
}
--
For User ID
I go here in my Google Analytics web interface:
https://analytics.google.com/analytics/web/#/report/visitors-user-activity/a45743608w76484324p185098721/_u.date00=20190327&_u.date01=20190402&_r.userId=Not%20Logged%20In-
I get user activity details as expected:
--
I call the following:
POST https://analyticsreporting.googleapis.com/v4/userActivity:search?key={YOUR_API_KEY}
{
"viewId": "185098721",
"dateRange": {
"startDate": "2019-03-27",
"endDate": "2019-04-02"
},
"user": {
"type": "USER_ID",
"userId": "Not Logged In-"
}
}
I get an error instead:
{
"error": {
"code": 400,
"message": "USER_ID: Not Logged In- not found.",
"status": "INVALID_ARGUMENT"
}
}
--
I have tried different IDs, different dates, changing the type to CLIENT_ID, URL encoding the User ID, and User IDs with no spaces - no joy.
It seems this is indeed a bug which several others are also experiencing.
This bug can be +1'd and followed here:
https://issuetracker.google.com/issues/130161158
Edit: This has now been fixed.
From your URL, you are looking for an ID called Not%20Logged%20In- which is not a valid id. Its probably changing the id when you copy paste the URL.

Dialogflow simulator not responding

I am testing a simple conversation from my dialogflow simulator using a fulfillment hosted in firebase functions.
And I am receiving the fulfillment response when triggered
But my simulator is showing this. Saying no response is received.
Please help
The complete RAW fulfillment response
{
"responseId": "99b660de-e2ca-4d8c-ace5-ef724fe5ee72",
"queryResult": {
"queryText": "male",
"parameters": {
"gender": "male"
},
"allRequiredParamsPresent": true,
"webhookPayload": {
"google": {
"richResponse": {
"items": [
{
"simpleResponse": {
"textToSpeech": "Amazing"
}
}
]
},
"expectUserResponse": true,
"userStorage": "{\"data\":{}}"
}
},
"outputContexts": [
{
"name": "projects/assurance-purple/agent/sessions/bf891cbe-8642-eb61-ed7b-d6796adfab60/contexts/_actions_on_google",
"lifespanCount": 99,
"parameters": {
"data": "{}",
"gender.original": "male",
"gender": "male"
}
}
],
"intent": {
"name": "projects/assurance-purple/agent/intents/96b523a0-7a3a-4135-bdfc-d9d8ad16b661",
"displayName": "getGender"
},
"intentDetectionConfidence": 1,
"diagnosticInfo": {
"webhook_latency_ms": 45
},
"languageCode": "en"
},
"webhookStatus": {
"message": "Webhook execution successful"
}
}
My actions on google Testing debug tab
`
{
"response": "We're sorry, but something went wrong. Please try again.",
"expectUserResponse": false,
"conversationToken": "",
"audioResponse": "",
"visualResponse": {
"visualElementsList": [
{
"displayText": {
"content": "Sorry, this action is not available in simulation"
}
}
],
"suggestionsList": [],
"agentLogoUrl": ""
},
"clientError": 4,
"is3pResponse": false
}
`
You don't show the entire response (copying and pasting it as text in your question would have been better), but it looks like you're sending a response back for an Action, but trying to test it in Dialogflow's conversation tool.
The Actions on Google response is slightly different than the response that Dialogflow expects to handle the additional features that the Assistant supports. Because of this, you need to use the Actions on Google simulator when testing your agent.
The Dialogflow test is looking for some specific fields to show the response that are not included with the actions-on-google library, and it will not show anything that is in a Google RichResponse object.
To summarize:
If you are working with an Action, use the Actions on Google simulator.
If you are working with other Dialogflow integrations, you can use the test tool on the right in Dialogflow.
Update
The error you're indicating from the AoG Simulator suggests that you're trying to just issue a statement in the conversation and not starting the Action, or that the Action has quit. Make sure you're talking to the action by starting it with "talk to my test app" or whatever the name of your Action is.

How can I use googles "Interesting Calendars" with their v3 FreeBusy API?

When I attempt to use a calendar such as en.usa#holiday#group.v.calendar.google.com (Or anything with the ID ending in group.v.calendar.google.com) The FreeBusy API errors with:
"calendars": {
"en.usa#holiday#group.v.calendar.google.com": {
"errors": [
{
"domain": "global",
"reason": "notFound"
}
],
"busy": []
}
}
Making the same request but asking for another calendar succeeds.
The request I am making is reproducible in the Google API Docs at https://developers.google.com/calendar/v3/reference/freebusy/query
Where the request body is:
{
"timeMin": "2018-07-01T11:21:53.682-04:00",
"timeMax": "2018-08-25T11:21:53.682-04:00",
"items": [
{
"id": "en.usa#holiday#group.v.calendar.google.com"
}
],
"timeZone": "UTC"
}
I ruled out credentials being an issue; the same credentials work with this calendarId when it is used on the events API. This should also mean that the calendarId is valid.
The google account being used has this interesting calendar added to it. (Those events show up in the combined view)

Resources