Instantiation
The first step in using the SDK is setting up an authenticated instance.
We use an async function since we need to await the asynchronus authentication service response. Internally the login function will cache the returned the authentication token and use it for subsequent requests. As well as it will handle re-issuing a token when the one in use expires.
All API requests must be authenticated

User Level Authentication

The SDK has user level authentication meaning the actions allowed against the instance will depend on the role and privileges of the user account you authenticate with.
For example; If the user account you instantiate the SDK with has a role of contributor you will be able to create and update content items but will not be able to delete or publish content items.
When using the SDK we recommend these 2 things for authenticating.
    1.
    An account created specifically for using with the SDK
    2.
    The role of developer for the SDK user
1
async function authedSDK() {
2
try {
3
const auth = new SDK.Auth();
4
const session = await auth.login(
5
process.env.ZESTY_USER_EMAIL,
6
process.env.ZESTY_USER_PASSWORD
7
);
8
9
return new SDK(process.env.ZESTY_INSTANCE_ZUID, session.token);
10
} catch (err) {
11
console.error(err)
12
// Handle errors. e.g. send to logging service
13
// re throw error
14
throw err
15
}
16
}
17
const instance = await authedSDK()
Copied!
1
const auth = new SDK.Auth();
2
const sdk = auth.login(
3
process.env.ZESTY_USER_EMAIL,
4
process.env.ZESTY_USER_PASSWORD
5
).then(session => {
6
return new SDK(process.env.ZESTY_INSTANCE_ZUID, session.token);
7
}).catch(err => {
8
console.error(err)
9
// Handle errors. e.g. send to logging service
10
// re throw error
11
throw err
12
})
Copied!
Last modified 1yr ago