I would like to export my all user events. Is there a way to retrieve all user events data with API ? I tried:
import_user_events but i get:
InvalidArgument: 400 Field "inputConfig" is a required field, but no value is found.
Solved! Go to Solution.
Hello @lsolatorio , I think my question was misunderstood. I would like to retrieve user events as csv, json or dataframe. And finally I was able to get the events using the recommendationengine API. Here is the code and reference page :
from google.cloud import recommendationengine_v1beta1
import proto
from google.oauth2 import service_account
import json
# Create a client
gbq_credentials = service_account.Credentials.from_service_account_file("credentials.json")
client = recommendationengine_v1beta1.UserEventServiceClient(credentials=gbq_credentials)
request = recommendationengine_v1beta1.ListUserEventsRequest(
parent="projects/your_project_id/locations/global/catalogs/default_catalog/eventStores/default_event_store",
)
# Make the request
page_result = client.list_user_events(request=request)
# Handle the response
events=[]
for i,response in enumerate(page_result):
print(i)
events.append(json.loads(proto.Message.to_json(response)))
Hello @world_of_data,
Thank you for sharing your reference link and the error message.
The missing "inputConfig" data refers to a series of user event information that the Retail API needs to know before initializing the import request, shown in this sample code.
# Initialize request argument(s)
input_config = retail_v2.UserEventInputConfig()
input_config.user_event_inline_source.user_events.event_type = "event_type_value"
input_config.user_event_inline_source.user_events.visitor_id = "visitor_id_value"
You can review this document to better understand the required information and their respective data types.
Listing a few more resources that can be helpful to you.
Once you have secured your user events data in a table, you can then query on it and save/ download the generated results.
Hello @lsolatorio , I think my question was misunderstood. I would like to retrieve user events as csv, json or dataframe. And finally I was able to get the events using the recommendationengine API. Here is the code and reference page :
from google.cloud import recommendationengine_v1beta1
import proto
from google.oauth2 import service_account
import json
# Create a client
gbq_credentials = service_account.Credentials.from_service_account_file("credentials.json")
client = recommendationengine_v1beta1.UserEventServiceClient(credentials=gbq_credentials)
request = recommendationengine_v1beta1.ListUserEventsRequest(
parent="projects/your_project_id/locations/global/catalogs/default_catalog/eventStores/default_event_store",
)
# Make the request
page_result = client.list_user_events(request=request)
# Handle the response
events=[]
for i,response in enumerate(page_result):
print(i)
events.append(json.loads(proto.Message.to_json(response)))
User | Count |
---|---|
2 | |
1 | |
1 | |
1 | |
1 |