0

I am building an integration between my Laravel application and Amazon Personalize using:

aws/aws-sdk-php 

Everything goes ok, but when I look on how to update the datasets with new Users, interactions and items, I couldn't find the right method/approach to do this, or if it is even possible.

I have created the Event Tracker but I can't find how to replicate this Python code into PHP:

    # Configure Properties:
    event = {
    "itemId": str(ITEM_ID),
    }
    event_json = json.dumps(event)
        
    # Make Call
    personalize_events.put_events(
    trackingId = TRACKING_ID,
    userId= USER_ID,
    sessionId = session_ID,
    eventList = [{
        'sentAt': int(time.time()),
        'eventType': 'EVENT_TYPE',
        'properties': event_json
        }] 

The code above is a portion extracted from here https://github.com/aws-samples/amazon-personalize-samples/blob/master/getting_started/notebooks/1.Building_Your_First_Campaign.ipynb

That would be for tracking new events: https://docs.aws.amazon.com/personalize/latest/dg/API_UBS_PutEvents.html

If there is a chance to avoid executing an extra Python script better, if not I will go for that option.

Thanks in advance!

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
lucianov88
  • 185
  • 3
  • 10

1 Answers1

0

I found that I need to use the PersonalizeEventsClient instead of PersonalizeClient for this purpose, as stated here:

https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-personalize-events-2018-03-22.html#putevents

The link is part of the AWS Personalize documentation, I missed that previously, there they explain how to PutEvents, Items and Users using the AWS SDK PHP, for example:

$client = AWS::createClient('personalizeevents');
$result = $client->putEvents([
    'eventList' => [ // REQUIRED
        [
            'eventId' => '<string>',
            'eventType' => '<string>', // REQUIRED
            'eventValue' => <float>,
            'impression' => ['<string>', ...],
            'itemId' => '<string>',
            'properties' => '<string>',
            'recommendationId' => '<string>',
            'sentAt' => <integer || string || DateTime>, // REQUIRED
        ],
        // ...
    ],
    'sessionId' => '<string>', // REQUIRED
    'trackingId' => '<string>', // REQUIRED
    'userId' => '<string>',
]);

I am also using this service provider for Laravel:

https://github.com/aws/aws-sdk-php-laravel

lucianov88
  • 185
  • 3
  • 10
  • A link to a solution is welcome, but please ensure your answer is useful without it: [add context around the link](//meta.stackexchange.com/a/8259) so your fellow users will have some idea what it is and why it’s there, then quote the most relevant part of the page you're linking to in case the target page is unavailable. [Answers that are little more than a link may be deleted.](/help/deleted-answers) – Sabito stands with Ukraine Jan 15 '21 at 07:51