Skip to main content

StrapiService

Upgather SDK


Upgather SDK / StrapiService

Class: StrapiService

Defined in: lib/services/StrapiService.ts:94

A service class for interacting with a Strapi API with proper response type handling.

Remarks

This class provides a dynamic, type-safe API for performing CRUD operations on Strapi content types. It uses auto-generated entity types that match actual API responses.

Constructors

new StrapiService()

new StrapiService(apiClient): StrapiService

Defined in: lib/services/StrapiService.ts:102

Creates an instance of StrapiService.

Parameters

apiClient

ApiClient

The ApiClient instance used to perform HTTP requests.

Returns

StrapiService

Methods

type()

type<K>(contentType): object

Defined in: lib/services/StrapiService.ts:173

Returns a service object for the specified Strapi content type with proper entity typing.

Type Parameters

K extends keyof StrapiContentMapping

A key from StrapiContentMapping corresponding to a content type.

Parameters

contentType

K

The friendly name of the content type (must exist in StrapiContentMapping).

Returns

object

An object with methods for performing CRUD operations on the specified content type.

create()

create: (data, params?) => Promise<EntityType<K>>

Create a new entry with proper entity typing.

Parameters
data

Partial<EntityType<K>>

The data for the new entry.

params?

StrapiQueryParams

Optional query parameters (e.g. locale).

Returns

Promise<EntityType<K>>

A promise resolving to the created entity.

Example
// Create a new app.
await strapiService.type('App').create({ integrationOrgId: '123', integrationType: 'eventbrite' }, { locale: 'en' });
delete()

delete: (id, params?) => Promise<EntityType<K>>

Delete an entry by its ID with proper entity typing.

Parameters
id

The ID of the entry.

string | number

params?

StrapiQueryParams

Optional query parameters (e.g. locale).

Returns

Promise<EntityType<K>>

A promise resolving to the deleted entity.

Example
// Delete an app.
await strapiService.type('App').delete(123, { locale: 'en' });
get()

get: (id, params?) => Promise<EntityType<K>>

Fetch a single entry by its ID with proper entity typing.

Parameters
id

The ID of the entry.

string | number

params?

StrapiQueryParams

Optional query parameters (e.g. populate, fields, locale, status, etc.).

Returns

Promise<EntityType<K>>

A promise resolving to a typed entity.

Example
// Retrieve a single app with id '123'
await strapiService.type('App').get(123, { populate: ['organization'] });
mergeUpdate()

mergeUpdate: (id, changes, params?) => Promise<EntityType<K>>

Safely update an entry using the GET-merge-PUT pattern.

Strapi v5 PUT is a full replace — any field not included in the body gets nullified. This method GETs the current published state, strips system fields, merges the provided changes, and PUTs the complete merged document back with ?status=published.

Parameters
id

The documentId of the entry.

string | number

changes

Partial<EntityType<K>>

Partial data to merge onto the current record.

params?

StrapiQueryParams

Optional query parameters for the PUT (defaults to { status: 'published' }).

Returns

Promise<EntityType<K>>

A promise resolving to the updated entity.

Example
await strapiService.type('Speaker').mergeUpdate('abc123', { title: 'New Title' });
query()

query: (params?) => Promise<EntityType<K>[]>

Query multiple entries using URL parameters with proper entity typing.

Parameters
params?

StrapiQueryParams

Optional query parameters.

Returns

Promise<EntityType<K>[]>

A promise resolving to an array of typed entities.

Example
// Query apps with filters and pagination.
await strapiService.type('App').query({ filters: { integrationType: { $eq: 'eventbrite' } }, pagination: { page: 1, pageSize: 10 } });
update()

update: (id, data, params?) => Promise<EntityType<K>>

Update an existing entry by its ID with proper entity typing.

Parameters
id

The ID of the entry.

string | number

data

Partial<EntityType<K>>

The updated data for the entry.

params?

StrapiQueryParams

Optional query parameters (e.g. locale).

Returns

Promise<EntityType<K>>

A promise resolving to the updated entity.

Example
// Update an app.
await strapiService.type('App').update(123, { isConnected: true }, { locale: 'en' });

Remarks

For simplicity, the endpoint is assumed to be the lowercased plural of the content type name. Special handling is provided for Users which return arrays directly (no wrapper).


upload()

upload(file, options): Promise<StrapiUploadedFile[]>

Defined in: lib/services/StrapiService.ts:122

Upload a file and attach it to a content type entry's media field.

Parameters

file

Blob

The file to upload (Blob or File).

options

Strapi upload options specifying which entry and field to attach to.

field

string

ref

string

refId

string

Returns

Promise<StrapiUploadedFile[]>

A promise resolving to the uploaded file metadata from Strapi.

Example

await strapiService.upload(logoFile, {
ref: 'api::sponsor.sponsor',
refId: 'abc123',
field: 'logo',
});