:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
import { apiMutator } from '../../../../frontend/src/lib/api-orval-mutator'
/**
* Auto-generated from the Django backend OpenAPI schema.
* To modify these types, update the Django serializers or views, then run:
* hogli build:openapi
* Questions or issues? #team-devex on Slack
*
* PostHog API - generated
* OpenAPI spec version: 1.0.0
*/
import type {
AnnotationApi,
AnnotationsListParams,
ChangeFeedApi,
ChangeFeedListParams,
PaginatedAnnotationListApi,
PatchedAnnotationApi,
} from './api.schemas'
// https://stackoverflow.com/questions/49579094/typescript-conditional-types-filter-out-readonly-properties-pick-only-requir/49579497#49579497
type IfEquals<X, Y, A = X, B = never> = (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2 ? A : B
type WritableKeys<T> = {
[P in keyof T]-?: IfEquals<{ [Q in P]: T[P] }, { -readonly [Q in P]: T[P] }, P>
}[keyof T]
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never
type DistributeReadOnlyOverUnions<T> = T extends any ? NonReadonly<T> : never
type Writable<T> = Pick<T, WritableKeys<T>>
type NonReadonly<T> = [T] extends [UnionToIntersection<T>]
? {
[P in keyof Writable<T>]: T[P] extends object ? NonReadonly<NonNullable<T[P]>> : T[P]
}
: DistributeReadOnlyOverUnions<T>
export const getAnnotationsListUrl = (projectId: string, params?: AnnotationsListParams) => {
const normalizedParams = new URLSearchParams()
Object.entries(params || {}).forEach(([key, value]) => {
if (value !== undefined) {
normalizedParams.append(key, value === null ? 'null' : String(value))
}
})
const stringifiedParams = normalizedParams.toString()
return stringifiedParams.length > 0
? `/api/projects/${projectId}/annotations/?${stringifiedParams}`
: `/api/projects/${projectId}/annotations/`
}
/**
* Create, Read, Update and Delete annotations. [See docs](https://posthog.com/docs/data/annotations) for more information on annotations.
*/
export const annotationsList = async (
projectId: string,
params?: AnnotationsListParams,
options?: RequestInit
): Promise<PaginatedAnnotationListApi> => {
return apiMutator<PaginatedAnnotationListApi>(getAnnotationsListUrl(projectId, params), {
...options,
method: 'GET',
})
}
export const getAnnotationsCreateUrl = (projectId: string) => {
return `/api/projects/${projectId}/annotations/`
}
/**
* Create, Read, Update and Delete annotations. [See docs](https://posthog.com/docs/data/annotations) for more information on annotations.
*/
export const annotationsCreate = async (
projectId: string,
annotationApi?: NonReadonly<AnnotationApi>,
options?: RequestInit
): Promise<AnnotationApi> => {
return apiMutator<AnnotationApi>(getAnnotationsCreateUrl(projectId), {
...options,
method: 'POST',
headers: { 'Content-Type': 'application/json', ...options?.headers },
body: JSON.stringify(annotationApi),
})
}
export const getAnnotationsRetrieveUrl = (projectId: string, id: number) => {
return `/api/projects/${projectId}/annotations/${id}/`
}
/**
* Create, Read, Update and Delete annotations. [See docs](https://posthog.com/docs/data/annotations) for more information on annotations.
*/
export const annotationsRetrieve = async (
projectId: string,
id: number,
options?: RequestInit
): Promise<AnnotationApi> => {
return apiMutator<AnnotationApi>(getAnnotationsRetrieveUrl(projectId, id), {
...options,
method: 'GET',
})
}
export const getAnnotationsUpdateUrl = (projectId: string, id: number) => {
return `/api/projects/${projectId}/annotations/${id}/`
}
/**
* Create, Read, Update and Delete annotations. [See docs](https://posthog.com/docs/data/annotations) for more information on annotations.
*/
export const annotationsUpdate = async (
projectId: string,
id: number,
annotationApi?: NonReadonly<AnnotationApi>,
options?: RequestInit
): Promise<AnnotationApi> => {
return apiMutator<AnnotationApi>(getAnnotationsUpdateUrl(projectId, id), {
...options,
method: 'PUT',
headers: { 'Content-Type': 'application/json', ...options?.headers },
body: JSON.stringify(annotationApi),
})
}
export const getAnnotationsPartialUpdateUrl = (projectId: string, id: number) => {
return `/api/projects/${projectId}/annotations/${id}/`
}
/**
* Create, Read, Update and Delete annotations. [See docs](https://posthog.com/docs/data/annotations) for more information on annotations.
*/
export const annotationsPartialUpdate = async (
projectId: string,
id: number,
patchedAnnotationApi?: NonReadonly<PatchedAnnotationApi>,
options?: RequestInit
): Promise<AnnotationApi> => {
return apiMutator<AnnotationApi>(getAnnotationsPartialUpdateUrl(projectId, id), {
...options,
method: 'PATCH',
headers: { 'Content-Type': 'application/json', ...options?.headers },
body: JSON.stringify(patchedAnnotationApi),
})
}
export const getAnnotationsDestroyUrl = (projectId: string, id: number) => {
return `/api/projects/${projectId}/annotations/${id}/`
}
/**
* Hard delete of this model is not allowed. Use a patch API call to set "deleted" to true
*/
export const annotationsDestroy = async (projectId: string, id: number, options?: RequestInit): Promise<unknown> => {
return apiMutator<unknown>(getAnnotationsDestroyUrl(projectId, id), {
...options,
method: 'DELETE',
})
}
export const getChangeFeedListUrl = (projectId: string, params?: ChangeFeedListParams) => {
const normalizedParams = new URLSearchParams()
Object.entries(params || {}).forEach(([key, value]) => {
if (value !== undefined) {
normalizedParams.append(key, value === null ? 'null' : String(value))
}
})
const stringifiedParams = normalizedParams.toString()
return stringifiedParams.length > 0
? `/api/projects/${projectId}/change_feed/?${stringifiedParams}`
: `/api/projects/${projectId}/change_feed/`
}
/**
* Lists the changes that can affect production in a time window, newest first: feature flag and experiment edits, error tracking releases, and annotations. Use it to find what changed just before an error spike or a metric drop. Changes the user has no access to are left out.
* @summary List recent production changes
*/
export const changeFeedList = async (
projectId: string,
params?: ChangeFeedListParams,
options?: RequestInit
): Promise<ChangeFeedApi> => {
return apiMutator<ChangeFeedApi>(getChangeFeedListUrl(projectId, params), {
...options,
method: 'GET',
})
}