StrapiService
Upgather SDK / StrapiService
Class: StrapiService
Constructors
new StrapiService()
new StrapiService(
apiClient):StrapiService
Creates an instance of StrapiService.
Parameters
apiClient
The ApiClient instance used to perform HTTP requests.
Returns
Methods
type()
type<
K>(contentType):object
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
InputType<K>
The data for the new entry.
params?
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?
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' });
find()
find: (
params?) =>Promise<EntityType<K>[]>
Fetch the entries of this content type, filtered and sorted by the caller.
The service could address a single entry and could not address the collection, so every caller that wanted a filtered list dropped to the raw client and wrote the endpoint out by hand. That is how a route came to read one collection and write to another: the path was a string in each file rather than a name in one place.
Parameters
params?
Query parameters (filters, sort, pagination, populate).
Returns
Promise<EntityType<K>[]>
A promise resolving to the typed entities, or an empty list.
Example
await strapiService.type('TicketAllocation').find({
filters: { ticket_type: { documentId: { $eq: id } } },
sort: ['name:asc'],
});
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?
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>>
Update an entry, sending only what changed.
This was written believing Strapi v5 PUT is a full replace that nullifies any omitted field, and it read the record back, stripped the system fields and returned the whole document with the changes merged in. That belief is wrong, and the method was unsafe in the one way it was meant to protect against: the read it merged from does not populate relations or components, so anything it could have nullified was missing from the merge anyway.
Measured against a live Strapi v5 instance with a record carrying both a relation and a repeatable component: a PUT of the scalars alone left both intact. PUT is a partial update, so this now sends the changes and nothing else, which is the behaviour every caller already expected.
The name is kept because callers depend on it and the meaning has not changed: merge these fields onto what is stored.
Parameters
id
The documentId of the entry.
string | number
changes
InputType<K>
Partial data to merge onto the current record.
params?
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?
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
InputType<K>
The updated data for the entry.
params?
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
The endpoint is Strapi's own plural name, reproduced rather than guessed: see strapiEndpoint. Users are the one exception, returning arrays directly with no wrapper.
upload()
upload(
file,options):Promise<StrapiUploadedFile[]>
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',
});