Methods
Discover how to use this beautiful SDK. 🖥
CRUD
find
- Parameters
- contentType:
string - params?:
StrapiRequestParams
- contentType:
- Returns:
Promise<StrapiResponse<T>>
Retrieve a list of content type entries that match the query filters.
await strapi.find<Restaurant>('restaurants')Check out the Strapi documentation for more information.
findOne
- Parameters
- contentType:
string - documentId:
string - params?:
StrapiBaseRequestParams
- contentType:
- Returns:
Promise<StrapiResponse<T>>
Retrieve a specific content type entry by its documentId. You can enhance your query by adding filters to select the returning fields and populate relations.
await strapi.findOne<Restaurant>('restaurants', 'hgv1vny5cebq2l3czil1rpb3')create
- Parameters
- contentType:
string - data:
AxiosRequestConfig["data"] - params?:
StrapiBaseRequestParams
- contentType:
- Returns:
Promise<StrapiResponse<T>>
Create a content type entry and returns its value. You can apply query filters to choose the returning fields and populate relations.
await strapi.create<Restaurant>('restaurants', { name: 'The Fork' })update
- Parameters
- contentType:
string - documentId:
string - data:
AxiosRequestConfig["data"] - params?:
StrapiBaseRequestParams
- contentType:
- Returns:
Promise<StrapiResponse<T>>
Update a content type entry by its documentId, and receive the updated entry in return. You can apply query filters to specify the returning fields and populate relations.
await strapi.update<Restaurant>('restaurants', 1, { name: 'The Fork' })delete
- Parameters
- contentType:
string - documentId:
string
- contentType:
- Returns:
Promise<void>
Delete a content type entry by its documentId
await strapi.delete<Restaurant>('restaurants', 'hgv1vny5cebq2l3czil1rpb3')DELETE requests only send a 204 HTTP status on success and no longer return data in the response body.Authentication
register
- Parameters
- data:
StrapiRegistrationData
- data:
- Returns:
Promise<StrapiAuthenticationResponse>
Register a new User and set the associated Token.
const { user, jwt } = await strapi.register({ username: '', email: '', password: '' })Check out the Strapi documentation for more information.
login
- Parameters
- data:
StrapiAuthenticationData
- data:
- Returns:
Promise<StrapiAuthenticationResponse>
Authenticate a User and set the associated Token.
const { user, jwt } = await strapi.login({ identifier: '', password: '' })Check out the Strapi documentation for more information.
logout
It logs out the user by removing the authentication token from the chosen storage & axios header.
strapi.logout()changePassword
- Parameters
- data:
StrapiChangePasswordData
- data:
- Returns:
Promise<StrapiAuthenticationResponse>
Change the password for the currently logged-in user.
const { user, jwt } = await strapi.changePassword({ currentPassword: '', password: '', passwordConfirmation: '' })Check out the Strapi documentation for more information.
forgotPassword
- Parameters
- data:
StrapiForgotPasswordData
- data:
- Returns:
Promise<void>
Change the password for the currently logged-in user.
await strapi.forgotPassword({ email: '' })Check out the Strapi documentation for more information.
resetPassword
- Parameters
- data:
StrapiResetPasswordData
- data:
- Returns:
Promise<StrapiAuthenticationResponse>
Reset the user password and set the associated Token.
const { user, jwt } = await strapi.resetPassword({ code: '', password: '', passwordConfirmation: '' })Check out the Strapi documentation for more information.
sendEmailConfirmation
- Parameters
- Returns:
Promise<void>
Send an email to a user programmatically to confirm their account.
await strapi.sendEmailConfirmation({ email: '' })Check out the Strapi documentation for more information.
getProviderAuthenticationUrl
- Parameters
- provider:
StrapiAuthProvider
- provider:
- Returns:
string
Retrieve the correct authentication page URL for a given provider.
window.location = strapi.getAuthenticationProvider('provider')Check out the Strapi Provider list for more information.
authenticateProvider
- Parameters
- provider:
StrapiAuthProvider - access_token:
string
- provider:
- Returns:
Promise<StrapiAuthenticationResponse>
After authorization, the provider will redirect the user to your frontend with an access token in the URL. The access_token parameter is not necessary if it's already included in your URL redirection, but you can provide one if needed.
const { user, jwt } = await strapi.authenticateProvider('provider')Check out the Strapi documentation for more information.
fetchUser
- Returns:
Promise<StrapiUser>
Fetching user data is a common requirement. You can use this method to retrieve the current user from /users/me when a JWT is stored in your storage. It then sets the User.
const user = await strapi.fetchUser()getToken
- Returns:
string | null
Retrieve your JWT token from selected storage.
const token = strapi.getToken()setToken
- Parameters
- token:
string
- token:
- Returns:
void
Set your JWT token in axios headers as a Bearer token and store it in the selected storage.
const token = strapi.setToken('my_jwt_token')removeToken
- Returns:
void
Remove your JWT token from axios headers and the selected storage.
strapi.removeToken()