Skip to content

Commit 61889fa

Browse files
vovavovavovavovagl-pix
authored andcommitted
Source PostHog: Use account information for checking the connection (#4692)
* this should fix the check if no records in annotations stream * update schemas for new SAT requirements && apply user hint upgrade on wrong api key * save schema upd * upd insights schema * upd insights schema2 * upd insights schema3 * upd insights schema4 * upd insights schema5 (null is joking) * upd insights schema6 (null is joking) * upd insights schema7 * upd insights schema8 * upd insights schema8 * bump version && docs
1 parent daf5fab commit 61889fa

File tree

12 files changed

+65
-51
lines changed

12 files changed

+65
-51
lines changed

airbyte-config/init/src/main/resources/config/STANDARD_SOURCE_DEFINITION/af6d50ee-dddf-4126-a8ee-7faee990774f.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
"sourceDefinitionId": "af6d50ee-dddf-4126-a8ee-7faee990774f",
33
"name": "PostHog",
44
"dockerRepository": "airbyte/source-posthog",
5-
"dockerImageTag": "0.1.1",
5+
"dockerImageTag": "0.1.2",
66
"documentationUrl": "https://docs.airbyte.io/integrations/sources/posthog"
77
}

airbyte-config/init/src/main/resources/seed/source_definitions.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
- sourceDefinitionId: af6d50ee-dddf-4126-a8ee-7faee990774f
5858
name: PostHog
5959
dockerRepository: airbyte/source-posthog
60-
dockerImageTag: 0.1.1
60+
dockerImageTag: 0.1.2
6161
documentationUrl: https://docs.airbyte.io/integrations/sources/posthog
6262
- sourceDefinitionId: cd42861b-01fc-4658-a8ab-5d11d0510f01
6363
name: Recurly

airbyte-integrations/connectors/source-posthog/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ RUN pip install .
1212
ENV AIRBYTE_ENTRYPOINT "python /airbyte/integration_code/main.py"
1313
ENTRYPOINT ["python", "/airbyte/integration_code/main.py"]
1414

15-
LABEL io.airbyte.version=0.1.1
15+
LABEL io.airbyte.version=0.1.2
1616
LABEL io.airbyte.name=airbyte/source-posthog

airbyte-integrations/connectors/source-posthog/integration_tests/configured_catalog.json

-3
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@
8282
"supported_sync_modes": ["full_refresh"],
8383
"source_defined_cursor": null,
8484
"default_cursor_field": null,
85-
"source_defined_primary_key": [["id"]],
8685
"namespace": null
8786
},
8887
"sync_mode": "full_refresh",
@@ -97,7 +96,6 @@
9796
"supported_sync_modes": ["full_refresh"],
9897
"source_defined_cursor": null,
9998
"default_cursor_field": null,
100-
"source_defined_primary_key": [["id"]],
10199
"namespace": null
102100
},
103101
"sync_mode": "full_refresh",
@@ -127,7 +125,6 @@
127125
"supported_sync_modes": ["full_refresh"],
128126
"source_defined_cursor": null,
129127
"default_cursor_field": null,
130-
"source_defined_primary_key": [["id"]],
131128
"namespace": null
132129
},
133130
"sync_mode": "full_refresh",

