|
| 1 | +# Zeplin JavaScript SDK |
| 2 | +[](https://www.npmjs.com/package/@zeplin/sdk) |
| 3 | +[](https://www.npmjs.com/package/@zeplin/sdk) |
| 4 | + |
| 5 | +Official JavaScript interface to the [Zeplin API](https://docs.zeplin.dev). It works in both Node.js and web browser environments. |
| 6 | + |
| 7 | +## Installation |
| 8 | + |
| 9 | +``` |
| 10 | +npm install @zeplin/sdk |
| 11 | +``` |
| 12 | + |
| 13 | +or |
| 14 | + |
| 15 | +``` |
| 16 | +yarn add @zeplin/sdk |
| 17 | +``` |
| 18 | + |
| 19 | +## Getting started |
| 20 | + |
| 21 | +To get started with the SDK, you can create a personal access token from the web app under [Developer](https://app.zeplin.io/profile/developer) tab in your profile page. |
| 22 | + |
| 23 | +You can use this token to make API calls for your own Zeplin account. |
| 24 | + |
| 25 | +```js |
| 26 | +import { ZeplinApi, Configuration } "@zeplin/sdk"; |
| 27 | + |
| 28 | +const zeplinClient = new ZeplinApi(new Configuration({ accessToken: "ACCESS_TOKEN" })); |
| 29 | + |
| 30 | +const me = await zeplinClient.getCurrentUser(); |
| 31 | + |
| 32 | +``` |
| 33 | + |
| 34 | +### OAuth |
| 35 | +If you want to build an application for other Zeplin users, you can also create a Zeplin app the [profile page](https://app.zeplin.io/profile/developer). |
| 36 | + |
| 37 | + |
| 38 | +Check out this [example](./examples/oauth-app) to see how you can implement an OAuth flow using the SDK. |
| 39 | + |
| 40 | +## Usage |
| 41 | + |
| 42 | +The SDK exposes Zeplin API endpoints as methods. These methods are grouped into namespace objects by the type of object they interact with. |
| 43 | + |
| 44 | +For example: |
| 45 | +```js |
| 46 | +import { ZeplinApi, Configuration, ScreenNoteColorNameEnum } "@zeplin/sdk"; |
| 47 | + |
| 48 | +const zeplinClient = new ZeplinApi(new Configuration({ accessToken: "ACCESS_TOKEN" })); |
| 49 | + |
| 50 | +// Get colors in the styleguide |
| 51 | +zeplinClient.colors.getStyleguideColors("STYLEGUIDE_ID"); |
| 52 | + |
| 53 | +// Add a note on the screen |
| 54 | +zeplinClient.screens.createScreenNote("PROJECT_ID", "SCREEN_ID", { |
| 55 | + content: "Çaylar filiz! :turkish_tea:", |
| 56 | + position: { x: 0.1, y: 0.1 }, |
| 57 | + color: ScreenNoteColorNameEnum.DEEP_PURPLE |
| 58 | +}); |
| 59 | + |
| 60 | +// Invite a member to the workspace |
| 61 | +zeplinClient.organizations.inviteOrganizationMember("ORGANIZATION_ID", { |
| 62 | + handle: "rooolan", |
| 63 | + role: "editor" |
| 64 | +}); |
| 65 | +``` |
| 66 | + |
| 67 | +Check out the [API documentation](https://docs.zeplin.dev/reference) for complete list of endpoints and groups. |
| 68 | + |
| 69 | +## Examples |
| 70 | + |
| 71 | +- [Command-line app using personal access token](./examples/cli-with-personal-access-token) |
| 72 | +- [Simple OAuth application](./examples/oauth-app) |
| 73 | + |
| 74 | +## License |
| 75 | + |
| 76 | +The project is available as open source under the terms of the [MIT License](LICENSE). |
| 77 | + |
| 78 | +## Need help? |
| 79 | + |
| 80 | +Ping us at [email protected] for any feedback or questions. You can also find us in the [Zeplin Developer Slack ](https://zpl.io/zeplin-dev-slack) group! |
0 commit comments