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. Strapi v4 introduces new query filters.
await strapi.find<Restaurant[]>('restaurants')
Check out the Strapi documentation for more information.
findOne
- Parameters
- contentType:
string
- id:
string|number
- params?:
StrapiBaseRequestParams
- contentType:
- Returns:
Promise<StrapiResponse<T>>
Retrieve a specific content type entry by its ID. You can enhance your query by adding filters to select the returning fields
and populate
relations.
await strapi.findOne<Restaurant>('restaurants', 1)
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
- id:
string|number
- data:
AxiosRequestConfig["data"]
- params?:
StrapiBaseRequestParams
- contentType:
- Returns:
Promise<StrapiResponse<T>>
Update a content type entry by its ID, 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
- id:
string|number
- params?:
StrapiBaseRequestParams
- contentType:
- Returns:
Promise<StrapiResponse<T>>
Delete a content type entry by its ID, and receive the deleted entry in return. You can apply query filters to define the returning fields
and populate
relations.
await strapi.delete<Restaurant>('restaurants', 1)
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
v2.3.0+Strapi v4.3.3+- 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.
setUser
- Parameters
- user:
StrapiUser
- user:
- Returns:
void
Set local data for the logged-in user.
strapi.setUser(user)
getter
and setter
for user
properties have been removed. Now, you can use strapi.user
to both set and get user data.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
v2.2.0+- Returns:
string | null
Retrieve your JWT token from selected storage.
const token = strapi.getToken()
setToken
v2.2.0+- 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
v2.2.0+- Returns:
void
Remove your JWT token from axios
headers and the selected storage.
strapi.removeToken()