airbyte-integrations/connectors/source-posthog/source_posthog/schemas/annotations.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@
55
"type": "integer"
66
},
77
"content": {
8-
"type": "string"
8+
"type": ["string", "null"]
99
},
1010
"date_marker": {
11-
"type": "string",
11+
"type": ["string", "null"],
1212
"format": "date-time"
1313
},
1414
"creation_type": {
15-
"type": "string"
15+
"type": ["string", "null"]
1616
},
1717
"dashboard_item": {
18-
"type": "string"
18+
"type": ["string", "null"]
1919
},
2020
"created_by": {
2121
"type": "object",

airbyte-integrations/connectors/source-posthog/source_posthog/schemas/cohorts.json

+8-8
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@
88
"type": "string"
99
},
1010
"groups": {
11-
"type": "array",
11+
"type": ["array", "object"],
1212
"items": {
1313
"type": "object",
1414
"properties": {
1515
"days": {
16-
"type": "string"
16+
"type": ["string", "null"]
1717
},
1818
"action_id": {
19-
"type": "string"
19+
"type": ["string", "null"]
2020
},
2121
"properties": {
22-
"type": "array",
22+
"type": ["array"],
2323
"items": {
2424
"type": "object"
2525
}
@@ -46,19 +46,19 @@
4646
"type": "string"
4747
},
4848
"first_name": {
49-
"type": "string"
49+
"type": ["string", "null"]
5050
},
5151
"email": {
52-
"type": "string"
52+
"type": ["string", "null"]
5353
}
5454
}
5555
},
5656
"created_at": {
57-
"type": "string",
57+
"type": ["string", "null"],
5858
"format": "date-time"
5959
},
6060
"last_calculation": {
61-
"type": "string"
61+
"type": ["string", "null"]
6262
},
6363
"errors_calculating": {
6464
"type": "integer"

airbyte-integrations/connectors/source-posthog/source_posthog/schemas/events.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"type": "string"
99
},
1010
"event": {
11-
"type": "string"
11+
"type": ["string", "object"]
1212
},
1313
"timestamp": {
1414
"type": "string",
@@ -34,7 +34,7 @@
3434
"elements": {
3535
"type": "array",
3636
"items": {
37-
"type": "string"
37+
"type": ["string", "object"]
3838
}
3939
},
4040
"elements_chain": {

airbyte-integrations/connectors/source-posthog/source_posthog/schemas/feature_flags.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"type": "string"
1212
},
1313
"rollout_percentage": {
14-
"type": "integer"
14+
"type": ["integer", "null"]
1515
},
1616
"filters": {
1717
"type": "object",

airbyte-integrations/connectors/source-posthog/source_posthog/schemas/insights.json

+28-28
Original file line numberDiff line numberDiff line change
@@ -5,118 +5,118 @@
55
"type": "integer"
66
},
77
"name": {
8-
"type": "string"
8+
"type": ["string", "null"]
99
},
1010
"filters": {
11-
"type": "object",
11+
"type": ["object", "null"],
1212
"properties": {
1313
"events": {
1414
"type": "array",
1515
"items": {
1616
"type": "object",
1717
"properties": {
1818
"id": {
19-
"type": "string"
19+
"type": ["string", "null"]
2020
},
2121
"math": {
22-
"type": "string"
22+
"type": ["string", "null"]
2323
},
2424
"name": {
25-
"type": "string"
25+
"type": ["string", "null"]
2626
},
2727
"type": {
28-
"type": "string"
28+
"type": ["string", "null"]
2929
},
3030
"order": {
31-
"type": "integer"
31+
"type": ["integer", "null"]
3232
},
3333
"properties": {
3434
"type": "array",
3535
"items": {
36-
"type": "string"
36+
"type": ["string", "null", "object"]
3737
}
3838
},
3939
"math_property": {
40-
"type": "string"
40+
"type": ["string", "null"]
4141
}
4242
}
4343
}
4444
},
4545
"display": {
46-
"type": "string"
46+
"type": ["string", "null"]
4747
},
4848
"filters": {
4949
"type": "array",
5050
"items": {
51-
"type": "string"
51+
"type": ["string", "null"]
5252
}
5353
},
5454
"insight": {
55-
"type": "string"
55+
"type": ["string", "null"]
5656
},
5757
"session": {
58-
"type": "string"
58+
"type": ["string", "null"]
5959
},
6060
"interval": {
61-
"type": "string"
61+
"type": ["string", "integer"]
6262
},
6363
"pagination": {
64-
"type": "object"
64+
"type": ["object", "null"]
6565
}
6666
}
6767
},
6868
"filters_hash": {
69-
"type": "string"
69+
"type": ["string", "null"]
7070
},
7171
"order": {
72-
"type": "string"
72+
"type": ["string", "null", "object"]
7373
},
7474
"deleted": {
7575
"type": "boolean"
7676
},
7777
"dashboard": {
78-
"type": "string"
78+
"type": ["string", "integer", "null"]
7979
},
8080
"layouts": {
81-
"type": "object"
81+
"type": ["object", "null"]
8282
},
8383
"color": {
84-
"type": "string"
84+
"type": ["string", "null"]
8585
},
8686
"last_refresh": {
87-
"type": "string",
87+
"type": ["string", "null"],
8888
"format": "date-time"
8989
},
9090
"refreshing": {
9191
"type": "boolean"
9292
},
9393
"result": {
94-
"type": "string"
94+
"type": ["string", "null", "object"]
9595
},
9696
"created_at": {
97-
"type": "string",
97+
"type": ["string", "null"],
9898
"format": "date-time"
9999
},
100100
"saved": {
101101
"type": "boolean"
102102
},
103103
"created_by": {
104-
"type": "object",
104+
"type": ["object", "null"],
105105
"properties": {
106106
"id": {
107107
"type": "integer"
108108
},
109109
"uuid": {
110-
"type": "string"
110+
"type": ["string", "null"]
111111
},
112112
"distinct_id": {
113-
"type": "string"
113+
"type": ["string", "null"]
114114
},
115115
"first_name": {
116-
"type": "string"
116+
"type": ["string", "null"]
117117
},
118118
"email": {
119-
"type": "string"
119+
"type": ["string", "null"]
120120
}
121121
}
122122
}

airbyte-integrations/connectors/source-posthog/source_posthog/source.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
# SOFTWARE.
2323
#
2424

25-
2625
from typing import Any, List, Mapping, Tuple
2726

2827
import pendulum
28+
import requests
2929
from airbyte_cdk.logger import AirbyteLogger
3030
from airbyte_cdk.models import SyncMode
3131
from airbyte_cdk.sources import AbstractSource
@@ -41,6 +41,7 @@
4141
InsightsPath,
4242
InsightsSessions,
4343
Persons,
44+
PingMe,
4445
Trends,
4546
)
4647

@@ -50,11 +51,13 @@ def check_connection(self, logger: AirbyteLogger, config: Mapping[str, Any]) ->
5051
try:
5152
_ = pendulum.parse(config["start_date"], strict=True)
5253
authenticator = TokenAuthenticator(token=config["api_key"])
53-
stream = Cohorts(authenticator=authenticator)
54+
stream = PingMe(authenticator=authenticator)
5455
records = stream.read_records(sync_mode=SyncMode.full_refresh)
5556
_ = next(records)
5657
return True, None
5758
except Exception as e:
59+
if isinstance(e, requests.exceptions.HTTPError) and e.response.status_code == 401:
60+
return False, f"Please check you api_key. Error: {repr(e)}"
5861
return False, repr(e)
5962

6063
def streams(self, config: Mapping[str, Any]) -> List[Stream]:

airbyte-integrations/connectors/source-posthog/source_posthog/streams.py

+13
Original file line numberDiff line numberDiff line change
@@ -228,3 +228,16 @@ class Trends(PosthogStream):
228228

229229
def path(self, stream_slice: Mapping[str, Any] = None, **kwargs) -> str:
230230
return "insight/trend"
231+
232+
233+
class PingMe(PosthogStream):
234+
"""
235+
Docs: https://posthog.com/docs/api/user
236+
"""
237+
238+
def path(self, stream_slice: Mapping[str, Any] = None, **kwargs) -> str:
239+
return "users/@me"
240+
241+
def parse_response(self, response: requests.Response, stream_state: Mapping[str, Any], **kwargs) -> Iterable[Mapping]:
242+
response_json = response.json()
243+
yield response_json

docs/integrations/sources/posthog.md

+1
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,6 @@ Please follow these [steps](https://posthog.com/docs/api/overview#how-to-obtain-
5656

5757
| Version | Date | Pull Request | Subject |
5858
| :------ | :-------- | :----- | :------ |
59+
| 0.1.2 | 2021-07-15 | [4692](https://github.com/airbytehq/airbyte/pull/4692) | Source PostHog: Use account information for checking the connection
5960
| 0.1.1 | 2021-07-05 | [4539](https://github.com/airbytehq/airbyte/pull/4539) | Add `AIRBYTE_ENTRYPOINT` env variable for kubernetes support|
6061
| 0.1.0 | 2021-06-08 | [3768](https://github.com/airbytehq/airbyte/pull/3768) | Initial Release |

0 commit comments

Comments
 (0)