Skip to content

Conversation

@markkasaboski
Copy link
Contributor

@markkasaboski markkasaboski commented Jan 21, 2025

…is a query param

New Retrieve Event

Screenshot 2025-01-21 at 11 08 52 AM

Old Retrieve Event

Screenshot 2025-01-21 at 11 08 37 AM

Changelog

Screenshot 2025-01-21 at 11 31 16 AM

@markkasaboski markkasaboski force-pushed the mark/new-activities-endpoint branch from 696fb80 to 9629357 Compare January 21, 2025 17:36
@aviau
Copy link
Member

aviau commented Jan 21, 2025

Given this is just a new "alias", I would suggest that we don't mark it as deprecated. Instead, I would only document the new endpoint and add a small note saying:

  • For backwards compatibility, this endpoint is also available as /old/endpoint

@aviau
Copy link
Member

aviau commented Jan 21, 2025

Can we create a new entry for january changes here?

@aviau
Copy link
Member

aviau commented Jan 21, 2025

Can we update the guides that used this endpoint to instead use the new one?

We will be able to update all the uid parsing logic. So, global search can now look like this:

#!/usr/bin/env python3

import datetime
import os
import time

from flareio import FlareApiClient


api_key: str | None = os.environ.get("FLARE_API_KEY")
if not api_key:
    raise Exception("Please provide an API key")

api_client = FlareApiClient(api_key=api_key)

from_timestamp: str = (
    datetime.datetime.now(tz=datetime.timezone.utc) - datetime.timedelta(hours=1)
).isoformat()

last_from: str | None = None
fetched_pages: int = 0

for resp in api_client.scroll(
    method="POST",
    url="/firework/v4/events/global/_search",
    json={
        "size": 10,
        "order": "asc",
        "from": None,
        "filters": {
            "type": ["chat_message"],
            "estimated_created_at": {"gte": from_timestamp},
        },
        "query": {
            "type": "query_string",
            "query_string": "hello",
        },
    },
):
    # Rate limiting.
    time.sleep(1)

    resp_data: dict = resp.json()
    items: list[dict] = resp_data["items"]

    fetched_pages += 1
    print(f"Fetched page {fetched_pages} with {len(items)} results...")

    # Save the last "next" value.
    last_from = resp_data.get("next") or last_from

    # (Optional): Get the full data
    for item in items:
        # Rate limiting.
        time.sleep(1)

        event_response = api_client.get(
            url="/firework/v2/activities/",
            params={
                "uid": item["metadata"]["uid"],
            },
        )

        full_data = event_response.json()
        print(f"Here is the full data of the event: {full_data}")

@aviau
Copy link
Member

aviau commented Jan 21, 2025

Please wait for my approval before merging this.

@markkasaboski markkasaboski force-pushed the mark/new-activities-endpoint branch 5 times, most recently from 86782ec to 7eaae52 Compare January 21, 2025 19:28
@markkasaboski markkasaboski force-pushed the mark/new-activities-endpoint branch from 7eaae52 to c96f0a7 Compare January 21, 2025 21:00
@markkasaboski markkasaboski force-pushed the mark/new-activities-endpoint branch from c96f0a7 to 39b2b33 Compare January 21, 2025 21:37
@aviau aviau merged commit f5af7be into main Jan 21, 2025
2 checks passed
@markkasaboski markkasaboski deleted the mark/new-activities-endpoint branch January 21, 2025 22:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants