├── docs ├── .vuepress │ ├── public │ │ ├── robots.txt │ │ ├── favicon.ico │ │ ├── cosmicjs-logo.png │ │ ├── icons │ │ │ ├── webhooks.png │ │ │ ├── npm.svg │ │ │ ├── npm-black.svg │ │ │ ├── terminal.svg │ │ │ ├── graphql.svg │ │ │ ├── puzzle-piece.svg │ │ │ ├── graphql-black.svg │ │ │ ├── function-black.svg │ │ │ └── function.svg │ │ └── cosmicjs.svg │ ├── theme │ │ ├── styles │ │ │ ├── palette.styl │ │ │ ├── toc.styl │ │ │ ├── wrapper.styl │ │ │ ├── home.styl │ │ │ ├── config.styl │ │ │ ├── arrow.styl │ │ │ ├── custom-blocks.styl │ │ │ ├── mobile.styl │ │ │ ├── code.styl │ │ │ └── index.styl │ │ ├── layouts │ │ │ ├── 404.vue │ │ │ └── Layout.vue │ │ ├── components │ │ │ ├── DropdownTransition.vue │ │ │ ├── SidebarButton.vue │ │ │ ├── NavLink.vue │ │ │ ├── Sidebar.vue │ │ │ ├── SidebarLinks.vue │ │ │ ├── SidebarGroup.vue │ │ │ ├── SidebarLink.vue │ │ │ ├── Home.vue │ │ │ ├── Navbar.vue │ │ │ ├── NavLinks.vue │ │ │ ├── AlgoliaSearchBox.vue │ │ │ ├── DropdownLink.vue │ │ │ └── Page.vue │ │ ├── global-components │ │ │ ├── Badge.vue │ │ │ └── HomeCard.vue │ │ ├── index.js │ │ └── util │ │ │ └── index.js │ └── config.js ├── rest-api │ ├── request-limits.md │ ├── errors.md │ ├── README.md │ ├── authentication.md │ ├── webhooks.md │ ├── users.md │ ├── object-types.md │ ├── media.md │ ├── buckets.md │ └── extensions.md ├── graphql-api │ ├── request-limits.md │ ├── README.md │ ├── methods-overview.md │ ├── examples.md │ └── queries.md ├── README.md ├── webhooks │ └── README.md ├── extensions │ └── README.md ├── functions │ └── README.md └── cli │ └── README.md ├── .gitignore ├── package.json └── README.md /docs/.vuepress/public/robots.txt: -------------------------------------------------------------------------------- 1 | User-agent: * 2 | Disallow: / -------------------------------------------------------------------------------- /docs/.vuepress/theme/styles/palette.styl: -------------------------------------------------------------------------------- 1 | $nprogressColor = #29ABE2 -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | .vuepress/dist 4 | docs/.vuepress/dist -------------------------------------------------------------------------------- /docs/.vuepress/theme/styles/toc.styl: -------------------------------------------------------------------------------- 1 | .table-of-contents 2 | .badge 3 | vertical-align middle 4 | -------------------------------------------------------------------------------- /docs/.vuepress/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cosmicjs/docs/master/docs/.vuepress/public/favicon.ico -------------------------------------------------------------------------------- /docs/.vuepress/public/cosmicjs-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cosmicjs/docs/master/docs/.vuepress/public/cosmicjs-logo.png -------------------------------------------------------------------------------- /docs/.vuepress/public/icons/webhooks.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cosmicjs/docs/master/docs/.vuepress/public/icons/webhooks.png -------------------------------------------------------------------------------- /docs/.vuepress/theme/styles/wrapper.styl: -------------------------------------------------------------------------------- 1 | $wrapper 2 | max-width $contentWidth 3 | margin 0 auto 4 | padding 2rem 2.5rem 5 | @media (max-width: $MQNarrow) 6 | padding 2rem 7 | @media (max-width: $MQMobileNarrow) 8 | padding 1.5rem 9 | 10 | -------------------------------------------------------------------------------- /docs/.vuepress/public/icons/npm.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /docs/.vuepress/public/icons/npm-black.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /docs/.vuepress/theme/styles/home.styl: -------------------------------------------------------------------------------- 1 | .docs-home-page .content, 2 | .docs-home-page .page-edit, 3 | .docs-home-page .page-nav { 4 | max-width: 960px; 5 | } 6 | 7 | @media (min-width: ($MQMobile + 1px)) { 8 | .home-card-list { 9 | margin-top: 30px; 10 | display: flex; 11 | flex-wrap: wrap; 12 | } 13 | } -------------------------------------------------------------------------------- /docs/.vuepress/theme/styles/config.styl: -------------------------------------------------------------------------------- 1 | // colors 2 | $accentColor = #0085a4 3 | $textColor = #2c3e50 4 | $borderColor = #eaecef 5 | $codeBgColor = #282c34 6 | $arrowBgColor = #ccc 7 | 8 | // layout 9 | $navbarHeight = 3.6rem 10 | $sidebarWidth = 20rem 11 | $contentWidth = 740px 12 | 13 | // responsive breakpoints 14 | $MQNarrow = 959px 15 | $MQMobile = 719px 16 | $MQMobileNarrow = 419px 17 | 18 | // code 19 | $lineNumbersWrapperWidth = 3.5rem 20 | $codeLang = js ts html md vue css sass scss less stylus go java c sh yaml py docker dockerfile makefile 21 | -------------------------------------------------------------------------------- /docs/.vuepress/theme/layouts/404.vue: -------------------------------------------------------------------------------- 1 | 10 | 11 | 27 | -------------------------------------------------------------------------------- /docs/.vuepress/theme/styles/arrow.styl: -------------------------------------------------------------------------------- 1 | @require './config' 2 | 3 | .arrow 4 | display inline-block 5 | width 0 6 | height 0 7 | &.up 8 | border-left 4px solid transparent 9 | border-right 4px solid transparent 10 | border-bottom 6px solid $arrowBgColor 11 | &.down 12 | border-left 4px solid transparent 13 | border-right 4px solid transparent 14 | border-top 6px solid $arrowBgColor 15 | &.right 16 | border-top 4px solid transparent 17 | border-bottom 4px solid transparent 18 | border-left 6px solid $arrowBgColor 19 | &.left 20 | border-top 4px solid transparent 21 | border-bottom 4px solid transparent 22 | border-right 6px solid $arrowBgColor 23 | -------------------------------------------------------------------------------- /docs/.vuepress/theme/components/DropdownTransition.vue: -------------------------------------------------------------------------------- 1 | 11 | 12 | 28 | 29 | 34 | -------------------------------------------------------------------------------- /docs/rest-api/request-limits.md: -------------------------------------------------------------------------------- 1 | # Request Limits 2 | ### Rate Limits 3 | All Cosmic Buckets have a rate limit of `500` API requests per second per IP address. This only applies to non-cached API requests. Non-cached API requests include any initial `GET` request, all `POST`, `PUT`, `PATCH`, and `DELETE` requests to the API. This does not apply to any files or images served via the Cosmic CDN or imgix CDN. 4 | 5 | ### Size Limits 6 | Except for the upload media endpoint, which allows up to `900MB` files to be uploaded, all Cosmic request and response payloads have a size limit of `6MB`. 7 | 8 | ### Optimizations 9 | All requests allow `gzip` ecoding. If connecting to the API directly, adding `Accept-Encoding: gzip` can dramatically reduce response time and size. This is added by default on all Cosmic open source clients. -------------------------------------------------------------------------------- /docs/graphql-api/request-limits.md: -------------------------------------------------------------------------------- 1 | # Request Limits 2 | ### Rate Limits 3 | All Cosmic Buckets have a rate limit of `500` API requests per second per IP address. This only applies to non-cached API requests. Non-cached API requests include any initial `GET` request, all `POST`, `PUT`, `PATCH`, and `DELETE` requests to the API. This does not apply to any files or images served via the Cosmic CDN or imgix CDN. 4 | 5 | ### Size Limits 6 | Except for the upload media endpoint, which allows up to `900MB` files to be uploaded, all Cosmic request and response payloads have a size limit of `6MB`. 7 | 8 | ### Optimizations 9 | All requests allow `gzip` ecoding. If connecting to the API directly, adding `Accept-Encoding: gzip` can dramatically reduce response time and size. This is added by default on all Cosmic open source clients. -------------------------------------------------------------------------------- /docs/.vuepress/theme/styles/custom-blocks.styl: -------------------------------------------------------------------------------- 1 | .custom-block 2 | .custom-block-title 3 | font-weight 600 4 | margin-bottom -0.4rem 5 | &.tip, &.warning, &.danger 6 | padding .1rem 1.5rem 7 | border-left-width .5rem 8 | border-left-style solid 9 | margin 1rem 0 10 | &.tip 11 | background-color #f3f5f7 12 | border-color #42b983 13 | &.warning 14 | background-color rgba(255,229,100,.3) 15 | border-color darken(#ffe564, 35%) 16 | color darken(#ffe564, 70%) 17 | .custom-block-title 18 | color darken(#ffe564, 50%) 19 | a 20 | color $textColor 21 | &.danger 22 | background-color #ffe6e6 23 | border-color darken(red, 20%) 24 | color darken(red, 70%) 25 | .custom-block-title 26 | color darken(red, 40%) 27 | a 28 | color $textColor 29 | 30 | 31 | -------------------------------------------------------------------------------- /docs/.vuepress/theme/styles/mobile.styl: -------------------------------------------------------------------------------- 1 | @require './config' 2 | 3 | $mobileSidebarWidth = $sidebarWidth * 0.82 4 | 5 | // narrow desktop / iPad 6 | @media (max-width: $MQNarrow) 7 | .sidebar 8 | font-size 15px 9 | width $mobileSidebarWidth 10 | .page 11 | padding-left $mobileSidebarWidth 12 | 13 | // wide mobile 14 | @media (max-width: $MQMobile) 15 | .sidebar 16 | top 110px 17 | padding-top $navbarHeight 18 | transform translateX(-100%) 19 | transition transform .2s ease 20 | .page 21 | padding-left 0 22 | .theme-container 23 | &.sidebar-open 24 | .sidebar 25 | transform translateX(0) 26 | &.no-navbar 27 | .sidebar 28 | padding-top: 0 29 | 30 | // narrow mobile 31 | @media (max-width: $MQMobileNarrow) 32 | h1 33 | font-size 1.9rem 34 | .content 35 | div[class*="language-"] 36 | margin 0.85rem -1.5rem 37 | border-radius 0 38 | -------------------------------------------------------------------------------- /docs/.vuepress/theme/global-components/Badge.vue: -------------------------------------------------------------------------------- 1 | 25 | 26 | 45 | -------------------------------------------------------------------------------- /docs/rest-api/errors.md: -------------------------------------------------------------------------------- 1 | # Errors 2 | 3 | The Cosmic API uses the following error codes: 4 | 5 | | Error Code | Meaning | 6 | | ------------------ | -------------------------------------------------------------------- | 7 | | 200 | OK - Everything worked as expected. | 8 | | 400 | Bad Request - Your request is invalid. | 9 | | 401 | Unauthorized - Your access key is incorrect. | 10 | | 402 | Payment Required - Your Bucket needs to be upgraded to continue use. | 11 | | 403 | Forbidden - You are not allowed to access this content. | 12 | | 404 | Not Found - The requested resource doesn't exist. | 13 | | 429 | Too Many Requests - Too many requests hit the API too quickly. | 14 | | 500, 502, 503, 504 | Internal Server Error - Something went wrong on our end. | -------------------------------------------------------------------------------- /docs/.vuepress/theme/components/SidebarButton.vue: -------------------------------------------------------------------------------- 1 | 8 | 9 | 28 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cosmicjs-docs", 3 | "version": "0.1.0-alpha", 4 | "description": "Cosmic documentation site", 5 | "main": "index.js", 6 | "scripts": { 7 | "dev": "vuepress dev docs", 8 | "build": "vuepress build docs", 9 | "test": "echo \"Error: no test specified\" && exit 1" 10 | }, 11 | "repository": { 12 | "type": "git", 13 | "url": "git+https://github.com/cosmicjs/docs.git" 14 | }, 15 | "keywords": [ 16 | "documentation", 17 | "cosmicjs" 18 | ], 19 | "author": "Ben Hong ", 20 | "license": "ISC", 21 | "bugs": { 22 | "url": "https://github.com/cosmicjs/docs/issues" 23 | }, 24 | "homepage": "https://github.com/cosmicjs/docs#readme", 25 | "devDependencies": { 26 | "@vuepress/plugin-google-analytics": "^1.0.0-alpha.47", 27 | "vuepress": "^1.0.0-alpha.47" 28 | }, 29 | "dependencies": { 30 | "vue-tabs-component": "^1.5.0", 31 | "vuepress-intercom": "^1.0.3", 32 | "vuepress-plugin-tabs": "^0.2.2" 33 | }, 34 | "engines": { 35 | "node": ">=8.0.0 <9.0.0" 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /docs/.vuepress/theme/components/NavLink.vue: -------------------------------------------------------------------------------- 1 | 19 | 20 | 50 | -------------------------------------------------------------------------------- /docs/.vuepress/public/icons/terminal.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | terminal 5 | Created with Sketch. 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /docs/.vuepress/theme/index.js: -------------------------------------------------------------------------------- 1 | const path = require('path') 2 | 3 | // Theme API. 4 | module.exports = (options, ctx) => ({ 5 | alias () { 6 | const { themeConfig, siteConfig } = ctx 7 | // resolve algolia 8 | const isAlgoliaSearch = ( 9 | themeConfig.algolia 10 | || Object.keys(siteConfig.locales && themeConfig.locales || {}) 11 | .some(base => themeConfig.locales[base].algolia) 12 | ) 13 | return { 14 | '@AlgoliaSearchBox': isAlgoliaSearch 15 | ? path.resolve(__dirname, 'components/AlgoliaSearchBox.vue') 16 | : path.resolve(__dirname, 'noopModule.js') 17 | } 18 | }, 19 | 20 | plugins: [ 21 | ['@vuepress/active-header-links', options.activeHeaderLinks], 22 | '@vuepress/search', 23 | '@vuepress/plugin-nprogress', 24 | ['container', { 25 | type: 'tip', 26 | defaultTitle: { 27 | '/zh/': '提示' 28 | } 29 | }], 30 | ['container', { 31 | type: 'warning', 32 | defaultTitle: { 33 | '/zh/': '注意' 34 | } 35 | }], 36 | ['container', { 37 | type: 'danger', 38 | defaultTitle: { 39 | '/zh/': '警告' 40 | } 41 | }] 42 | ] 43 | }) 44 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## DEPRECATED 2 | This the the repo for the OLD docs (v1). Go to the repo for the latest docs [here](https://github.com/cosmicjs/cosmic-docs). 3 | 4 |

5 | Cosmic 6 |

7 |

8 | 📖 View Docs 9 |

10 | 11 | ## Local Setup 12 | 13 | To setup the local environment: 14 | 15 | ### Prerequisites 16 | 17 | - [Node.js v8+](https://nodejs.org/en/) 18 | - [yarn](https://yarnpkg.com/en/) (Optional, but recommended) 19 | 20 | ### Development 21 | 22 | This will create a local web server at `http://localhost:8080/` if nothing is running on that port. It has hot module reloading and will detect most changes you make.* 23 | 24 | ``` 25 | $ yarn run dev 26 | ``` 27 | 28 | \* Note: It is not always reliable when making low level configurations or changing the underlying architecture of VuePress, but this should not impact most users who are focused on content and UI level changes. 29 | 30 | ### Build 31 | 32 | This will compile the package you want for deploying to production. It will create a folder in `docs/.vuepress/dist`. 33 | 34 | ``` 35 | $ yarn build 36 | ``` 37 | -------------------------------------------------------------------------------- /docs/.vuepress/public/icons/graphql.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /docs/.vuepress/public/icons/puzzle-piece.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | puzzle-piece 5 | Created with Sketch. 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /docs/.vuepress/theme/components/Sidebar.vue: -------------------------------------------------------------------------------- 1 | 9 | 10 | 22 | 23 | 61 | -------------------------------------------------------------------------------- /docs/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | pageClass: docs-home-page 3 | cardData: 4 | - title: 'REST API' 5 | url: '/rest-api/' 6 | description: 'Integrate your content using the Cosmic NPM module or directly to the REST API.' 7 | icon: '/icons/npm.svg' 8 | - title: 'GraphQL API' 9 | url: '/graphql-api/' 10 | description: "Use the GraphQL API to get only the data you need and nothing you don't." 11 | icon: '/icons/graphql.svg' 12 | - title: 'Guides' 13 | url: '/guides/' 14 | description: "Use our quick start guides to get started using Cosmic with different development tools." 15 | icon: 'https://cdn.cosmicjs.com/4d1e8850-33e7-11ea-983a-099bce0aacb8-067-book-2.svg' 16 | - title: 'Webhooks' 17 | url: '/webhooks/' 18 | description: "Make external requests when events occur in your Bucket." 19 | icon: 'https://cdn.cosmicjs.com/0d611e50-c832-11ea-b44f-f5c7da208e23-007-anchor.svg' 20 | - title: 'Extensions' 21 | url: '/extensions/' 22 | description: "Connect to third-party APIs and create custom views within your Bucket." 23 | icon: 'https://cdn.cosmicjs.com/6174d730-898e-11ea-9edc-335682595c41-cubes.svg' 24 | - title: 'CLI' 25 | url: '/cli/' 26 | description: 'Use the power of Cosmic from the comfort of your command-line tool.' 27 | icon: 'https://cdn.cosmicjs.com/505c07b0-c832-11ea-b44f-f5c7da208e23-039-web-programming.svg' 28 | - title: 'Functions' 29 | url: '/functions/' 30 | description: 'Deploy code without having to manage server infrastructure.' 31 | icon: '/icons/function.svg' 32 | --- 33 | 34 | # Documentation 35 | 36 | Welcome to Cosmic! Learn how to use the entire Cosmic toolkit and explore features. 37 | 38 |
39 | 47 | 48 |
-------------------------------------------------------------------------------- /docs/rest-api/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | sidebarDepth: 1 3 | --- 4 | 5 | # Cosmic REST API 6 | 7 | The Cosmic REST API and available clients help you manage content for your websites and applications. We support cross-origin resource sharing, allowing you to interact securely with our API from a client-side web application (though you should never expose your private keys or credentials in any public website's client-side code). JSON is returned by all API responses, including errors. 8 | 9 | The API is fully CRUD capable, allowing you to perform Create, Read, Update, and Delete requests to your Cosmic Buckets. 10 | 11 | ::: tip Quick Tip 12 | For a quick reference to get content from your Bucket, click the "Developer Tools" button found on select pages in your [Bucket Dashboard ](https://app.cosmicjs.com/login). 13 | 14 | 15 | ::: 16 | 17 | ## Getting Started 18 | 19 | [Create a Cosmic account](https://app.cosmicjs.com/signup) and get familiar with the Cosmic Dashboard. 20 | 21 | ## API Endpoint 22 | You can make direct calls to the REST API from the following base URL. Current version is `v1`. 23 | ``` 24 | https://api.cosmicjs.com/v1 25 | ``` 26 | 27 | ## Status Check 28 | You can check on the API system status via the [Cosmic status page](https://cosmicjs.statuspage.io/) and via the following endpoint: 29 | ``` 30 | https://api.cosmicjs.com/status 31 | ``` 32 | 33 | ## Node.js Installation 34 | Install the [Cosmic NPM Module](https://www.npmjs.com/package/cosmicjs) to follow examples using Node.js 35 | ```bash 36 | npm i cosmicjs 37 | ``` 38 | 39 | ### Terms 40 | 41 | These docs assume you understand the core concepts of Cosmic including Buckets, Object Types and Objects. For a brief overview of these terms, see the [Getting Started guide](https://cosmicjs.com/getting-started). 42 | -------------------------------------------------------------------------------- /docs/.vuepress/theme/components/SidebarLinks.vue: -------------------------------------------------------------------------------- 1 | 23 | 24 | 87 | -------------------------------------------------------------------------------- /docs/.vuepress/public/cosmicjs.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 8 | 9 | 10 | 12 | 14 | 16 | 18 | 20 | 22 | 23 | 24 | 26 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /docs/graphql-api/README.md: -------------------------------------------------------------------------------- 1 | # Cosmic GraphQL API 2 | 3 | Welcome to the Cosmic GraphQL documentation. Learn about all of the features and methods to perform `queries` and `mutations`. 4 | 5 | ::: tip Quick Tip 6 | For a quick reference to get content from your Bucket, click the "Developer Tools" button found on select pages in your [Bucket Dashboard ](https://app.cosmicjs.com/login). 7 | 8 | 9 | ::: 10 | 11 | ## API Endpoint 12 | 13 | All `queries` and `mutations` are called to the Cosmic GraphQL endpoint: 14 | 15 | ``` 16 | https://graphql.cosmicjs.com/v2 17 | ``` 18 | 19 | ## Status Check 20 | You can check on the API system status via the [Cosmic status page](https://cosmicjs.statuspage.io/). 21 | 22 | ## Playground 23 | Use the playground for a full interactive demonstration. Use the "Docs" and "Schema" buttons on the right side for documentation on models, queries, inputs, and descriptions. 24 | 25 | **[Full screen  ](https://cosmic-graphql-playground.netlify.com/?endpoint=https%3A%2F%2Fgraphql.cosmicjs.com%2Fv2&query=%7B%0A%20%20getObjects%28%0A%20%20%20%20bucket_slug%3A%20%22simple-react-blog%22%2C%0A%20%20%20%20input%3A%20%7B%20%0A%20%20%20%20%20%20type%3A%20%22posts%22%0A%20%20%20%20%7D%0A%20%20%29%20%7B%0A%20%20%20%20%20objects%20%7B%0A%20%20%20%20%20%20title%0A%20%20%20%20%20%20content%0A%20%20%20%20%7D%0A%20%20%20%20total%0A%20%20%7D%0A%7D)** 26 | 27 | 28 | ## Changelog 29 | ### v2 30 | New Queries: 31 | - `getObjectRevisions`: gets Object Revisions 32 | - `addObjectRevision`: adds an Object Revision 33 | 34 | New query format: 35 | - `getObjects` requires a new query format. Now includes params `limit`, `total`, and `skip`. 36 | - `getMedia` requires a new query format. Now includes params `limit`, `total`, and `skip`. 37 | 38 | Search and Filter Options: 39 | - The `getObjects` method now allows you to search and filter by metadata. 40 | 41 | [View previous version docs here](/graphql-api/previous-versions#v1). -------------------------------------------------------------------------------- /docs/.vuepress/theme/global-components/HomeCard.vue: -------------------------------------------------------------------------------- 1 | 24 | 25 | 39 | 40 | 117 | -------------------------------------------------------------------------------- /docs/.vuepress/public/icons/graphql-black.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 72 | -------------------------------------------------------------------------------- /docs/webhooks/README.md: -------------------------------------------------------------------------------- 1 | # Cosmic Webhooks 2 | 3 | Cosmic makes it easy to add Webhooks to trigger a POST request to the endpoint of your choice when an event occurs in your Bucket. This is great for integrating static site rebuilds whenever content is changed, or adding third-party integrations like notifying your team on Slack whenever content has been added. 4 | 5 | ## Format 6 | 7 | All requests to your endpoint are sent via POST with Header and Body information. For example: 8 | 9 | #### Example Header 10 | ```json 11 | { 12 | "content-length": "450", // Your content length 13 | "x-cosmicjs-event": "object.edited.draft", // Your event key (see below) 14 | "accept": "application/json", 15 | "content-type": "application/json" 16 | } 17 | ``` 18 | 19 | #### Example Body 20 | ```json 21 | { 22 | "type": "object.edited.draft", 23 | "created_at": 1576861549889, 24 | "data": { 25 | "_id": "5dfcff5d6340c9000865cc25", 26 | "slug": "my-awesome-title", 27 | "title": "My Awesome Title", 28 | "content": "

My awesome content

", 29 | "metafields":[], 30 | "modified_at": "2019-12-20T17:05:49.879Z", 31 | "modified_by": "56d66b2f903a79b904000001", 32 | "type_slug": "tests", 33 | "status": "draft", 34 | "publish_at": null, 35 | "bucket": "5df644188e47080008e7721a", 36 | "created_at": "2019-12-20T17:05:49.879Z", 37 | "created_by": "56d66b2f903a79b904000001", 38 | "metadata": null 39 | } 40 | } 41 | ``` 42 | 43 | ## Events 44 | 45 | This is a list of available events. We will add to this list as more features become available. 46 | 47 | | Event | Occurs When | 48 | | ------------------------ | ---------------------------------------- | 49 | | object.created.draft | Object created and set to draft. | 50 | | object.created.published | Object created and published. | 51 | | object.edited.draft | Existing Object edited and set to draft. | 52 | | object.edited.published | Existing Object edited and published. | 53 | | object.edited.unpublished | Existing Object edited and unpublished. | 54 | | object.deleted | Object deleted. | 55 | | media.created | Media created. | 56 | | media.edited | Media edited. | 57 | | media.deleted | Media deleted. | 58 | | merge.completed | Merge Request completed. | 59 | 60 | ### Getting Started 61 | 62 | Manage Webhooks in your Bucket by logging in and going to the Webhooks section in your Bucket located at: 63 | 64 | - Your Bucket Dashboard > Webhooks 65 | 66 | ## Testing 67 | 68 | Using a service like [Beeceptor](https://beeceptor.com/) makes it easy to test your Webhooks and view response data. 69 | -------------------------------------------------------------------------------- /docs/graphql-api/methods-overview.md: -------------------------------------------------------------------------------- 1 | # Methods Overview 2 | 3 | ## Queries 4 | 5 | In GraphQL terminolgy, `queries` perform read actions on API resources. 6 | | Method | Description | Authentication Required | 7 | | ---------- | -------- | -------- | 8 | | [getObjects](/graphql-api/queries.html#getobjects) | Get Objects from a Bucket | | 9 | | [getObject](/graphql-api/queries.html#getobject) | Get a single Object from a Bucket | | 10 | | [getObjectRevisions](/graphql-api/queries.html#getObjectRevisions) | Get a single Object from a Bucket | | 11 | | [getMedia](/graphql-api/queries.html#getmedia) | Get Media from a Bucket | | 12 | | [getObjectTypes](/graphql-api/queries.html#getobjecttypes) | Get Object Types from a Bucket | | 13 | | [getBucket](/graphql-api/queries.html#getbucket) | Get all Bucket content | | 14 | | [getAccessToken](/graphql-api/queries.html#getaccesstoken) | Get token for account-related access (not required for Bucket-level access) | 15 | | [getBuckets](/graphql-api/queries.html#getbuckets) | Get all Buckets on your user account | yes | 16 | | [getUsers](/graphql-api/queries.html#getusers) | Get Users in a Bucket | yes | 17 | | [getUser](/graphql-api/queries.html#getuser) | Get a User in a Bucket | yes | 18 | 19 | ## Mutations 20 | 21 | In GraphQL terminolgy, `mutations` perform write, edit, or delete actions on API resources. 22 | | Method | Description | Authentication Required | 23 | | ---------- | -------- | -------- | 24 | | [addObject](/graphql-api/mutations.html#addobject) | Add an Object to your Bucket | | 25 | | [editObject](/graphql-api/mutations.html#editobject) | Edit an Object in your Bucket | | 26 | | [deleteObject](/graphql-api/mutations.html#deleteobject) | Delete an Object in your Bucket | | 27 | | [addObjectType](/graphql-api/mutations.html#addobjecttype) | Add an Object Type to your Bucket | | 28 | | [editObjectType](/graphql-api/mutations.html#editobjecttype) | Edit an Object Type in your Bucket | | 29 | | [deleteObjectType](/graphql-api/mutations.html#deleteobjecttype) | Delete an Object Type in your Bucket | | 30 | | [addBucket](/graphql-api/mutations.html#addbucket) | Add a Bucket to your user account | yes | 31 | | [deleteBucket](/graphql-api/mutations.html#deletebucket) | Delete a Bucket from your user account | yes | 32 | | [importBucket](/graphql-api/mutations.html#importbucket) | Import a Bucket on your user account | yes | 33 | | [addUser](/graphql-api/mutations.html#adduser) | Add a user to your Bucket | yes | 34 | | [addWebhook](/graphql-api/mutations.html#addwebhook) | Add a Webhook to your Bucket | yes | 35 | | [deleteWebhook](/graphql-api/mutations.html#deletewebhook) | Delete a Webhook in your Bucket | yes | 36 | | [addMedia](/graphql-api/mutations.html#addmedia) | `Coming soon` | yes | 37 | | [deleteMedia](/graphql-api/mutations.html#deletemedia) | Delete Media from your Bucket | yes | 38 | | [addExtension](/graphql-api/mutations.html#addextension) | `Coming soon` | yes | 39 | | [deleteExtension](/graphql-api/mutations.html#deleteextension) | Delete an Extension in your Bucket | yes | 40 | -------------------------------------------------------------------------------- /docs/rest-api/authentication.md: -------------------------------------------------------------------------------- 1 | # Authentication 2 | 3 | ## Get your token 4 | You can get your authentication token in your user account settings located in Account Settings > Authentication. You can also make requests to the API with your `email` and `password`. 5 | 6 | Send your `email` and `password` to receive your access token. Your access token will be used to add Buckets to your account as well as other account-related access. 7 | 8 | **NOTE: You do not need to use the token to access your Bucket. Your Bucket has its own read and write keys for restricted access.** 9 | 10 | | Parameter | Required | Type | Description | 11 | | --------- | -------- | ------ | ----------------------------- | 12 | | email | required | String | Your Cosmic login email | 13 | | password | required | String | Your Cosmic login password | 14 | 15 | :::: tabs :options="{ useUrlFragment: false }" 16 | 17 | ::: tab Bash 18 | **Definition** 19 | 20 | ``` 21 | POST https://api.cosmicjs.com/v1/authenticate 22 | ``` 23 | 24 | **Example Request** 25 | 26 | ```bash 27 | # With shell, you can just pass your email and password 28 | curl -X POST "https://api.cosmicjs.com/v1/authenticate" \ 29 | -d "email=you@youremail.com" \ 30 | -d "password=yourpassword" 31 | ``` 32 | 33 | **Example Response** 34 | 35 | ```json 36 | { 37 | "success": true, 38 | "message": "Token created successfully.", 39 | "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXV.eyJlbWFpbCI6InNwaXJvbnl..." 40 | } 41 | ``` 42 | 43 | ::: 44 | 45 | ::: tab Node.js 46 | **Definition** 47 | 48 | ```js 49 | Cosmic.authenticate() 50 | ``` 51 | 52 | **Example Request** 53 | 54 | ```js 55 | const Cosmic = require('cosmicjs')() // double parentheses to init function without token 56 | Cosmic.authenticate({ 57 | email: 'you@youremail.com', 58 | password: 'yourpassword' 59 | }).then(data => { 60 | console.log(data) 61 | }) 62 | .catch(err => { 63 | console.log(err) 64 | }) 65 | ``` 66 | 67 | **Example Response** 68 | 69 | ```json 70 | { 71 | "success": true, 72 | "message": "Token created successfully.", 73 | "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXV.eyJlbWFpbCI6InNwaXJvbnl..." 74 | } 75 | ``` 76 | 77 | ::: 78 | 79 | :::: 80 | 81 | 82 | ## Use your token 83 | 84 | You can use the Authentication token using REST requests to the API 85 | 86 | **Example Request with CURL** 87 | 88 | ```bash 89 | curl "https://api.cosmicjs.com/v1/buckets" \ 90 | -H "Authorization: Bearer " \ 91 | -H "Content-Type: application/json" 92 | # Gets all Buckets connected to your account. Your authorization token in the header request is the only required property. 93 | ``` 94 | 95 | **Example Request with the NPM module** 96 | 97 | ```js 98 | const Cosmic = require('cosmicjs')({ 99 | token: 'your-token-from-auth-request' 100 | }) 101 | Cosmic.getBuckets() 102 | .then(data => { 103 | console.log(data) 104 | }) 105 | .catch(err => { 106 | console.log(err) 107 | }) 108 | ``` -------------------------------------------------------------------------------- /docs/graphql-api/examples.md: -------------------------------------------------------------------------------- 1 | # Examples 2 | 3 | ## Node.js 4 | 5 | The following example will get 2 Blog Posts from the Bucket Simple React Blog. 6 | 7 | 1. Install [`axios`](https://www.npmjs.com/package/axios) 8 | 9 | ```bash 10 | npm install axios 11 | ``` 12 | 13 | 2. Add the following code to a file titled `index.js` 14 | 15 | ```javascript 16 | // index.js 17 | const axios = require('axios') 18 | axios.post('https://graphql.cosmicjs.com/v2', { 19 | query: `{ 20 | getObjects( 21 | bucket_slug: "simple-react-blog", 22 | input: { type: "posts", limit: 2 } 23 | ){ 24 | objects { 25 | title 26 | } 27 | total 28 | } 29 | }` 30 | }) 31 | .then(function (response) { 32 | const objects = response.data.data.getObjects 33 | console.log(objects) 34 | }) 35 | .catch(function (error) { 36 | console.log(error) 37 | }); 38 | ``` 39 | 40 | 3. Run the following command 41 | 42 | ```bash 43 | node index.js 44 | ``` 45 | 46 | ## Apollo 47 | You can use [Apollo Client](https://github.com/apollographql/apollo-client) to connect to the Cosmic GraphQL API. You will need to use a browser build system as noted on the [Apollo Client README](https://github.com/apollographql/apollo-client/blob/master/README.md#installation). 48 | 1. Install Apollo packages 49 | ```bash 50 | npm install apollo-boost graphql 51 | ``` 52 | 2. Create a file titled `index.js` and add the following example code: 53 | ```javascript 54 | // index.js 55 | import ApolloClient from "apollo-boost"; 56 | const client = new ApolloClient({ 57 | uri: "https://graphql.cosmicjs.com/v2" 58 | }); 59 | 60 | import { gql } from "apollo-boost"; 61 | 62 | client 63 | .query({ 64 | query: gql` 65 | { 66 | getObjects( 67 | bucket_slug: "simple-react-blog", 68 | input: { type: "posts", limit: 2 } 69 | ){ 70 | objects { 71 | title 72 | content 73 | } 74 | total 75 | } 76 | } 77 | ` 78 | }) 79 | .then(result => { 80 | console.log(result) 81 | document.getElementById('root').innerHTML = JSON.stringify(result.data.getObjects); 82 | }); 83 | ``` 84 | 3. Install [`webpack-cli`](https://www.npmjs.com/package/webpack-cli) 85 | ```bash 86 | npm i -g webpack-cli 87 | ``` 88 | 4. Create a file titled `webpack.config.js` 89 | ```javascript 90 | // webpack.config.js 91 | const path = require('path'); 92 | module.exports = { 93 | entry: './index.js', 94 | output: { 95 | path: path.resolve(__dirname, 'dist'), 96 | filename: 'bundle.js' 97 | } 98 | }; 99 | ``` 100 | 5. Create an HTML file titled `index.html` 101 | ```html 102 | 103 | 104 | 105 | Cosmic GraphQL Apollo Example 106 | 107 | 108 |
109 | 110 | 111 | 112 | ``` 113 | 6. Run webpack 114 | ``` 115 | webpack 116 | ``` 117 | 7. View the `index.html` file in a browser. 118 | 119 | 120 | ## Ajax 121 | 122 | Get one Object using client-side AJAX method. 123 | 124 | 125 | -------------------------------------------------------------------------------- /docs/.vuepress/theme/styles/code.styl: -------------------------------------------------------------------------------- 1 | .content 2 | code 3 | color lighten($textColor, 20%) 4 | padding 0.25rem 0.5rem 5 | margin 0 6 | font-size 0.85em 7 | background-color rgba(27,31,35,0.05) 8 | border-radius 3px 9 | .token 10 | &.deleted 11 | color #EC5975 12 | &.inserted 13 | color $accentColor 14 | 15 | .content 16 | pre, pre[class*="language-"] 17 | line-height 1.4 18 | padding 1.25rem 1.5rem 19 | margin 0.85rem 0 20 | background-color $codeBgColor 21 | border-radius 6px 22 | overflow auto 23 | code 24 | color #fff 25 | padding 0 26 | background-color transparent 27 | border-radius 0 28 | 29 | div[class*="language-"] 30 | position relative 31 | background-color $codeBgColor 32 | border-radius 6px 33 | .highlight-lines 34 | user-select none 35 | padding-top 1.3rem 36 | position absolute 37 | top 0 38 | left 0 39 | width 100% 40 | line-height 1.4 41 | .highlighted 42 | background-color rgba(0, 0, 0, 66%) 43 | pre, pre[class*="language-"] 44 | background transparent 45 | position relative 46 | z-index 1 47 | &::before 48 | position absolute 49 | z-index 3 50 | top 0.8em 51 | right 1em 52 | font-size 0.75rem 53 | color rgba(255, 255, 255, 0.4) 54 | &:not(.line-numbers-mode) 55 | .line-numbers-wrapper 56 | display none 57 | &.line-numbers-mode 58 | .highlight-lines .highlighted 59 | position relative 60 | &:before 61 | content ' ' 62 | position absolute 63 | z-index 3 64 | left 0 65 | top 0 66 | display block 67 | width $lineNumbersWrapperWidth 68 | height 100% 69 | background-color rgba(0, 0, 0, 66%) 70 | pre 71 | padding-left $lineNumbersWrapperWidth + 1 rem 72 | vertical-align middle 73 | .line-numbers-wrapper 74 | position absolute 75 | top 0 76 | width $lineNumbersWrapperWidth 77 | text-align center 78 | color rgba(255, 255, 255, 0.3) 79 | padding 1.25rem 0 80 | line-height 1.4 81 | br 82 | user-select none 83 | .line-number 84 | position relative 85 | z-index 4 86 | user-select none 87 | font-size 0.85em 88 | &::after 89 | content '' 90 | position absolute 91 | z-index 2 92 | top 0 93 | left 0 94 | width $lineNumbersWrapperWidth 95 | height 100% 96 | border-radius 6px 0 0 6px 97 | border-right 1px solid rgba(0, 0, 0, 66%) 98 | background-color $codeBgColor 99 | 100 | 101 | for lang in $codeLang 102 | div{'[class~="language-' + lang + '"]'} 103 | &:before 104 | content ('' + lang) 105 | 106 | div[class~="language-javascript"] 107 | &:before 108 | content "js" 109 | 110 | div[class~="language-typescript"] 111 | &:before 112 | content "ts" 113 | 114 | div[class~="language-markup"] 115 | &:before 116 | content "html" 117 | 118 | div[class~="language-markdown"] 119 | &:before 120 | content "md" 121 | 122 | div[class~="language-json"]:before 123 | content "json" 124 | 125 | div[class~="language-ruby"]:before 126 | content "rb" 127 | 128 | div[class~="language-python"]:before 129 | content "py" 130 | 131 | div[class~="language-bash"]:before 132 | content "sh" 133 | 134 | div[class~="language-php"]:before 135 | content "php" 136 | -------------------------------------------------------------------------------- /docs/.vuepress/theme/components/SidebarGroup.vue: -------------------------------------------------------------------------------- 1 | 62 | 63 | 78 | 79 | 141 | -------------------------------------------------------------------------------- /docs/.vuepress/theme/components/SidebarLink.vue: -------------------------------------------------------------------------------- 1 | 99 | 100 | 132 | -------------------------------------------------------------------------------- /docs/.vuepress/theme/components/Home.vue: -------------------------------------------------------------------------------- 1 | 51 | 52 | 72 | 73 | 163 | -------------------------------------------------------------------------------- /docs/.vuepress/theme/layouts/Layout.vue: -------------------------------------------------------------------------------- 1 | 52 | 53 | 155 | 156 | 157 | -------------------------------------------------------------------------------- /docs/.vuepress/theme/components/Navbar.vue: -------------------------------------------------------------------------------- 1 | 40 | 41 | 89 | 90 | 145 | -------------------------------------------------------------------------------- /docs/.vuepress/theme/components/NavLinks.vue: -------------------------------------------------------------------------------- 1 | 35 | 36 | 117 | 118 | 152 | -------------------------------------------------------------------------------- /docs/.vuepress/theme/styles/index.styl: -------------------------------------------------------------------------------- 1 | @require './config' 2 | @require './code' 3 | @require './custom-blocks' 4 | @require './arrow' 5 | @require './wrapper' 6 | @require './toc' 7 | @require './home' 8 | @require '~vuepress-plugin-tabs/dist/themes/default.styl' 9 | 10 | html, body 11 | padding 0 12 | margin 0 13 | background-color #fff 14 | 15 | body 16 | font-family 'Open Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif 17 | -webkit-font-smoothing antialiased 18 | -moz-osx-font-smoothing grayscale 19 | font-size 16px 20 | color $textColor 21 | 22 | a:hover 23 | text-decoration none 24 | 25 | .page 26 | padding-left $sidebarWidth 27 | 28 | .deprecation-banner 29 | display: block; 30 | background-color: #FFF7ED; 31 | color: #ea580c; 32 | padding: 0.9rem 1.25rem; 33 | font-size: 1rem; 34 | line-height: 1.5rem; 35 | text-align: center; 36 | width: 100%; 37 | margin-inline: auto; 38 | 39 | .navbar 40 | position sticky 41 | z-index 20 42 | z-index 20 43 | top 0 44 | left 0 45 | right 0 46 | height $navbarHeight 47 | background-color #fff 48 | box-sizing border-box 49 | border-bottom 1px solid $borderColor 50 | 51 | .sidebar-mask 52 | position fixed 53 | z-index 9 54 | top 0 55 | left 0 56 | width 100vw 57 | height 100vh 58 | display none 59 | 60 | .sidebar 61 | font-size 16px 62 | background-color #fff 63 | width $sidebarWidth 64 | position fixed 65 | z-index 10 66 | margin 0 67 | top 110px 68 | left 0 69 | bottom 0 70 | box-sizing border-box 71 | border-right 1px solid $borderColor 72 | overflow-y auto 73 | 74 | .content:not(.custom) 75 | @extend $wrapper 76 | > *:first-child 77 | margin-top $navbarHeight 78 | p.demo 79 | padding 1rem 1.5rem 80 | border 1px solid #ddd 81 | border-radius 4px 82 | img 83 | max-width 100% 84 | 85 | .content.custom 86 | padding 0 87 | margin 0 88 | img 89 | max-width 100% 90 | 91 | a 92 | font-weight 500 93 | color $accentColor 94 | text-decoration none 95 | 96 | p a code 97 | font-weight 400 98 | color $accentColor 99 | 100 | kbd 101 | background #eee 102 | border solid 0.15rem #ddd 103 | border-bottom solid 0.25rem #ddd 104 | border-radius 0.15rem 105 | padding 0 0.15em 106 | 107 | blockquote 108 | font-size .9rem 109 | color #999 110 | border-left .5rem solid #dfe2e5 111 | margin 0.5rem 0 112 | padding .25rem 0 .25rem 1rem 113 | & > p 114 | margin 0 115 | 116 | ul, ol 117 | padding-left 1.2em 118 | 119 | strong 120 | font-weight 600 121 | 122 | h1, h2, h3, h4, h5, h6 123 | font-weight 600 124 | line-height 1.25 125 | .content:not(.custom) > & 126 | margin-top (0.5rem - $navbarHeight) 127 | padding-top ($navbarHeight + 1rem) 128 | margin-bottom 0 129 | &:first-child 130 | margin-top -1.5rem 131 | margin-bottom 1rem 132 | + p, + pre, + .custom-block 133 | margin-top 2rem 134 | &:hover .header-anchor 135 | opacity: 1 136 | 137 | h1 138 | font-size 2.2rem 139 | 140 | h2 141 | font-size 1.65rem 142 | padding-bottom .3rem 143 | border-bottom 1px solid $borderColor 144 | 145 | h3 146 | font-size 1.35rem 147 | 148 | a.header-anchor 149 | font-size 0.85em 150 | float left 151 | margin-left -0.87em 152 | padding-right 0.23em 153 | margin-top 0.125em 154 | opacity 0 155 | &:hover 156 | text-decoration none 157 | 158 | code, kbd, .line-number 159 | font-family source-code-pro, Menlo, Monaco, Consolas, "Courier New", monospace 160 | 161 | p, ul, ol 162 | line-height 1.7 163 | 164 | hr 165 | border 0 166 | border-top 1px solid $borderColor 167 | 168 | table 169 | border-collapse collapse 170 | margin 1rem 0 171 | display: block 172 | overflow-x: auto 173 | 174 | tr 175 | border-top 1px solid #dfe2e5 176 | &:nth-child(2n) 177 | background-color #f6f8fa 178 | 179 | th, td 180 | border 1px solid #dfe2e5 181 | padding .6em 1em 182 | 183 | .theme-container 184 | &.sidebar-open 185 | .sidebar-mask 186 | display: block 187 | &.no-navbar 188 | .content:not(.custom) > h1, h2, h3, h4, h5, h6 189 | margin-top 1.5rem 190 | padding-top 0 191 | .sidebar 192 | top 0 193 | 194 | 195 | @media (min-width: ($MQMobile + 1px)) 196 | .theme-container.no-sidebar 197 | .sidebar 198 | display none 199 | .page 200 | padding-left 0 201 | 202 | @require 'mobile.styl' -------------------------------------------------------------------------------- /docs/.vuepress/theme/components/AlgoliaSearchBox.vue: -------------------------------------------------------------------------------- 1 | 13 | 14 | 61 | 62 | 156 | -------------------------------------------------------------------------------- /docs/.vuepress/theme/components/DropdownLink.vue: -------------------------------------------------------------------------------- 1 | 51 | 52 | 78 | 79 | 180 | -------------------------------------------------------------------------------- /docs/.vuepress/public/icons/function-black.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 19 | 21 | 40 | 42 | 43 | 45 | image/svg+xml 46 | 48 | 49 | 50 | 51 | 52 | 57 | 62 | 63 | -------------------------------------------------------------------------------- /docs/.vuepress/public/icons/function.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 19 | 21 | 40 | 42 | 43 | 45 | image/svg+xml 46 | 48 | 49 | 50 | 51 | 52 | 57 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /docs/rest-api/webhooks.md: -------------------------------------------------------------------------------- 1 | # Webhooks 2 | Webhooks send a POST request to the endpoint of your choice when the specific event occurs. The data payload in the same fomat as Object and Media. Read more about Webhooks including the payload sent to the endpoint on the [Webhooks documentation page](/webhooks). 3 | 4 | 5 | ## Add Webhook 6 | 7 | Your authorization token in the header is required. 8 | 9 | | Parameter | Required | Type | Description | 10 | | --------- | -------- | ------ | -------------------------------------------------------------------------------------------------------------------------------------------------------- | 11 | | event | required | Enum | object.created.draft, object.created.published, object.edited.draft, object.edited.published, object.deleted, media.created, media.edited, media.deleted | 12 | | endpoint | required | String | The endpoint that will receive the data | 13 | 14 | :::: tabs :options="{ useUrlFragment: false }" 15 | 16 | ::: tab Bash 17 | **Definition** 18 | 19 | ``` 20 | POST https://api.cosmicjs.com/v1/:bucket_slug/webhooks 21 | ``` 22 | 23 | **Example Request** 24 | 25 | ```json 26 | { 27 | "event": "object.created.published", 28 | "endpoint": "http://my-listener.com" 29 | } 30 | ``` 31 | 32 | **Example Response** 33 | 34 | ```json 35 | { 36 | "webhook": { 37 | "id": "e39b2480-f043-11e7-ba08-234e3fae7762", 38 | "title": "Object created and published", 39 | "event": "object.created.published", 40 | "endpoint": "http://my-listener.com" 41 | } 42 | } 43 | ``` 44 | 45 | ::: 46 | 47 | ::: tab Node.js 48 | **Definition** 49 | 50 | ```js 51 | bucket.addWebhooks() 52 | ``` 53 | 54 | **Example Request** 55 | 56 | ```js 57 | const Cosmic = require('cosmicjs')({ 58 | token: 'your-token-from-auth-request' // optional 59 | }) 60 | const bucket = Cosmic.bucket({ 61 | slug: 'bucket-slug' 62 | }) 63 | bucket.addWebhook({ 64 | event: 'object.created.published', 65 | endpoint: 'http://my-listener.com' 66 | }) 67 | .then(data => { 68 | console.log(data) 69 | }) 70 | .catch(err => { 71 | console.log(err) 72 | }) 73 | ``` 74 | 75 | **Example Response** 76 | 77 | ```json 78 | { 79 | "webhook": { 80 | "id": "e39b2480-f043-11e7-ba08-234e3fae7762", 81 | "title": "Object created and published", 82 | "event": "object.created.published", 83 | "endpoint": "http://my-listener.com" 84 | } 85 | } 86 | ``` 87 | 88 | ::: 89 | 90 | :::: 91 | 92 | ## Get Webhooks 93 | 94 | Get webhooks in your Bucket. Authentication token is required in the header (see Authentication section). Must have admin level access. 95 | 96 | :::: tabs :options="{ useUrlFragment: false }" 97 | 98 | ::: tab Bash 99 | **Definition** 100 | 101 | ``` 102 | GET https://api.cosmicjs.com/v1/:bucket_slug/webhooks 103 | ``` 104 | 105 | **Example Request** 106 | 107 | ```bash 108 | curl "https://api.cosmicjs.com/v1/creative-agency/webhooks" \ 109 | -H "Authorization: Bearer " 110 | ``` 111 | 112 | **Example Response** 113 | 114 | ```json 115 | { 116 | "webhooks": [ 117 | { 118 | "title": "Object created and published", 119 | "event": "object.created.published", 120 | "endpoint": "http://your-endpoint.com/webhook-listener" 121 | }, 122 | { 123 | "title": "Object edited and unpublished", 124 | "event": "object.created.unpublished", 125 | "endpoint": "http://your-endpoint.com/webhook-listener" 126 | } 127 | ], 128 | "total": 2 129 | } 130 | ``` 131 | 132 | ::: 133 | 134 | ::: tab Node.js 135 | **Definition** 136 | 137 | ```js 138 | bucket.getWebhooks() 139 | ``` 140 | 141 | **Example Request** 142 | 143 | ```js 144 | const bucket = Cosmic.bucket({ 145 | slug: 'bucket-slug' 146 | }) 147 | bucket.getWebhooks() 148 | .then(data => { 149 | console.log(data) 150 | }) 151 | .catch(err => { 152 | console.log(err) 153 | }) 154 | ``` 155 | 156 | **Example Response** 157 | 158 | ```json 159 | { 160 | "webhooks": [ 161 | { 162 | "title": "Object created and published", 163 | "event": "object.created.published", 164 | "endpoint": "http://your-endpoint.com/webhook-listener" 165 | }, 166 | { 167 | "title": "Object edited and unpublished", 168 | "event": "object.created.unpublished", 169 | "endpoint": "http://your-endpoint.com/webhook-listener" 170 | } 171 | ], 172 | "total": 2 173 | } 174 | ``` 175 | 176 | ::: 177 | 178 | :::: 179 | 180 | 181 | ## Delete a Webhook 182 | 183 | The webhook id and authorization token in the header are required. 184 | 185 | :::: tabs :options="{ useUrlFragment: false }" 186 | 187 | ::: tab Bash 188 | **Definition** 189 | 190 | ``` 191 | DELETE https://api.cosmicjs.com/v1/:bucket_slug/webhooks/:webhook_id 192 | ``` 193 | 194 | **Example Response** 195 | 196 | ```json 197 | { 198 | "status": "200", 199 | "message": "Webhook deleted." 200 | } 201 | ``` 202 | 203 | ::: 204 | 205 | ::: tab Node.js 206 | **Definition** 207 | 208 | ```js 209 | Cosmic.deleteWebhook() 210 | ``` 211 | 212 | **Example Request** 213 | 214 | ```js 215 | const Cosmic = require('cosmicjs')({ 216 | token: 'your-token-from-auth-request' // optional 217 | }) 218 | const bucket = Cosmic.bucket({ 219 | slug: 'bucket-slug', 220 | }) 221 | bucket.deleteWebhook({ 222 | id: 'c62defe0-5f93-11e7-8054-873245f0e98d' 223 | }) 224 | .then(data => { 225 | console.log(data) 226 | }) 227 | .catch(err => { 228 | console.log(err) 229 | }) 230 | ``` 231 | 232 | **Example Response** 233 | 234 | ```json 235 | { 236 | "status": "200", 237 | "message": "Webhook deleted." 238 | } 239 | ``` 240 | 241 | ::: 242 | 243 | :::: 244 | -------------------------------------------------------------------------------- /docs/extensions/README.md: -------------------------------------------------------------------------------- 1 | # Extensions 2 | 3 | Cosmic Extensions enable you to customize the Cosmic Dashboard experience to create custom experiences in your Bucket Dashboard. 4 | Pre-built Extensions are available for demo and install. 5 | 6 | ![Screenshot of Cosmic dashboard](https://web-assets.cosmicjs.com/images/docs/dashboard-screenshot.jpg) 7 | 8 | ## Getting started 9 | 10 | Go to _Your Bucket > Settings > Extensions_. There are [pre-built Extensions available for install](https://cosmicjs.com/extensions) to extend the functionality of your Bucket. All of the code is open source. You can also build your own Extensions. They are simply [JAMstack](https://jamstack.org/) apps (static web app built using HTML / CSS / JavaScript). 11 | 12 | ### Adding an extension 13 | 14 | 1. Go to _Your Bucket > Extensions > Add Extension_ 15 | 1. You can add either an Extension that points to a URL (https required, X-Frame Options enabled) or upload a zip file that contains a static web app. 16 | 17 | ## Extension via external URL 18 | 19 | You can add an Extension by URL (https required, X-Frame Options enabled), title and icon. 20 | 21 | ![Screenshot of adding extension by URL](https://web-assets.cosmicjs.com/images/docs/add-extension-url.png) 22 | 23 | ### Query parameters 24 | 25 | After adding your Extension, query parameters are attached to the URL for easy connection to your Bucket. The format looks like this: 26 | 27 | ``` 28 | https://my-custom-webapp.netlify.com?bucket_slug=your-bucket-slug&read_key=your-bucket-read-key&write_key=your-bucket-write-key 29 | ``` 30 | 31 | | Name | Description | 32 | | -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- | 33 | | bucket_slug | Your Bucket slug. Use this to connect to your Cosmic Bucket for read / write / edits. | 34 | | read_key | Your Bucket read key. Needed to read from your Bucket if this value is set in your Bucket > Settings > Basic. | 35 | | write_key | Your Bucket write key. Needed for writes to your Bucket if this value is set in your Bucket > Settings > Basic. | 36 | | [custom key / value] | You can add unlimited custom query pamaters such as 3rd-party API keys to connect to different services. Find this in your Cosmic Extension settings page. | 37 | 38 | ## Extension via static web app 39 | 40 | Check out the [Extension Starter](https://github.com/cosmicjs/extension-starter) to see a basic HTML / CSS / JavaScript example. 41 | 42 | Add a static web app Extension to your Bucket by uploading a zipped folder that includes at least the following required files: 43 | 44 | ``` 45 | . (Your extension folder) 46 | ├── extension.json (Optional) 47 | ├── index.html 48 | ``` 49 | 50 | ### Extension settings 51 | 52 | The `extension.json` file sets information about your Extension. Add an optional [Font Awesome icon](http://fontawesome.io/icons/) to create a custom icon in the side nav. Add an image URL as the thumbnail image next to your Extension. Example: 53 | 54 | ```json 55 | { 56 | "title": "Product Manager", 57 | "font_awesome_class": "fa-tags", 58 | "image_url": "https://this-is-your-thumbnail-url.xyz" 59 | } 60 | ``` 61 | 62 | ### Optional import data 63 | 64 | Along with the Extension info, you can import data to the destination Bucket. By adding an `objects` array, you are able to import Objects. By adding an `object_types` array, you are able to import Object Types. 65 | 66 | ```json 67 | { 68 | "title": "Product Manager", 69 | "font_awesome_class": "fa-tags", 70 | "image_url": "http://this-is-your-thumbnail-url.xyz" 71 | "objects": [ 72 | { 73 | "title": "Product 1", 74 | "slug": "product-1", 75 | "type_slug": "products", 76 | "metafields": [ 77 | { 78 | "title": "Image", 79 | "key": "image", 80 | "value": "1234asdf1234.jpg" 81 | }, 82 | { 83 | "title": "Price", 84 | "key": "price", 85 | "value": "$12.99" 86 | } 87 | ] 88 | }, 89 | { 90 | "title": "Product 2", 91 | "slug": "product-2", 92 | "type_slug": "products", 93 | "metafields": [ 94 | { 95 | "title": "Image", 96 | "key": "image", 97 | "value": "4321asdf1234.jpg" 98 | }, 99 | { 100 | "title": "Price", 101 | "key": "price", 102 | "value": "$14.99" 103 | } 104 | ] 105 | } 106 | ], 107 | "object_types": [ 108 | { 109 | "title": "Products", 110 | "slug": "products", 111 | "singular": "Product", 112 | "metafields":[ 113 | { 114 | "title": "Image", 115 | "key": "image", 116 | "type": "file", 117 | "value": "" 118 | }, 119 | { 120 | "title": "Price", 121 | "key": "price", 122 | "type": "text", 123 | "value":"" 124 | } 125 | ] 126 | } 127 | ] 128 | } 129 | ``` 130 | 131 | ### Preparing Your Extension for Upload 132 | 133 | The static site folder contents: 134 | 135 | ![Screenshot of how to compress build folder - Part 1](https://web-assets.cosmicjs.com/images/docs/compress-1.png) 136 | 137 | Compress the folder: 138 | 139 | ![Screenshot of how to compress build folder - Part 2](https://web-assets.cosmicjs.com/images/docs/compress-2.png) 140 | 141 | Then upload the Extension to your Cosmic Bucket located in *Your Bucket > Extensions > Add Extension*. 142 | 143 | ![Screenshot of add extension](https://web-assets.cosmicjs.com/images/docs/add-extension-zip.png) 144 | 145 | ## Contribute 146 | 147 | Submit your idea to the [Cosmic contribution page](https://cosmicjs.com/contribute). We'll showcase your awesome Cosmic Extension and you'll get free stuff. 😎 148 | 149 | Any questions? Reach out to us on our [Slack channel](https://cosmicjs.com/community) and reach out to us [on Twitter](https://twitter.com/cosmicjs). 150 | -------------------------------------------------------------------------------- /docs/functions/README.md: -------------------------------------------------------------------------------- 1 | # Cosmic Functions 2 | 3 | ![Cosmic and AWS Logos](https://web-assets.cosmicjs.com/images/docs/cosmicjs-aws-logos.jpg) 4 | 5 | ## How it works 6 | 7 | You can deploy Node.js functions to AWS through your Bucket Dashboard located at _Your Bucket > Settings > Functions_. AWS Lambda functions are infinitely scalable, highly cost effective ([AWS gives you 1M requests per month free](https://aws.amazon.com/lambda/pricing/)), and you never have to pay for idle server time. **You can have unlimited Functions in your Cosmic Bucket and the feature is 100% free to use.** 8 | 9 | ## What's required? 10 | 11 | 1. Your AWS access key and secret key. (See instructions below) 12 | 2. Node.js codebase (zip or link to git repo) that follows Lambda requirements. 13 | 14 | ### How to get your AWS access keys 15 | Follow these steps to get your AWS access keys: 16 | 1. [Create or login](http://console.aws.amazon.com) to your Amazon Web Services Account and go to the Identity & Access Management (IAM) page. 17 | 2. Click on Users and then Add user. Enter a name in the first field to remind you this User is from Cosmic, like cosmic-admin. Enable Programmatic access by clicking the checkbox. Click Next to go through to the Permissions page. 18 | 19 | 3. Click on Attach existing policies directly. Search for and select AdministratorAccess then click through to Next: Review. Check everything looks good and click Create user. 20 | 21 | 4. View and copy the API Key & Secret to a temporary place. You'll need it for all of your Cosmic Function deploys. 22 | 23 | ## Required Files 24 | 25 | ### Entry file 26 | 27 | The `index.js` file of your codebase will need to export a `handler` function and follow the format for [AWS Lambda Node.js function handling](https://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-handler.html). The version of Node.js deployed is `v10.x`. Here's a simple Hello World example: 28 | 29 | ```js 30 | // index.js 31 | module.exports.handler = function(event, context, callback) { 32 | const response = { 33 | statusCode: 200, 34 | headers: { 35 | 'Access-Control-Allow-Origin': '*' // Required for CORS support to work 36 | }, 37 | body: 'Hello World ' + process.env.SOME_OPTIONAL_VAR 38 | } 39 | callback(null, response) 40 | } 41 | ``` 42 | 43 | ### Function config file 44 | 45 | The `function.json` file includes information that Cosmic uses to deploy your function. Here's an example: 46 | 47 | ```json 48 | { 49 | "title": "Hello World", 50 | "description": "Says Hello World and some custom message from env var.", 51 | "image_url": "https://cosmic-s3.imgix.net/ed58d700-7b2c-11e8-9d6b-252d8b978aea-SendGrid-Logo.png", 52 | "stage": "staging", 53 | "env_vars": [ 54 | { 55 | "key": "SOME_OPTIONAL_VAR", 56 | "value": "" 57 | } 58 | ], 59 | "routes": [ 60 | { 61 | "path": "hello-world", 62 | "method": "get", 63 | "cors": true 64 | } 65 | ] 66 | } 67 | ``` 68 | 69 | ### `function.json` Properties 70 | 71 | | Key | Type | Description | 72 | | -------------- | ------ | ---------------------------------------------------------------------------------- | 73 | | title | String | Function title | 74 | | description | String | Function description (HTML allowed) | 75 | | image_url | String | Image thumbnail URL | 76 | | stage | String | defaults to dev | 77 | | repo_url | String | Function git repo url | 78 | | env_vars | Array | key / value for environment variables | 79 | | routes | Array | Function routes: properties include path (string), method (string) and cors (bool) | 80 | | dynamic_routes | Bool | Allows dynamic routes to your function. Overrides the routes property. | 81 | 82 | ## Dynamic Routes 83 | 84 | Your Function can serve dynamic routes, like an Express application (see the Serverless Starter). To make routes dynamic, add the `dynamic_routes` property set to `true` in your `function.json` file: 85 | 86 | ```json 87 | { 88 | "title": "Dynamic Routes", 89 | "description": "A serverless function with dynamic routes.", 90 | "image_url": "https://cosmicjs.com/images/logos/serverless.svg", 91 | "stage": "dev", 92 | "dynamic_routes": true 93 | } 94 | ``` 95 | 96 | Your index.js file will look something like this: 97 | 98 | ```js 99 | // index.js 100 | const serverless = require('serverless-http') 101 | const express = require('express') 102 | const app = express() 103 | app.get('/:slug?', (req, res) => { 104 | res.json({ message: 'Your dynamic slug is ' + req.params.slug }); 105 | }) 106 | 107 | module.exports.handler = serverless(app); 108 | ``` 109 | 110 | ## Install your Function 111 | Go to *Your Bucket > Settings > Functions* to deploy a new Function. Whether you install from git repo URL or .zip file, make sure to include both `index.js` and `function.json` files in your codebase. 112 | 113 | ## Deploy your Function 114 | 115 | After your Function is installed, follow these steps: 116 | 117 | 1. Go to Your *Bucket > Settings > Functions > Your Function*. 118 | 1. Add your AWS credentials. 119 | 1. Add any other required environment variables. 120 | 1. Click "Deploy Function". 121 | 122 | ## Examples 123 | View these Function examples on GitHub: 124 | 125 | - [Function Starter](https://github.com/cosmicjs/function-starter) 126 | - Get started with Cosmic Functions. 127 | 128 | - [SendGrid Email](https://github.com/cosmicjs/send-email-function) 129 | - Send an email using SendGrid. 130 | 131 | - [Stripe Charge](https://github.com/cosmicjs/stripe-charge-function) 132 | - Submit a charge to Stripe. 133 | 134 | We hope you enjoy the new freedom you have to deploy serverless functions using Cosmic JS. If you have any questions, you can [reach out to us on Twitter](https://twitter.com/cosmicjs) and [join the community on Slack](https://cosmicjs.com/community). 135 | -------------------------------------------------------------------------------- /docs/.vuepress/theme/components/Page.vue: -------------------------------------------------------------------------------- 1 | 63 | 64 | 194 | 195 | 245 | -------------------------------------------------------------------------------- /docs/.vuepress/config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | siteTitle: 'Cosmic', 3 | base: '/', 4 | themeConfig: { 5 | logo: 'https://cdn.cosmicjs.com/3cf62ab0-8e13-11ea-9b8f-cd0254a8c979-cosmic-dark.svg', 6 | repo: 'cosmicjs/docs', 7 | docsDir: 'docs', 8 | editLinks: true, 9 | editLinkText: 'Edit this page', 10 | lastUpdated: 'Last Updated', 11 | algolia: { 12 | apiKey: '2cdadd5ab16751ea3a49a13854e5b052', 13 | indexName: 'cosmicjs' 14 | }, 15 | sidebar: { 16 | '/graphql-api/': [ 17 | { 18 | title: 'Home', 19 | path: '/' 20 | }, 21 | { 22 | title: 'REST API', 23 | icon: '/icons/npm.svg', 24 | path: '/rest-api/' 25 | }, 26 | { 27 | title: 'GraphQL API', 28 | icon: '/icons/graphql.svg', 29 | path: '/graphql-api/', 30 | collapsable: false, 31 | children: [ 32 | ['/graphql-api/', 'Introduction'], 33 | '/graphql-api/request-limits', 34 | '/graphql-api/methods-overview', 35 | '/graphql-api/queries', 36 | '/graphql-api/mutations', 37 | '/graphql-api/examples', 38 | '/graphql-api/previous-versions' 39 | ] 40 | }, 41 | { 42 | title: 'Guides', 43 | path: '/guides/', 44 | icon: 'https://cdn.cosmicjs.com/4d1e8850-33e7-11ea-983a-099bce0aacb8-067-book-2.svg' 45 | }, 46 | { 47 | title: 'Webhooks', 48 | path: '/webhooks/', 49 | icon: 'https://cdn.cosmicjs.com/0d611e50-c832-11ea-b44f-f5c7da208e23-007-anchor.svg' 50 | }, 51 | { 52 | title: 'Extensions', 53 | path: '/extensions/', 54 | icon: 'https://cdn.cosmicjs.com/6174d730-898e-11ea-9edc-335682595c41-cubes.svg' 55 | }, 56 | { 57 | title: 'CLI', 58 | path: '/cli/', 59 | icon: 'https://cdn.cosmicjs.com/505c07b0-c832-11ea-b44f-f5c7da208e23-039-web-programming.svg' 60 | }, 61 | { 62 | title: 'Functions', 63 | path: '/functions/', 64 | icon: '/icons/function.svg' 65 | } 66 | ], 67 | '/rest-api/': [ 68 | { 69 | title: 'Home', 70 | path: '/' 71 | }, 72 | { 73 | title: 'REST API', 74 | icon: '/icons/npm.svg', 75 | path: '/rest-api/', 76 | collapsable: false, 77 | children: [ 78 | ['/rest-api/', 'Introduction'], 79 | '/rest-api/errors', 80 | '/rest-api/request-limits', 81 | '/rest-api/authentication', 82 | '/rest-api/buckets', 83 | '/rest-api/users', 84 | '/rest-api/object-types', 85 | '/rest-api/objects', 86 | '/rest-api/metafields', 87 | '/rest-api/media', 88 | '/rest-api/webhooks', 89 | '/rest-api/extensions' 90 | ] 91 | }, 92 | { 93 | title: 'GraphQL API', 94 | icon: '/icons/graphql.svg', 95 | path: '/graphql-api/' 96 | }, 97 | { 98 | title: 'Guides', 99 | path: '/guides/', 100 | icon: 'https://cdn.cosmicjs.com/4d1e8850-33e7-11ea-983a-099bce0aacb8-067-book-2.svg' 101 | }, 102 | { 103 | title: 'Webhooks', 104 | path: '/webhooks/', 105 | icon: 'https://cdn.cosmicjs.com/0d611e50-c832-11ea-b44f-f5c7da208e23-007-anchor.svg' 106 | }, 107 | { 108 | title: 'Extensions', 109 | path: '/extensions/', 110 | icon: 'https://cdn.cosmicjs.com/6174d730-898e-11ea-9edc-335682595c41-cubes.svg' 111 | }, 112 | { 113 | title: 'CLI', 114 | path: '/cli/', 115 | icon: 'https://cdn.cosmicjs.com/505c07b0-c832-11ea-b44f-f5c7da208e23-039-web-programming.svg' 116 | }, 117 | { 118 | title: 'Functions', 119 | path: '/functions/', 120 | icon: '/icons/function.svg' 121 | } 122 | ], 123 | '/': [ 124 | { 125 | title: 'Home', 126 | path: '/' 127 | }, 128 | { 129 | title: 'REST API', 130 | icon: '/icons/npm.svg', 131 | path: '/rest-api/', 132 | }, 133 | { 134 | title: 'GraphQL API', 135 | path: '/graphql-api/', 136 | icon: '/icons/graphql.svg' 137 | }, 138 | { 139 | title: 'Guides', 140 | path: '/guides/', 141 | icon: 'https://cdn.cosmicjs.com/4d1e8850-33e7-11ea-983a-099bce0aacb8-067-book-2.svg' 142 | }, 143 | { 144 | title: 'Webhooks', 145 | path: '/webhooks/', 146 | icon: 'https://cdn.cosmicjs.com/0d611e50-c832-11ea-b44f-f5c7da208e23-007-anchor.svg' 147 | }, 148 | { 149 | title: 'Extensions', 150 | path: '/extensions/', 151 | icon: 'https://cdn.cosmicjs.com/6174d730-898e-11ea-9edc-335682595c41-cubes.svg' 152 | }, 153 | { 154 | title: 'CLI', 155 | path: '/cli/', 156 | icon: 'https://cdn.cosmicjs.com/505c07b0-c832-11ea-b44f-f5c7da208e23-039-web-programming.svg' 157 | }, 158 | { 159 | title: 'Functions', 160 | path: '/functions/', 161 | icon: '/icons/function.svg' 162 | } 163 | ] 164 | } 165 | }, 166 | head: [ 167 | ['link', 168 | { 169 | href: "https://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,400,300,600", 170 | rel: "stylesheet", 171 | type: "text/css" 172 | } 173 | ], 174 | [ 175 | 'link', 176 | { 177 | rel: 'shortcut icon', 178 | type: 'image/x-icon', 179 | href: 'https://cosmicjs.com/images/favicons/apple-touch-icon-57x57.png' 180 | } 181 | ], 182 | [ 183 | 'link', 184 | { 185 | rel: 'icon', 186 | type: 'image/x-icon', 187 | href: 'https://cosmicjs.com/images/favicons/apple-touch-icon-57x57.png' 188 | } 189 | ], 190 | [ 191 | 'meta', 192 | { 193 | name: 'robots', 194 | content: 'noindex' 195 | } 196 | ] 197 | ], 198 | plugins: [ 199 | 'tabs', 200 | [ 201 | '@vuepress/google-analytics', 202 | { 203 | 'ga': 'UA-47527341-3' 204 | } 205 | ], 206 | [require('vuepress-intercom'), { appId: 'o4fm83zs' }] 207 | ] 208 | } -------------------------------------------------------------------------------- /docs/.vuepress/theme/util/index.js: -------------------------------------------------------------------------------- 1 | export const hashRE = /#.*$/ 2 | export const extRE = /\.(md|html)$/ 3 | export const endingSlashRE = /\/$/ 4 | export const outboundRE = /^(https?:|mailto:|tel:)/ 5 | 6 | export function normalize (path) { 7 | return decodeURI(path) 8 | .replace(hashRE, '') 9 | .replace(extRE, '') 10 | } 11 | 12 | export function getHash (path) { 13 | const match = path.match(hashRE) 14 | if (match) { 15 | return match[0] 16 | } 17 | } 18 | 19 | export function isExternal (path) { 20 | return outboundRE.test(path) 21 | } 22 | 23 | export function isMailto (path) { 24 | return /^mailto:/.test(path) 25 | } 26 | 27 | export function isTel (path) { 28 | return /^tel:/.test(path) 29 | } 30 | 31 | export function ensureExt (path) { 32 | if (isExternal(path)) { 33 | return path 34 | } 35 | const hashMatch = path.match(hashRE) 36 | const hash = hashMatch ? hashMatch[0] : '' 37 | const normalized = normalize(path) 38 | 39 | if (endingSlashRE.test(normalized)) { 40 | return path 41 | } 42 | return normalized + '.html' + hash 43 | } 44 | 45 | export function isActive (route, path) { 46 | const routeHash = route.hash 47 | const linkHash = getHash(path) 48 | if (linkHash && routeHash !== linkHash) { 49 | return false 50 | } 51 | const routePath = normalize(route.path) 52 | const pagePath = normalize(path) 53 | return routePath === pagePath 54 | } 55 | 56 | export function resolvePage (pages, rawPath, base) { 57 | if (base) { 58 | rawPath = resolvePath(rawPath, base) 59 | } 60 | const path = normalize(rawPath) 61 | for (let i = 0; i < pages.length; i++) { 62 | if (normalize(pages[i].regularPath) === path) { 63 | return Object.assign({}, pages[i], { 64 | type: 'page', 65 | path: ensureExt(pages[i].path) 66 | }) 67 | } 68 | } 69 | console.error(`[vuepress] No matching page found for sidebar item "${rawPath}"`) 70 | return {} 71 | } 72 | 73 | function resolvePath (relative, base, append) { 74 | const firstChar = relative.charAt(0) 75 | if (firstChar === '/') { 76 | return relative 77 | } 78 | 79 | if (firstChar === '?' || firstChar === '#') { 80 | return base + relative 81 | } 82 | 83 | const stack = base.split('/') 84 | 85 | // remove trailing segment if: 86 | // - not appending 87 | // - appending to trailing slash (last segment is empty) 88 | if (!append || !stack[stack.length - 1]) { 89 | stack.pop() 90 | } 91 | 92 | // resolve relative path 93 | const segments = relative.replace(/^\//, '').split('/') 94 | for (let i = 0; i < segments.length; i++) { 95 | const segment = segments[i] 96 | if (segment === '..') { 97 | stack.pop() 98 | } else if (segment !== '.') { 99 | stack.push(segment) 100 | } 101 | } 102 | 103 | // ensure leading slash 104 | if (stack[0] !== '') { 105 | stack.unshift('') 106 | } 107 | 108 | return stack.join('/') 109 | } 110 | 111 | /** 112 | * @param { Page } page 113 | * @param { string } regularPath 114 | * @param { SiteData } site 115 | * @param { string } localePath 116 | * @returns { SidebarGroup } 117 | */ 118 | export function resolveSidebarItems (page, regularPath, site, localePath) { 119 | const { pages, themeConfig } = site 120 | 121 | const localeConfig = localePath && themeConfig.locales 122 | ? themeConfig.locales[localePath] || themeConfig 123 | : themeConfig 124 | 125 | const pageSidebarConfig = page.frontmatter.sidebar || localeConfig.sidebar || themeConfig.sidebar 126 | if (pageSidebarConfig === 'auto') { 127 | return resolveHeaders(page) 128 | } 129 | 130 | const sidebarConfig = localeConfig.sidebar || themeConfig.sidebar 131 | if (!sidebarConfig) { 132 | return [] 133 | } else { 134 | const { base, config } = resolveMatchingConfig(regularPath, sidebarConfig) 135 | return config 136 | ? config.map(item => resolveItem(item, pages, base)) 137 | : [] 138 | } 139 | } 140 | 141 | /** 142 | * @param { Page } page 143 | * @returns { SidebarGroup } 144 | */ 145 | function resolveHeaders (page) { 146 | const headers = groupHeaders(page.headers || []) 147 | return [{ 148 | type: 'group', 149 | collapsable: false, 150 | title: page.title, 151 | path: null, 152 | children: headers.map(h => ({ 153 | type: 'auto', 154 | title: h.title, 155 | basePath: page.path, 156 | path: page.path + '#' + h.slug, 157 | children: h.children || [] 158 | })) 159 | }] 160 | } 161 | 162 | export function groupHeaders (headers) { 163 | // group h3s under h2 164 | headers = headers.map(h => Object.assign({}, h)) 165 | let lastH2 166 | headers.forEach(h => { 167 | if (h.level === 2) { 168 | lastH2 = h 169 | } else if (lastH2) { 170 | (lastH2.children || (lastH2.children = [])).push(h) 171 | } 172 | }) 173 | return headers.filter(h => h.level === 2) 174 | } 175 | 176 | export function resolveNavLinkItem (linkItem) { 177 | return Object.assign(linkItem, { 178 | type: linkItem.items && linkItem.items.length ? 'links' : 'link' 179 | }) 180 | } 181 | 182 | /** 183 | * @param { Route } route 184 | * @param { Array | Array | [link: string]: SidebarConfig } config 185 | * @returns { base: string, config: SidebarConfig } 186 | */ 187 | export function resolveMatchingConfig (regularPath, config) { 188 | if (Array.isArray(config)) { 189 | return { 190 | base: '/', 191 | config: config 192 | } 193 | } 194 | for (const base in config) { 195 | if (ensureEndingSlash(regularPath).indexOf(encodeURI(base)) === 0) { 196 | return { 197 | base, 198 | config: config[base] 199 | } 200 | } 201 | } 202 | return {} 203 | } 204 | 205 | function ensureEndingSlash (path) { 206 | return /(\.html|\/)$/.test(path) 207 | ? path 208 | : path + '/' 209 | } 210 | 211 | function resolveItem (item, pages, base, groupDepth = 1) { 212 | if (typeof item === 'string') { 213 | return resolvePage(pages, item, base) 214 | } else if (Array.isArray(item)) { 215 | return Object.assign(resolvePage(pages, item[0], base), { 216 | title: item[1] 217 | }) 218 | } else { 219 | if (groupDepth > 3) { 220 | console.error( 221 | '[vuepress] detected a too deep nested sidebar group.' 222 | ) 223 | } 224 | const children = item.children || [] 225 | if (children.length === 0 && item.path) { 226 | return Object.assign(resolvePage(pages, item.path, base), { 227 | title: item.title, 228 | icon: item.icon ? item.icon : '' 229 | }) 230 | } 231 | return { 232 | type: 'group', 233 | path: item.path, 234 | title: item.title, 235 | sidebarDepth: item.sidebarDepth, 236 | children: children.map(child => resolveItem(child, pages, base, groupDepth + 1)), 237 | collapsable: item.collapsable !== false, 238 | icon: item.icon ? item.icon : '' 239 | } 240 | } 241 | } 242 | -------------------------------------------------------------------------------- /docs/cli/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | sidebarDepth: 2 3 | --- 4 | 5 | # Cosmic CLI 6 | 7 | This is the official command line tool for [Cosmic](https://cosmicjs.com). Use it to log in to your Cosmic account, manage Buckets, data, files and users within your Buckets, all from the comfort of your command line interface. 8 | 9 | ::: tip Quick Tip 10 | For a quick reference to get content from your Bucket, click the "Developer Tools" button found on select pages in your [Bucket Dashboard ](https://app.cosmicjs.com/login). 11 | 12 | 13 | ::: 14 | 15 | ## Installation 16 | 17 | Install the CLI globally: 18 | 19 | ```bash 20 | npm i -g cosmic-cli 21 | ``` 22 | 23 | To check that it installed properly, run `cosmic` on your command line and you should see a list of commands. 24 | 25 | ## Getting Started 26 | 27 | Let's walk through the commands you need to get started. For an introduction to the Cosmic CLI run the `begin` command. 28 | ```bash 29 | cosmic begin 30 | ``` 31 | 32 | 33 | ### Login 34 | 35 | Use your credentials (from https://cosmicjs.com) to login on the command line. You will only have to do this once. If you used GitHub to sign up, you can also login via authentication token which you can find at https://cosmicjs.com/account/authentication 36 | 37 | ```bash 38 | $ cosmic login 39 | ? Email: starman@gmail.com 40 | ? Password: [hidden] 41 | Authenticated 42 | ``` 43 | 44 | ## Usage 45 | 46 | All Cosmic CLI commands are of the format: 47 | 48 | ```bash 49 | cosmic [command] [options] 50 | ``` 51 | 52 | 53 | ### Use Bucket 54 | 55 | Now that you are logged in, you can connect to any of your Buckets on your account. The `use-bucket` command will set your Bucket config options. You can set your read and write access keys with this command for later use to interact with your Bucket content. Find your Bucket `slug`, `read_key`, and `write_key` access keys in Your Bucket > Settings > API Access after [logging into your account](https://app.cosmicjs.com/login). 56 | 57 | ```bash 58 | $ cosmic use-bucket simple-react-blog --read_key your-read-key --write_key your-write-key 59 | Now using bucket simple-react-blog 60 | ``` 61 | 62 | To test that we connected to the Bucket properly: 63 | 64 | ```bash 65 | $ cosmic get-objects --limit 1 66 | Success 67 | { objects: 68 | [ { _id: '59df6dd5fd8d731b2100118d', 69 | bucket: '59df6dcbfd8d731b21001188', 70 | slug: 'jane-doe', 71 | title: 'Jane Doe', 72 | content: '

Something about Jane...

', 73 | metafields: [Array], 74 | type_slug: 'authors', 75 | created: '2017-10-12T13:27:49.663Z', 76 | created_at: '2017-10-12T13:27:49.663Z', 77 | status: 'published', 78 | metadata: [Object] } ], 79 | limit: 1 } 80 | ``` 81 | 82 | Now you are ready to use any of the commands to have full control over your Bucket! 83 | 84 | 85 | ### Help 86 | 87 | Run `cosmic -h` for a list of all commands. The list is also included at the [bottom of this README](https://github.com/cosmicjs/cosmic-cli#commands). 88 | 89 | Run `cosmic [command] -h` for details on options for a specific command. 90 | 91 | ### Examples 92 | 93 | Below are a few examples of commands. Only a handful of the possible options are shown for the commands. 94 | 95 | **Creating an Object Type and then an Object** 96 | 97 | Creating a "Planets" Object Type and specifying default Metafields all Objects in this Object Type should have. For this example all planets will now include the Metafield titled "Radius". See the [REST API docs](/rest-api/metafields.html) for all Metafield options. 98 | ```bash 99 | $ cosmic add-object-type --slug planets --title Planets --metafields '[{"title": "Radius","type":"text", "key": "radius"}]' 100 | ``` 101 | 102 | Making an edit to the Object Type. This example adds another Metafield to the "Planets" Object Type. 103 | ```bash 104 | $ cosmic edit-object-type -s planets --metafields '[{"title": "Radius","type":"text", "key": "radius"},{"title": "Distance from Sun","type":"text", "key": "distance_from_sun"}]' 105 | ``` 106 | 107 | Creating an Object in the "Planets" Object Type: 108 | ```bash 109 | $ cosmic add-object --type_slug planets --title Venus --metafields '[{"title": "Radius","type":"text", "key": "radius", "value": "3,760 miles"},{"title": "Distance from Sun","type":"text", "key": "distance_from_sun", "value": "67.24 million miles"}]' 110 | ``` 111 | 112 | **Uploading Files to a Bucket** 113 | 114 | We upload any file from our computer to Cosmic with the name provided to -t, and into a specified folder (optional). 115 | 116 | Using shorthand params -f for --file and -t for --title 117 | ```bash 118 | $ cosmic add-media -f ./my-cat.png -t my-cat.png --folder cat-images 119 | ``` 120 | 121 | ### JSON String Inputs 122 | 123 | Some commands allow for two types of input: argument based and json string based. This is best illustrated with an example: 124 | 125 | To add a new barebones Object with only a title that is of Object Type `planets`, there are two ways we could go about it, with equivalent results: 126 | 127 | ```bash 128 | $ cosmic add-object --type_slug planets --title Venus 129 | ``` 130 | 131 | or 132 | 133 | ```bash 134 | $ cosmic add-object --json '{"type_slug": "planets", "title": "Venus"}' 135 | ``` 136 | 137 | The json string option is convenient in some use cases, and is included on the following commands: 138 | 139 | * add-object 140 | * add-object-type 141 | * edit-object 142 | * edit-object-type 143 | 144 | 145 | ### Commands 146 | 147 | For a list of the options for a command, use `cosmic [command] -h` 148 | 149 | * begin `Guide to Getting Started` 150 | * login 151 | * which-user `outputs the email of the current user` 152 | * which-bucket `outputs the slug of the current Bucket` 153 | * which-app `outputs the slug of the current app` 154 | * get-buckets [options] `shows Buckets available to user` 155 | * install-app `installs an app to your bucket and downloads the repo to your machine` 156 | * deploy-app [options] `deploys an app to the Cosmic App Server` 157 | * view-app `Opens browser window with demo link` 158 | * browse-apps [options] `search for apps or see all` 159 | * start-app `starts a downloaded app on your machine` 160 | * get-bucket [options] `get current bucket object` 161 | * use-bucket [options] [slug] 162 | * add-bucket [options] 163 | * delete-bucket [options] 164 | * get-objects [options] 165 | * get-object [options] 166 | * get-object-types 167 | * add-object-type [options] 168 | * edit-object-type [options] 169 | * delete-object-type [options] 170 | * add-object [options] 171 | * edit-object [options] 172 | * delete-object [options] 173 | * add-media [options] 174 | * get-media [options] 175 | * delete-media [options] 176 | * add-webhook [options] 177 | * delete-webhook [options] 178 | * add-user [options] -------------------------------------------------------------------------------- /docs/rest-api/users.md: -------------------------------------------------------------------------------- 1 | # Users 2 | 3 | ## Add User to Bucket 4 | 5 | Add a user to your Bucket. Authentication token is required and must have admin level access. 6 | 7 | | Parameter | Required | Type | Description | 8 | | ---------- | -------- | ------ | ----------------------------------------------------------- | 9 | | email | required | String | The new user's email | 10 | | role | required | Enum | admin, developer, editor or contributor | 11 | | first_name | | String | The new user's first name | 12 | | last_name | | String | The new user's last name | 13 | 14 | :::: tabs :options="{ useUrlFragment: false }" 15 | 16 | ::: tab Bash 17 | **Definition** 18 | 19 | ``` 20 | POST https://api.cosmicjs.com/v1/:bucket_slug/users 21 | ``` 22 | 23 | **Example Request** 24 | 25 | ```json 26 | { 27 | "email": "newuser@example.com", 28 | "role": "editor" 29 | } 30 | ``` 31 | 32 | **Example Response** 33 | 34 | ```json 35 | { 36 | "status": 200, 37 | "message": "User added." 38 | } 39 | ``` 40 | 41 | ::: 42 | 43 | ::: tab Node.js 44 | **Definition** 45 | 46 | ```js 47 | bucket.addUser() 48 | ``` 49 | 50 | **Example Request** 51 | 52 | ```js 53 | const bucket = Cosmic.bucket({ 54 | slug: 'bucket-slug', 55 | write_key: '' 56 | }) 57 | const params = { 58 | email: 'newuser@example.com', 59 | role: 'editor', 60 | first_name: 'Quasar', 61 | last_name: 'Jones' 62 | } 63 | bucket.addUser(params) 64 | .then(data => { 65 | console.log(data) 66 | }) 67 | .catch(err => { 68 | console.log(err) 69 | }) 70 | ``` 71 | 72 | **Example Response** 73 | 74 | ```json 75 | { 76 | "status": 200, 77 | "message": "User added." 78 | } 79 | ``` 80 | 81 | ::: 82 | 83 | :::: 84 | 85 | ## Get Users 86 | 87 | Get users in your Bucket. Authentication token is required in the header (see Authentication section). Must have admin level access. 88 | 89 | :::: tabs :options="{ useUrlFragment: false }" 90 | 91 | ::: tab Bash 92 | **Definition** 93 | 94 | ``` 95 | GET https://api.cosmicjs.com/v1/:bucket_slug/users 96 | ``` 97 | 98 | **Example Request** 99 | 100 | ```bash 101 | curl "https://api.cosmicjs.com/v1/creative-agency/users" \ 102 | -H "Authorization: Bearer " 103 | ``` 104 | 105 | **Example Response** 106 | 107 | ```json 108 | { 109 | "users": [ 110 | { 111 | "_id": "5357ef811693be2118000001", 112 | "first_name": "Starman", 113 | "last_name": "Jones", 114 | "email": "starman@milkyway.com", 115 | "username": "starman", 116 | "bio": "Enjoy traveling at the speed of light, black holes and supernovas are my jam.", 117 | "avatar_url": "https://cosmicjs.imgix.net/1c3690c0-9dbc-11e7-b30d-b3b3f0076a4f-me.jpg", 118 | "website": "https://starman.com", 119 | "twitter": "https://twitter.com/starman", 120 | "linkedin": "http://linkedin.com/in/starman", 121 | "github": "http://github.com/starman", 122 | "company": "Starman Inc.", 123 | "location": "Neptune" 124 | }, 125 | { 126 | "_id": "56d66b2f903a79b904000001", 127 | "first_name": "Quasar", 128 | "last_name": "Jones", 129 | "email": "quasar@milkyway.com", 130 | "username": "quasar", 131 | "bio": "I contain massive black holes and may evolve into a galaxy.", 132 | "avatar_url": "https://cosmic-s3.imgix.net/08544a00-eaa3-11e7-8c73-5dadcfada90e-wave.jpg", 133 | "website": "https://quasar.com", 134 | "twitter": "https://twitter.com/quasar", 135 | "linkedin": "http://linkedin.com/in/quasar", 136 | "github": "http://github.com/quasar", 137 | "company": "Quasar Inc.", 138 | "location": "Titan" 139 | } 140 | ], 141 | "total": 2 142 | } 143 | ``` 144 | 145 | ::: 146 | 147 | ::: tab Node.js 148 | **Definition** 149 | 150 | ```js 151 | bucket.getUsers() 152 | ``` 153 | 154 | **Example Request** 155 | 156 | ```js 157 | const bucket = Cosmic.bucket({ 158 | slug: 'bucket-slug' 159 | }) 160 | bucket.getUsers() 161 | .then(data => { 162 | console.log(data) 163 | }) 164 | .catch(err => { 165 | console.log(err) 166 | }) 167 | ``` 168 | 169 | **Example Response** 170 | 171 | ```json 172 | { 173 | "users": [ 174 | { 175 | "_id": "5357ef811693be2118000001", 176 | "first_name": "Starman", 177 | "last_name": "Jones", 178 | "email": "starman@milkyway.com", 179 | "username": "starman", 180 | "bio": "Enjoy traveling at the speed of light, black holes and supernovas are my jam.", 181 | "avatar_url": "https://cosmicjs.imgix.net/1c3690c0-9dbc-11e7-b30d-b3b3f0076a4f-me.jpg", 182 | "website": "https://starman.com", 183 | "twitter": "https://twitter.com/starman", 184 | "linkedin": "http://linkedin.com/in/starman", 185 | "github": "http://github.com/starman", 186 | "company": "Starman Inc.", 187 | "location": "Neptune" 188 | }, 189 | { 190 | "_id": "56d66b2f903a79b904000001", 191 | "first_name": "Quasar", 192 | "last_name": "Jones", 193 | "email": "quasar@milkyway.com", 194 | "username": "quasar", 195 | "bio": "I contain massive black holes and may evolve into a galaxy.", 196 | "avatar_url": "https://cosmic-s3.imgix.net/08544a00-eaa3-11e7-8c73-5dadcfada90e-wave.jpg", 197 | "website": "https://quasar.com", 198 | "twitter": "https://twitter.com/quasar", 199 | "linkedin": "http://linkedin.com/in/quasar", 200 | "github": "http://github.com/quasar", 201 | "company": "Quasar Inc.", 202 | "location": "Titan" 203 | } 204 | ], 205 | "total": 2 206 | } 207 | ``` 208 | 209 | ::: 210 | 211 | :::: 212 | 213 | ## Get User 214 | 215 | Get a single user from your Bucket. Authentication token is required in the header (see Authentication section). Must have admin level access. 216 | 217 | | Parameter | Required | Type | Description | 218 | | --------- | -------- | ------ | -------------------------------- | 219 | | id | required | String | User's id (found as `_id` param) | 220 | 221 | :::: tabs :options="{ useUrlFragment: false }" 222 | 223 | ::: tab Bash 224 | **Definition** 225 | 226 | ``` 227 | GET https://api.cosmicjs.com/v1/:bucket_slug/users/:user_id 228 | ``` 229 | 230 | **Example Response** 231 | 232 | ```json 233 | { 234 | "user": { 235 | "_id": "5357ef811693be2118000001", 236 | "first_name": "Starman", 237 | "last_name": "Jones", 238 | "email": "starman@milkyway.com", 239 | "username": "starman", 240 | "bio": "Enjoy traveling at the speed of light, black holes and supernovas are my jam.", 241 | "avatar_url": "https://cosmicjs.imgix.net/1c3690c0-9dbc-11e7-b30d-b3b3f0076a4f-me.jpg", 242 | "website": "https://starman.com", 243 | "twitter": "https://twitter.com/starman", 244 | "linkedin": "http://linkedin.com/in/starman", 245 | "github": "http://github.com/starman", 246 | "company": "Starman Inc.", 247 | "location": "Neptune" 248 | } 249 | } 250 | ``` 251 | 252 | ::: 253 | 254 | ::: tab Node.js 255 | **Definition** 256 | 257 | ```js 258 | bucket.getUser()const bucket = Cosmic.bucket({ 259 | slug: 'bucket-slug' 260 | }) 261 | const params = { 262 | id: '5357ef811693be2118000001' 263 | } 264 | bucket.getUser(params).then(data => { 265 | console.log(data) 266 | }).catch(err => { 267 | console.log(err) 268 | }) 269 | ``` 270 | 271 | **Example Response** 272 | 273 | ```json 274 | { 275 | "user": { 276 | "_id": "5357ef811693be2118000001", 277 | "first_name": "Starman", 278 | "last_name": "Jones", 279 | "email": "starman@milkyway.com", 280 | "username": "starman", 281 | "bio": "Enjoy traveling at the speed of light, black holes and supernovas are my jam.", 282 | "avatar_url": "https://cosmicjs.imgix.net/1c3690c0-9dbc-11e7-b30d-b3b3f0076a4f-me.jpg", 283 | "website": "https://starman.com", 284 | "twitter": "https://twitter.com/starman", 285 | "linkedin": "http://linkedin.com/in/starman", 286 | "github": "http://github.com/starman", 287 | "company": "Starman Inc.", 288 | "location": "Neptune" 289 | } 290 | } 291 | ``` 292 | 293 | ::: 294 | 295 | :::: 296 | -------------------------------------------------------------------------------- /docs/rest-api/object-types.md: -------------------------------------------------------------------------------- 1 | # Object Types 2 | 3 | ## Add Object Type 4 | 5 | Add a new Object Type to your Bucket. 6 | 7 | | Parameter | Required | Type | Description | 8 | | ---------- | -------- | ------ | ----------------------------------------------- | 9 | | title | required | String | Plural title of your Object Type | 10 | | slug | | String | Plural slug of your Object Type | 11 | | singular | | String | Singular title of your Object Type | 12 | | emoji | | String | Valid Unicode emoji | 13 | | singleton | | Boolean | Single or Multiple Objects | 14 | | metafields | | Array | Default Metafields for each Object in this type | 15 | | pretty | | Enum | true, Makes the response more reader-friendly | 16 | | write_key | | String | Restrict write access to your Bucket | 17 | 18 | :::: tabs :options="{ useUrlFragment: false }" 19 | 20 | ::: tab Bash 21 | **Definition** 22 | 23 | ``` 24 | POST https://api.cosmicjs.com/v1/:bucket_slug/add-object-type 25 | ``` 26 | 27 | **Example Request** 28 | 29 | ```json 30 | { 31 | "title": "Pages", 32 | "singular": "Page", 33 | "slug": "pages", 34 | "emoji": "📄", 35 | "singleton": false, 36 | "metafields": [ 37 | { 38 | "type": "text", 39 | "title": "Headline", 40 | "key": "headline", 41 | "required": true 42 | }, 43 | { 44 | "type": "file", 45 | "title": "Hero", 46 | "key": "hero", 47 | "required": true 48 | } 49 | ] 50 | } 51 | ``` 52 | 53 | **Example Response** 54 | 55 | ```json 56 | { 57 | "object_type": { 58 | "slug": "pages", 59 | "title": "Pages", 60 | "singular": "Page", 61 | "emoji": "📄", 62 | "singleton": false, 63 | "metafields": [ 64 | { 65 | "type": "text", 66 | "title": "Headline", 67 | "key": "headline", 68 | "required": true 69 | }, 70 | { 71 | "type": "file", 72 | "title": "Hero", 73 | "key": "hero", 74 | "required": true 75 | } 76 | ], 77 | "created_at": "2017-05-30T02:06:35.373Z", 78 | "metadata": null 79 | } 80 | } 81 | ``` 82 | 83 | ::: 84 | 85 | ::: tab Node.js 86 | 87 | ::: 88 | **Definition** 89 | 90 | ```js 91 | bucket.addObjectType() 92 | ``` 93 | 94 | **Example Request** 95 | 96 | ```js 97 | const bucket = Cosmic.bucket({ 98 | slug: 'bucket-slug', 99 | write_key: '' 100 | }) 101 | const params = { 102 | title: 'Pages', 103 | singular: 'Page', 104 | slug: 'pages', 105 | emoji: '📄', 106 | singleton: false, 107 | metafields: [ 108 | { 109 | type: 'text', 110 | title: 'Headline', 111 | key: 'headline', 112 | required: true 113 | }, 114 | { 115 | type: 'file', 116 | title: 'Hero', 117 | key: 'hero', 118 | required: true 119 | } 120 | ] 121 | } 122 | bucket.addObjectType(params) 123 | .then(data => { 124 | console.log(data) 125 | }) 126 | .catch(err => { 127 | console.log(err) 128 | }) 129 | ``` 130 | 131 | **Example Response** 132 | 133 | ```json 134 | { 135 | "object_type": { 136 | "slug": "pages", 137 | "title": "Pages", 138 | "singular": "Page", 139 | "emoji": "📄", 140 | "singleton": false, 141 | "metafields": [ 142 | { 143 | "type": "text", 144 | "title": "Headline", 145 | "key": "headline", 146 | "required": true 147 | }, 148 | { 149 | "type": "file", 150 | "title": "Hero", 151 | "key": "hero", 152 | "required": true 153 | } 154 | ], 155 | "created_at": "2017-05-30T02:06:35.373Z", 156 | "metadata": null 157 | } 158 | } 159 | ``` 160 | 161 | :::: 162 | 163 | ## Get Object Types 164 | 165 | Get all Object Types in your Bucket. 166 | 167 | | Parameter | Required | Type | Description | 168 | | --------- | -------- | ------ | --------------------------------------------- | 169 | | pretty | | Enum | true, Makes the response more reader-friendly | 170 | | read_key | | String | Restrict read access to your Bucket | 171 | 172 | :::: tabs :options="{ useUrlFragment: false }" 173 | 174 | ::: tab Bash 175 | **Definition** 176 | 177 | ``` 178 | GET https://api.cosmicjs.com/v1/:bucket_slug/object-types 179 | ``` 180 | 181 | **Example Request** 182 | ``` 183 | curl "https://api.cosmicjs.com/v1/wedding-site/object-types" 184 | ``` 185 | ::: 186 | 187 | ::: tab Node.js 188 | **Definition** 189 | 190 | ```js 191 | bucket.getObjectTypes() 192 | ``` 193 | 194 | **Example Request** 195 | 196 | 197 | 198 | ::: 199 | 200 | :::: 201 | 202 | ## Edit Object Type 203 | 204 | Edit an existing Object Type in your Bucket. 205 | 206 | | Parameter | Required | Type | Description | 207 | | ---------- | -------- | ------ | ----------------------------------------------- | 208 | | slug | required | String | Plural slug of your Object Type | 209 | | title | | String | Singular title of your Object Type | 210 | | singular | | String | Singular title of your Object Type | 211 | | emoji | | String | Valid Unicode emoji | 212 | | singleton | | Boolean | Single or Multiple Objects | 213 | | metafields | | Array | Default Metafields for each Object in this type | 214 | | pretty | | Enum | true, Makes the response more reader-friendly | 215 | | write_key | | String | Restrict write access to your Bucket | 216 | 217 | :::: tabs :options="{ useUrlFragment: false }" 218 | 219 | ::: tab Bash 220 | **Definition** 221 | 222 | ``` 223 | PUT https://api.cosmicjs.com/v1/:bucket_slug/edit-object-type 224 | ``` 225 | 226 | **Example Request** 227 | 228 | ```json 229 | { 230 | "slug": "pages", 231 | "metafields": [ 232 | { 233 | "type": "text", 234 | "title": "Headline", 235 | "key": "headline", 236 | "required": true 237 | }, 238 | { 239 | "type": "file", 240 | "title": "Hero", 241 | "key": "hero", 242 | "required": true 243 | }, 244 | { 245 | "type": "text", 246 | "title": "Tagline", 247 | "key": "tagline", 248 | "required": true 249 | } 250 | ] 251 | } 252 | ``` 253 | 254 | **Example Response** 255 | 256 | ```json 257 | { 258 | "object_type": { 259 | "slug": "pages", 260 | "title": "Pages", 261 | "singular": "Page", 262 | "metafields": [ 263 | { 264 | "type": "text", 265 | "title": "Headline", 266 | "key": "headline", 267 | "required": true 268 | }, 269 | { 270 | "type": "file", 271 | "title": "Hero", 272 | "key": "hero", 273 | "required": true 274 | }, 275 | { 276 | "type": "text", 277 | "title": "Tagline", 278 | "key": "tagline", 279 | "required": true 280 | } 281 | ], 282 | "modified_at": "2017-05-30T02:10:35.373Z", 283 | "created_at": "2017-05-30T02:06:35.373Z", 284 | "metadata": null 285 | } 286 | } 287 | ``` 288 | 289 | ::: 290 | 291 | ::: tab Node.js 292 | **Definition** 293 | 294 | ```js 295 | bucket.editObjectType() 296 | ``` 297 | 298 | **Example Request** 299 | 300 | ```js 301 | const bucket = Cosmic.bucket({ 302 | slug: 'bucket-slug', 303 | write_key: '' 304 | }) 305 | bucket.editObjectType({ 306 | slug: 'posts', 307 | title: 'New Posts Title' 308 | }) 309 | .then(data => { 310 | console.log(data) 311 | }) 312 | .catch(err => { 313 | console.log(err) 314 | }) 315 | ``` 316 | 317 | **Example Response** 318 | 319 | ```json 320 | { 321 | "object_type": { 322 | "slug": "pages", 323 | "title": "Pages", 324 | "singular": "Page", 325 | "metafields": [ 326 | { 327 | "type": "text", 328 | "title": "Headline", 329 | "key": "headline", 330 | "required": true 331 | }, 332 | { 333 | "type": "file", 334 | "title": "Hero", 335 | "key": "hero", 336 | "required": true 337 | }, 338 | { 339 | "type": "text", 340 | "title": "Tagline", 341 | "key": "tagline", 342 | "required": true 343 | } 344 | ], 345 | "modified_at": "2017-05-30T02:10:35.373Z", 346 | "created_at": "2017-05-30T02:06:35.373Z", 347 | "metadata": null 348 | } 349 | } 350 | ``` 351 | 352 | ::: 353 | 354 | :::: 355 | 356 | ## Delete Object Type 357 | 358 | Delete an existing Object Type from your Bucket. \* This does not delete Objects in this Object Type. 359 | 360 | | Parameter | Required | Type | Description | 361 | | --------- | -------- | ------ | ------------------------------------ | 362 | | write_key | | String | Restrict write access to your Bucket | 363 | 364 | :::: tabs :options="{ useUrlFragment: false }" 365 | 366 | ::: tab Bash 367 | **Definition** 368 | 369 | ``` 370 | DELETE https://api.cosmicjs.com/v1/:bucket_slug/object-types/:type_slug 371 | ``` 372 | 373 | _Example Request Body_ 374 | 375 | ```json 376 | { 377 | "write_key": "your-write-key-found-in-bucket-settings" // optional 378 | } 379 | ``` 380 | 381 | **Example Response** 382 | 383 | ```json 384 | { 385 | "status": "200", 386 | "message": "Object Type deleted." 387 | } 388 | ``` 389 | 390 | ::: 391 | 392 | ::: tab Node.js 393 | **Definition** 394 | 395 | ```js 396 | bucket.deleteObjectType() 397 | ``` 398 | 399 | **Example Request Body** 400 | 401 | ```js 402 | const bucket = Cosmic.bucket({ 403 | slug: 'bucket-slug', 404 | write_key: '' 405 | }) 406 | bucket.deleteObjectType({ 407 | slug: 'posts' 408 | }) 409 | .then(data => { 410 | console.log(data) 411 | }) 412 | .catch(err => { 413 | console.log(err) 414 | }) 415 | ``` 416 | 417 | **Example Response** 418 | 419 | ```json 420 | { 421 | "status": "200", 422 | "message": "Object Type deleted." 423 | } 424 | ``` 425 | 426 | ::: 427 | 428 | :::: 429 | -------------------------------------------------------------------------------- /docs/rest-api/media.md: -------------------------------------------------------------------------------- 1 | # Media 2 | 3 | ## Add Media 4 | 5 | The only required post value is the `media` object. You can also add optional `folder` and `metadata` params. 6 | 7 | ::: tip NOTE: 8 | The base endpoint is different than other REST API requests with a higher upload size limit of `900MB`. 9 | ::: 10 | 11 | ``` 12 | https://upload.cosmicjs.com/v1 13 | ``` 14 | 15 | | Parameter | Required | Type | Description | 16 | | --------- | -------- | ------------------------ | ------------------------------------- | 17 | | media | required | Media Object (see below) | Media object with specific properties | 18 | | folder | | String | Media folder slug | 19 | | metadata | | Object | Key / value data store | 20 | | write_key | | String | Your Bucket write key | 21 | 22 | :::: tabs :options="{ useUrlFragment: false }" 23 | 24 | ::: tab Bash 25 | **Definition** 26 | 27 | ``` 28 | POST https://upload.cosmicjs.com/v1/:bucket_slug/media 29 | ``` 30 | 31 | **Example Request** 32 | ```bash 33 | curl --form "folder=folder-name" --form "media=@test.png" --form "write_key=" 'https://api.cosmicjs.com/v1/:bucket_slug/media' 34 | ``` 35 | 36 | **Example Response** 37 | 38 | ```json 39 | { 40 | "media": { 41 | "name": "c20391e0-b8a4-11e6-8836-fbdfd6956b31-test.png", 42 | "original_name": "test.png", 43 | "size": 457307, 44 | "folder": "folder-name", 45 | "type": "image/png", 46 | "bucket": "5839c67f0d3201c114000004", 47 | "created": "2016-12-02T15:34:05.054Z", 48 | "location": "https://cdn.cosmicjs.com", 49 | "url": "https://cdn.cosmicjs.com/c20391e0-b8a4-11e6-8836-fbdfd6956b31-test.png", 50 | "imgix_url": "https://cosmic-s3.imgix.net/c20391e0-b8a4-11e6-8836-fbdfd6956b31-test.png" 51 | } 52 | } 53 | ``` 54 | 55 | ::: 56 | 57 | ::: tab Node.js 58 | **Definition** 59 | 60 | ```js 61 | bucket.addMedia() 62 | ``` 63 | 64 | **Example Request** 65 | 66 | ```js 67 | const bucket = Cosmic.bucket({ 68 | slug: 'bucket-slug', 69 | write_key: '' 70 | }) 71 | 72 | const media_object = req.files[0] // Using Multer 73 | // OR: 74 | // const media_object = { originalname: filename, buffer: filedata } // Not using Multer 75 | 76 | bucket.addMedia({ 77 | media: media_object, 78 | folder: 'your-folder-slug', 79 | metadata: { 80 | caption: 'Beautiful picture of the beach', 81 | credit: 'Tyler Jackson' 82 | } 83 | }) 84 | .then(data => { 85 | console.log(data) 86 | }) 87 | .catch(err => { 88 | console.log(err) 89 | }) 90 | 91 | /* 92 | As an example, another popular upload library for express is [express-fileupload](https://www.npmjs.com/package/express-fileupload). File objects obtained through this have the following properties: 93 | req.files.foo.name: "car.jpg" 94 | req.files.foo.mimetype: The mimetype of your file 95 | req.files.foo.data: A buffer representation of your file 96 | */ 97 | 98 | // In order to pass the file `req.files.foo` to Cosmic you would do: 99 | const media_object = { 100 | originalname: req.files.foo.name, 101 | buffer: req.files.foo.data 102 | } 103 | ``` 104 | 105 | **Example Response** 106 | 107 | ```json 108 | { 109 | "media": { 110 | "name": "c20391e0-b8a4-11e6-8836-fbdfd6956b31-bird.jpg", 111 | "original_name": "bird.jpg", 112 | "size": 457307, 113 | "type": "image/jpeg", 114 | "bucket": "5839c67f0d3201c114000004", 115 | "created": "2016-12-02T15:34:05.054Z", 116 | "location": "https://cosmicjs.com/uploads", 117 | "url": "https://cdn.cosmicjs.com/c20391e0-b8a4-11e6-8836-fbdfd6956b31-bird.jpg", 118 | "imgix_url": "https://cosmic-s3.imgix.net/c20391e0-b8a4-11e6-8836-fbdfd6956b31-bird.jpg", 119 | "metadata": [ 120 | { 121 | "key": "caption", 122 | "value": "Beautiful picture of the beach" 123 | }, 124 | { 125 | "key": "credit", 126 | "value": "Tyler Jackson" 127 | } 128 | ] 129 | } 130 | } 131 | ``` 132 | 133 | ::: 134 | 135 | :::: 136 | 137 | ### Server-side Multer Example 138 | 139 | This application uses Express and Multer to create a route `POST http://localhost:5000/upload` that will upload a file to your Bucket Media area. This is an example from the article [Upload Media to Your Cosmic Bucket Using Multer](https://www.cosmicjs.com/articles/upload-media-to-your-cosmic-js-bucket-using-multer-jzoddl9p). 140 | 141 | ```js 142 | // index.js 143 | const fs = require('fs') 144 | const Cosmic = require('cosmicjs')() 145 | const multer = require('multer') 146 | const express = require('express') 147 | var app = express() 148 | const bucket = Cosmic.bucket({ 149 | slug: 'your-bucket-slug', 150 | write_key: 'your-bucket-write-key' 151 | }) 152 | var storage = multer.diskStorage({ 153 | destination: function (req, file, cb) { 154 | cb(null, __dirname + '/uploads') 155 | }, 156 | filename: function (req, file, cb) { 157 | cb(null, file.fieldname + '-' + Date.now()) 158 | } 159 | }) 160 | var upload = multer({ storage: storage }) 161 | app.post('/upload', upload.single('file'), async function(req, res) { 162 | try { 163 | const media_object = { 164 | originalname: req.file.originalname, 165 | buffer: fs.createReadStream(req.file.path) 166 | } 167 | const response = await bucket.addMedia({ media: media_object }); 168 | return res.json(response); 169 | } catch (e) { 170 | console.log(e) 171 | } 172 | }); 173 | app.listen(5000); 174 | 175 | ``` 176 | 177 | ### Media Object 178 | 179 | The Media Object must be an object with certain properties indicated below. If using the [multer NPM module](https://www.npmjs.com/package/multer) the file objects have these by default. Otherwise you should create an object with these properties: 180 | 181 | | Parameter | Required | Type | Description | 182 | | ------------ | -------- | ----------- | ------------------------------------- | 183 | | originalname | required | String | The name of your file (something.jpg) | 184 | | buffer | | File Buffer | The File Buffer | 185 | 186 | ### Client-side React Dropzone Example 187 | React Dropzone is a popular file uploader on the client-side. For implementation, read the [React Dropzone docs on GitHub](https://github.com/react-dropzone/react-dropzone/). 188 | 189 | ::: tip Quick Tip 190 | To use the following example, get your Bucket slug and keys located in Bucket > Settings in your [Bucket Dashboard ](https://app.cosmicjs.com/login). 191 | ::: 192 | 193 | [View full screen / fork on StackBlitz ](https://stackblitz.com/edit/react-dropzone-cosmic) 194 | 195 | 196 | 197 | 198 | ## Get Media 199 | 200 | Get Media from your Bucket. You can add the folder parameter to get Media from a certain folder. 201 | 202 | ::: tip Quick Tip 203 | For a quick reference to this endpoint click the "Developer Tools" button on your Media table view in your [Bucket Dashboard ](https://app.cosmicjs.com/login). 204 | 205 | 206 | ::: 207 | 208 | | Parameter | Required | Type | Description | 209 | | --------- | -------- | ------ | -------------------- | 210 | | pretty | | File | Media object | 211 | | folder | | String | Media folder slug | 212 | | read_key | | String | Your Bucket read key | 213 | 214 | :::: tabs :options="{ useUrlFragment: false }" 215 | 216 | ::: tab Bash 217 | **Definition** 218 | 219 | ``` 220 | GET https://api.cosmicjs.com/v1/:bucket_slug/media 221 | ``` 222 | 223 | **Example Request** 224 | 225 | ```bash 226 | curl "https://api.cosmicjs.com/v1/wedding-site/media?pretty=true&folder=groomsmen&limit=3" 227 | ``` 228 | 229 | ::: 230 | 231 | ::: tab Node.js 232 | **Definition** 233 | 234 | ```js 235 | Cosmic.getMedia() 236 | ``` 237 | 238 | **Example Request** 239 | 240 | 241 | ::: 242 | 243 | :::: 244 | 245 | 246 | ### Imgix 247 | 248 | [Imgix](https://imgix.com/) is included with every account. You can use the Imgix suite of image processing tools on the URL provided by the `imgix_url` property value. Check out the [Imgix documentation](https://docs.imgix.com/) for more info. 249 | 250 | ## Delete Media 251 | 252 | If a write key is enabled on the requested bucket, the parameter `write_key` will need to be present. 253 | 254 | | Parameter | Required | Type | Description | 255 | | --------- | -------- | ------ | --------------------- | 256 | | write_key | | String | Your Bucket write key | 257 | | trigger_webhook | | Bool | Triggers corresponding Object action Webhook ([See Webhooks](/rest-api/webhooks.html#add-webhook)) | 258 | 259 | :::: tabs :options="{ useUrlFragment: false }" 260 | 261 | ::: tab Bash 262 | **Definition** 263 | 264 | ``` 265 | DELETE https://api.cosmicjs.com/v1/:bucket_slug/media/:media_id 266 | ``` 267 | 268 | **Example Request** 269 | 270 | ```json 271 | curl -X DELETE "https://api.cosmicjs.com/v1/bucket-slug/media/media_id" -d '{ "write_key": "your-write-key-found-in-bucket-settings" }' -H "Content-type: application/json" 272 | ``` 273 | 274 | **Example Response** 275 | 276 | ```json 277 | { 278 | "status": "200", 279 | "message": "Media deleted." 280 | } 281 | ``` 282 | 283 | ::: 284 | 285 | ::: tab Node.js 286 | **Definition** 287 | 288 | ```js 289 | Cosmic.deleteMedia() 290 | ``` 291 | 292 | **Example Request** 293 | 294 | ```js 295 | const bucket = Cosmic.bucket({ 296 | slug: 'bucket-slug', 297 | write_key: '' 298 | }) 299 | bucket.deleteMedia({ 300 | id: '5a4b18e12fff7ec0e3c13c65' 301 | }) 302 | .then(data => { 303 | console.log(data) 304 | }) 305 | .catch(err => { 306 | console.log(err) 307 | }) 308 | ``` 309 | 310 | **Example Response** 311 | 312 | ```json 313 | { 314 | "status": "200", 315 | "message": "Media deleted." 316 | } 317 | ``` 318 | 319 | ::: 320 | 321 | :::: 322 | -------------------------------------------------------------------------------- /docs/graphql-api/queries.md: -------------------------------------------------------------------------------- 1 | # Queries 2 | 3 | ::: tip Quick Tip 4 | For a quick reference to this endpoint click the "Developer Tools" button on your Objects table view in your [Bucket Dashboard ](https://app.cosmicjs.com/login). 5 | 6 | 7 | ::: 8 | 9 | ## getObjects 10 | Get Objects from a Bucket. 11 | 12 | ``` 13 | getObjects(bucket_slug, input) 14 | ``` 15 | 16 | ### Try it 17 | **[Full screen  ](https://cosmic-graphql-playground.netlify.com/?endpoint=https%3A%2F%2Fgraphql.cosmicjs.com%2Fv2&query=%7B%0A%20%20getObjects%28%0A%20%20%20%20bucket_slug%3A%20%22simple-react-blog%22%2C%0A%20%20%20%20input%3A%20%7B%20%0A%20%20%20%20%20%20type%3A%20%22posts%22%0A%20%20%20%20%7D%0A%20%20%29%20%7B%0A%20%20%20%20%20objects%20%7B%0A%20%20%20%20%20%20title%0A%20%20%20%20%20%20content%0A%20%20%20%20%7D%0A%20%20%20%20total%0A%20%20%7D%0A%7D)** 18 | 19 | 20 | 21 | ### Advanced Queries (Beta) 22 | Advanced queries give you powerful NoSQL database-like functionality for content fetching. Use the `query` parameter to send a valid JSON (stringified) query on the [Get Objects Method](#getobjects). 23 | 24 | ### Available Keys to Query 25 | 26 | | Parameter | Description | 27 | | --------------- | ----------------------------------------------| 28 | | _id | Object _id | 29 | | title | Object Title | 30 | | slug | Object Slug | 31 | | content | Object Content | 32 | | created_at | Object Created at Date | 33 | | published_at | Object Published at Date | 34 | | modified_at | Object Modified at Date | 35 | | created_by | Object Created by user id | 36 | | modified_by | Object Modified by user id | 37 | | metadata.$key | Metadata value(s) | 38 | 39 | ### Query Selectors 40 | 41 | | Parameter | Description | 42 | | --------------- | ----------------------------------------------| 43 | | $eq | Matches values that are equal to a specified value. Equivalent to direct key/value query.| 44 | | $gt | Matches values that are greater than a specified value.| 45 | | $gte | Matches values that are greater than or equal to a specified value.| 46 | | $lt | Matches values that are less than a specified value. | 47 | | $lte | Matches values that are less than or equal to a specified value. | 48 | | $in | Matches any of the values specified in an array. | 49 | | $ne | Matches all values that are not equal to a specified value. | 50 | | $nin | Matches none of the values specified in an array.| 51 | | $all | Matches arrays that contain all elements specified in the query.| 52 | | $regex, $options | Search for string, use `$options: "i"` for case insensitive matches | 53 | 54 | 55 | ### Logic Operators 56 | 57 | | Parameter | Description | 58 | | --------------- | ----------------------------------------------| 59 | | $and | Returns Objects that match all conditions | 60 | | $or | Returns Objects that match any conditions | 61 | 62 | 63 | ### Try it 64 | Some queries will require a separate variable. Add something like this to the Query Variables area: 65 | ``` 66 | { 67 | "query": { 68 | "title": { 69 | "$regex": "another", 70 | "$options": "i" 71 | } 72 | } 73 | } 74 | ``` 75 | **[Full screen  ](https://cosmic-graphql-playground.netlify.app/?endpoint=https%3A%2F%2Fgraphql.cosmicjs.com%2Fv2&query=%20query%20%28%24query%3A%20JSON%29%20%7B%0A%20%20%20%20getObjects%28%0A%20%20%20%20%20%20%20%20bucket_slug%3A%20%22simple-react-blog%22%2C%0A%20%20%20%20%20%20%20%20input%3A%20%7B%20%0A%20%20%20%20%20%20%20%20%20%20type%3A%22posts%22%0A%20%20%20%20%20%20%20%20%20%20query%3A%20%24query%0A%20%20%20%20%20%20%20%20%20%20props%3A%20%22title%2Cslug%2Cmetadata.author%22%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%29%20%7B%0A%20%20%20%20objects%20%7B%0A%20%20%20%20%20%20%20%20title%0A%20%20%20%20%20%20%09slug%0A%20%20%20%20%20%20%20%20metadata%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D)** 76 | 77 | 78 | 79 | ### More Examples 80 | [See more Advanced Queries examples in the REST API docs](/rest-api/objects.html#example-queries). 81 | 82 | 83 | ## getObject 84 | Get a single Object from a Bucket. 85 | ``` 86 | getObject(bucket_slug, input) 87 | ``` 88 | 89 | ### Try it 90 | **[Full screen  ](https://cosmic-graphql-playground.netlify.com/?endpoint=https://graphql.cosmicjs.com/v2&query=%7B%0A%20%20getObject(bucket_slug%3A%20%22simple-react-blog%22%2C%20input%3A%20%7B%20slug%3A%20%22a-wonderful-blog-post-about-earth%22%7D)%20%7B%0A%20%20%20%20title%0A%20%20%20%20content%0A%20%20%7D%0A%7D)** 91 | 92 | 93 | 94 | ## getObjectRevisions 95 | Get Object Revisions from a Bucket. 96 | 97 | ``` 98 | getObjectRevisions(bucket_slug, object_slug, input) 99 | ``` 100 | 101 | ### Try it 102 | **[Full screen  ](https://cosmic-graphql-playground.netlify.com/?endpoint=https%3A%2F%2Fgraphql.cosmicjs.com%2Fv2&query=%7B%0A%20%20getObjectRevisions%28%0A%20%20%20%20bucket_slug%3A%20%22simple-react-blog%22%2C%0A%20%20%20%20object_slug%3A%20%22a-wonderful-blog-post-about-earth%22%0A%20%20%29%20%7B%0A%20%20%20%20%20revisions%20%7B%0A%20%20%20%20%20%20title%0A%20%20%20%20%20%20content%0A%20%20%20%20%7D%0A%20%20%20%20total%0A%20%20%7D%0A%7D)** 103 | 104 | 105 | 106 | ## getMedia 107 | Get Media from a Bucket. 108 | ``` 109 | getMedia(bucket_slug, input) 110 | ``` 111 | 112 | ### Try it 113 | **[Full screen  ](https://cosmic-graphql-playground.netlify.com/?endpoint=https%3A%2F%2Fgraphql.cosmicjs.com%2Fv2&query=%7B%0A%20%20getMedia%28bucket_slug%3A%20%22simple-vue-blog%22%2C%0A%20%20%20%20input%3A%20%7B%0A%20%20%20%20%09limit%3A%202%0A%20%20%09%7D%0A%20%20%29%20%7B%0A%20%20%20%20media%20%7B%0A%20%20%20%20%09url%0A%20%20%09%7D%0A%20%20%20%20total%0A%20%20%7D%0A%7D)** 114 | 115 | 116 | 117 | ## getObjectTypes 118 | Get Object Types from a Bucket. 119 | ``` 120 | getObjectTypes(bucket_slug, input) 121 | ``` 122 | 123 | ### Try it 124 | **[Full screen  ](https://cosmic-graphql-playground.netlify.com/?endpoint=https://graphql.cosmicjs.com/v2&query=%7B%0A%20%20getObjectTypes(bucket_slug%3A%20%22simple-vue-blog%22)%20%7B%0A%20%20%20%20title%0A%20%20%7D%0A%7D)** 125 | 126 | 127 | 128 | ## getBucket 129 | Get all Bucket content. 130 | ``` 131 | getBucket(bucket_slug) 132 | ``` 133 | 134 | ### Try it 135 | **[Full screen  ](https://cosmic-graphql-playground.netlify.com/?endpoint=https://graphql.cosmicjs.com/v2&query=%7B%0A%20%20getBucket(%0A%20%20%20%20bucket_slug%3A%20%22simple-react-blog%22%2C%0A%20%20)%20%7B%0A%20%20%20%20objects%20%7B%0A%20%20%20%20%20%20title%0A%20%20%20%20%20%20slug%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D)** 136 | 137 | 138 | 139 | ## getAccessToken 140 | Get token for account-related access (not required for Bucket-level access). 141 | ``` 142 | getAccessToken(email, password) 143 | ``` 144 | 145 | ### Try it 146 | **[Full screen  ](https://cosmic-graphql-playground.netlify.com/?endpoint=https://graphql.cosmicjs.com/v2&query=%7B%0A%20%20getAccessToken(email%3A%20%22joe%40joes.com%22%2C%20password%3A%20%22myCatIsTheBest%22)%0A%7D)** 147 | 148 | 149 | 150 | ## getBuckets 151 | Get all Buckets on your user account. 152 | ``` 153 | getBuckets() 154 | ``` 155 | 156 | Requires `Authorization` in HTTP Header. Find token in Account Settings or using the `getAccessToken` method. 157 | 158 | ### Try it 159 | **[Full screen  ](https://cosmic-graphql-playground.netlify.com/?endpoint=https://graphql.cosmicjs.com/v2&query=%7B%0A%20%20getBuckets%20%7B%0A%20%20%20%20title%0A%20%20%7D%0A%7D)** 160 | 161 | 162 | 163 | ## getUsers 164 | Get Users in a Bucket. 165 | ``` 166 | getUsers(bucket_slug) 167 | ``` 168 | 169 | Requires `Authorization` in HTTP Header. Find token in Account Settings or using the `getAccessToken` method. 170 | 171 | ### Try it 172 | **[Full screen  ](https://cosmic-graphql-playground.netlify.com/?endpoint=https://graphql.cosmicjs.com/v2&query=%7B%0A%20%20getUsers(bucket_slug%3A%20%22art%22)%20%7B%0A%20%20%20%20first_name%0A%20%20%20%20email%0A%20%20%7D%0A%7D)** 173 | 174 | 175 | 176 | ## getUser 177 | Get a User in a Bucket. 178 | ``` 179 | getUser(bucket_slug, user_id) 180 | ``` 181 | 182 | Requires `Authorization` in HTTP Header. Find token in Account Settings or using the `getAccessToken` method. 183 | 184 | ### Try it 185 | **[Full screen  ](https://cosmic-graphql-playground.netlify.com/?endpoint=https://graphql.cosmicjs.com/v2&query=%7B%0A%20%20getUser(bucket_slug%3A%20%22art%22%2C%20user_id%3A%20%2256d66b2f903a79b904000001%22)%20%7B%0A%20%20%20%20_id%0A%20%20%20%20first_name%0A%20%20%20%20email%0A%20%20%7D%0A%7D)** 186 | 187 | 188 | -------------------------------------------------------------------------------- /docs/rest-api/buckets.md: -------------------------------------------------------------------------------- 1 | # Buckets 2 | Buckets are where you store content for your projects. 3 | 4 | ## Add Bucket 5 | 6 | `title` is the only required property. If no slug is present, the title will be [converted to a slug](https://www.npmjs.com/package/url-slug). See the table below for the other optional properties. The Bucket request matches the `bucket.json` file located in _Your Bucket Dashboard > Import / Export_. 7 | 8 | | Parameter | Required | Type | Description | 9 | | ------------- | -------- | ------ | -------------------------------------------------------------------------------------------------- | 10 | | title | required | String | Your Bucket title | 11 | | slug | | String | [URL-friendly](https://www.npmjs.com/package/url-slug) unique identifier | 12 | | read_key | | String | Restrict read access | 13 | | write_key | | String | Restrict write access | 14 | | cluster | | String | Add this Bucket to a Cluster. ID of existing Cluster | 15 | | object_types | | Array | Populate your Bucket with Object Types. See [Object Types](/rest-api/object-types.html) for model. | 16 | | objects | | Array | Populate your Bucket with Objects. See [Objects](/rest-api/objects.html) for model. | 17 | | media | | Array | Populate your Bucket with Media. See [Media](/rest-api/media.html) for model. | 18 | | media_folders | | Array | Populate your Bucket with Media Folders. See [Media](/rest-api/media.html) for model. | 19 | | webhooks | | Array | Populate your Bucket with [Webhooks](/webhooks). See [Webhooks](/webhooks) for model. | 20 | | extensions | | Array | Populate your Bucket with [Extensions]/docs(/extensions). See [Extensions](/extensions) for model. | 21 | 22 | :::: tabs :options="{ useUrlFragment: false }" 23 | 24 | ::: tab Bash 25 | **Definition** 26 | 27 | ``` 28 | POST https://api.cosmicjs.com/v1/buckets 29 | ``` 30 | 31 | **Example Request** 32 | 33 | ```bash 34 | curl -X POST "https://api.cosmicjs.com/v1/buckets" \ 35 | -H "Authorization: Bearer " \ 36 | -H "Content-Type: application/json" \ 37 | -d '{"title": "My New Bucket"}' 38 | ``` 39 | 40 | **Example Response** 41 | 42 | ```json 43 | { 44 | "bucket": { 45 | "_id": "55b3d557df0fb1df7600004b", 46 | "slug": "my-new-bucket", 47 | "title": "My New Bucket" 48 | } 49 | } 50 | ``` 51 | 52 | ::: 53 | 54 | ::: tab Node.js 55 | **Definition** 56 | 57 | ```js 58 | Cosmic.addBucket() 59 | ``` 60 | 61 | **Example Request** 62 | 63 | ```js 64 | const Cosmic = require('cosmicjs')({ 65 | token: 'your-token-from-auth-request' // required 66 | }) 67 | Cosmic.addBucket({ 68 | title: 'My New Bucket', 69 | slug: 'my-new-bucket' // must be unique across all Buckets in system 70 | }).then(data => { 71 | console.log(data) 72 | }) 73 | .catch(err => { 74 | console.log(err) 75 | }) 76 | ``` 77 | 78 | **Example Response** 79 | 80 | ```json 81 | { 82 | "bucket": { 83 | "_id": "55b3d557df0fb1df7600004b", 84 | "slug": "my-new-bucket", 85 | "title": "My New Bucket" 86 | } 87 | } 88 | ``` 89 | 90 | ::: 91 | 92 | :::: 93 | 94 | ## Get Buckets 95 | 96 | Gets all Buckets connected to your account. Your authorization token in the header request is the only required property. 97 | 98 | :::: tabs :options="{ useUrlFragment: false }" 99 | 100 | ::: tab Bash 101 | **Definition** 102 | 103 | ``` 104 | GET https://api.cosmicjs.com/v1/buckets 105 | ``` 106 | 107 | **Example Request** 108 | 109 | ```bash 110 | curl "https://api.cosmicjs.com/v1/buckets" \ 111 | -H "Authorization: Bearer " \ 112 | -H "Content-Type: application/json" 113 | # Gets all Buckets connected to your account. Your authorization token in the header request is the only required property. 114 | ``` 115 | 116 | **Example Response** 117 | 118 | ```json 119 | { 120 | "buckets": [ 121 | { 122 | "_id": "5a051c23ae05992b360005e7", 123 | "slug": "my-first-bucket", 124 | "title": "My First Bucket", 125 | "created_at": "2017-11-10T03:25:23.807Z", 126 | "modified_at": "2017-11-11T17:20:04.322Z" 127 | }, 128 | { 129 | "_id": "5a329f6769a130011900000c", 130 | "slug": "my-second-bucket", 131 | "title": "My Second Bucket", 132 | "created_at": "2017-12-14T15:57:27.274Z", 133 | "modified_at": "2018-01-14T04:06:29.630Z" 134 | }, 135 | { 136 | "_id": "5a329f6769a130011900000c", 137 | "slug": "my-third-bucket", 138 | "title": "My Third Bucket", 139 | "created_at": "2017-12-14T15:57:27.274Z", 140 | "modified_at": "2018-01-14T04:06:29.630Z" 141 | } 142 | ] 143 | } 144 | ``` 145 | 146 | ::: 147 | 148 | ::: tab Node.js 149 | **Definition** 150 | 151 | ```js 152 | Cosmic.getBuckets() 153 | ``` 154 | 155 | **Example Request** 156 | 157 | ```js 158 | const Cosmic = require('cosmicjs')({ 159 | token: 'your-token-from-auth-request' // optional 160 | }) 161 | Cosmic.getBuckets() 162 | .then(data => { 163 | console.log(data) 164 | }) 165 | .catch(err => { 166 | console.log(err) 167 | }) 168 | ``` 169 | 170 | **Example Response** 171 | 172 | ```json 173 | { 174 | "buckets": [ 175 | { 176 | "_id": "5a051c23ae05992b360005e7", 177 | "slug": "my-first-bucket", 178 | "title": "My First Bucket", 179 | "created_at": "2017-11-10T03:25:23.807Z", 180 | "modified_at": "2017-11-11T17:20:04.322Z" 181 | }, 182 | { 183 | "_id": "5a329f6769a130011900000c", 184 | "slug": "my-second-bucket", 185 | "title": "My Second Bucket", 186 | "created_at": "2017-12-14T15:57:27.274Z", 187 | "modified_at": "2018-01-14T04:06:29.630Z" 188 | }, 189 | { 190 | "_id": "5a329f6769a130011900000c", 191 | "slug": "my-third-bucket", 192 | "title": "My Third Bucket", 193 | "created_at": "2017-12-14T15:57:27.274Z", 194 | "modified_at": "2018-01-14T04:06:29.630Z" 195 | } 196 | ] 197 | } 198 | ``` 199 | 200 | ::: 201 | 202 | :::: 203 | 204 | ## Connect to Bucket 205 | 206 | For the NPM module: 207 | 208 | | Parameter | Required | Type | Description | 209 | | --------- | -------- | ------ | --------------------- | 210 | | slug | required | String | The Bucket slug | 211 | | read_key | | String | Restrict read access | 212 | | write_key | | String | Restrict write access | 213 | 214 | :::: tabs :options="{ useUrlFragment: false }" 215 | 216 | ::: tab Bash 217 | **Example Request** 218 | 219 | ```bash 220 | curl "https://api.cosmicjs.com/v1/wedding-site" 221 | ``` 222 | 223 | ::: 224 | 225 | ::: tab Node.js 226 | **Example Request** 227 | 228 | ```js 229 | // Use the Cosmic.bucket method to connect to different Buckets in your account. 230 | const Cosmic = require('cosmicjs')({ 231 | token: 'your-token-from-auth-request' // optional 232 | }) 233 | const bucket = Cosmic.bucket({ 234 | slug: 'my-first-bucket', 235 | read_key: '', 236 | write_key: '' 237 | }) 238 | const bucket2 = Cosmic.bucket({ 239 | slug: 'my-other-bucket', 240 | read_key: '', 241 | write_key: '' 242 | }) 243 | ``` 244 | 245 | ::: 246 | 247 | :::: 248 | 249 | ## Get Bucket 250 | 251 | Returns the entire Bucket including Object Types, Objects, Media and more. If you would like to restrict read access to your Bucket, you can do so in Your Bucket > Basic Settings. 252 | 253 | | Parameter | Required | Type | Description | 254 | | --------------- | -------- | ------ | ----------------------------------- | 255 | | hide_metafields | | Enum | true, Hides metafields | 256 | | read_key | | String | Restrict read access to your Bucket | 257 | 258 | :::: tabs :options="{ useUrlFragment: false }" 259 | 260 | ::: tab Bash 261 | **Definition** 262 | 263 | ``` 264 | GET https://api.cosmicjs.com/v1/:bucket_slug 265 | ``` 266 | 267 | **Example Request** 268 | 269 | ```bash 270 | curl "https://api.cosmicjs.com/v1/wedding-site" 271 | ``` 272 | 273 | ::: 274 | 275 | ::: tab Node.js 276 | **Definition** 277 | 278 | ```js 279 | bucket.getBucket() 280 | ``` 281 | 282 | **Example Request** 283 | 284 | 285 | ::: 286 | 287 | :::: 288 | 289 | ## Delete Bucket 290 | 291 | ::: danger DANGER 292 | Deletes the whole Bucket. **This cannot be undone.** 293 | ::: 294 | 295 | | Parameter | Required | Type | Description | 296 | | --------- | -------- | ------ | -------------------------------------------------------- | 297 | | id | required | String | The Bucket id found as "\_id" | 298 | | token | required | String | You can only delete Buckets that you have created / own. | 299 | 300 | :::: tabs :options="{ useUrlFragment: false }" 301 | 302 | ::: tab Bash 303 | **Definition** 304 | 305 | ``` 306 | DELETE https://api.cosmicjs.com/v1/buckets/:bucket_id 307 | ``` 308 | 309 | **Example Request** 310 | 311 | ```bash 312 | curl -X DELETE "https://api.cosmicjs.com/v1/buckets/:bucket_id" \ 313 | -H "Authorization: Bearer " 314 | ``` 315 | 316 | **Example Response** 317 | 318 | ```json 319 | { 320 | "status": "200", 321 | "message": "Bucket deleted" 322 | } 323 | ``` 324 | 325 | ::: 326 | 327 | ::: tab Node.js 328 | **Definition** 329 | 330 | ```js 331 | Cosmic.deleteBucket() 332 | ``` 333 | 334 | **Example Request** 335 | 336 | ```js 337 | const Cosmic = require('cosmicjs')){ 338 | token: 'your-token-from-auth-request' // required 339 | }) 340 | Cosmic.deleteBucket({ 341 | id: 'bucket_id' 342 | }).then(data => { 343 | console.log(data) 344 | }).catch(err => { 345 | console.log(err) 346 | }) 347 | ``` 348 | 349 | **Example Response** 350 | 351 | ```json 352 | { 353 | "status": "200", 354 | "message": "Bucket deleted" 355 | } 356 | ``` 357 | 358 | ::: 359 | 360 | :::: 361 | 362 | ## Import Bucket 363 | 364 | ::: danger DANGER 365 | The Bucket import method removes all current data: Object Types, Objects and Media and replaces it with new data. **This cannot be undone.** 366 | ::: 367 | 368 | The Bucket data schema matches the `bucket.json` file located in _Your Bucket Dashboard > Import / Export_. 369 | 370 | | Parameter | Required | Type | Description | 371 | | ------------- | -------- | ----- | -------------------------------------------------------------------------------------------------- | 372 | | object_types | | Array | Populate your Bucket with Object Types. See [Object Types](/rest-api/object-types.html) for model. | 373 | | objects | | Array | Populate your Bucket with Objects. See [Objects](/rest-api/objects.html) for model. | 374 | | media | | Array | Populate your Bucket with Media. See [Media](<(/rest-api/media.html)>) for model. | 375 | | media_folders | | Array | Populate your Bucket with Media Folders. See [Media](/rest-api/media.html) for model. | 376 | | webhooks | | Array | Populate your Bucket with Webhooks. See [Webhooks](/webhooks) for model. | 377 | | extensions | | Array | Populate your Bucket with Extensions. See [Extensions](/extensions) for model. | 378 | 379 | :::: tabs :options="{ useUrlFragment: false }" 380 | 381 | ::: tab Bash 382 | **Definition** 383 | 384 | ``` 385 | DELETE https://api.cosmicjs.com/v1/buckets/:bucket_id 386 | ``` 387 | 388 | **Example Request** 389 | 390 | ```bash 391 | curl -X DELETE "https://api.cosmicjs.com/v1/buckets/:bucket_id" \ 392 | -H "Authorization: Bearer " 393 | ``` 394 | 395 | **Example Response** 396 | 397 | ```json 398 | { 399 | "status": "200", 400 | "message": "Bucket deleted" 401 | } 402 | ``` 403 | 404 | ::: 405 | 406 | ::: tab Node.js 407 | **Definition** 408 | 409 | ```js 410 | Cosmic.importBucket() 411 | ``` 412 | 413 | **Example Request** 414 | 415 | ```js 416 | const Cosmic = require('cosmicjs')({ 417 | token: 'your-token-from-auth-request' // required 418 | }) 419 | const params = { 420 | "id": "5ace13795a39fb49db87ac95", // Bucket id found in Bucket Settings > Basic Settings 421 | "bucket": { // import data 422 | "object_types": [...], 423 | "objects": [...], 424 | "media": [...] 425 | } 426 | } 427 | Cosmic.importBucket(params).then(data => { 428 | console.log(data) 429 | }).catch(err => { 430 | console.log(err) 431 | }) 432 | ``` 433 | 434 | **Example Response** 435 | 436 | ```json 437 | { 438 | "bucket": { 439 | "_id": "5ace13795a39fb49db87ac95", 440 | "slug": "same-bucket-slug", 441 | "title": "Same Bucket Title", 442 | "object_types": [...], // all new Object Types 443 | "objects": [...], // all new Objects 444 | "media": [...] // all new Media 445 | } 446 | } 447 | ``` 448 | 449 | ::: 450 | 451 | :::: -------------------------------------------------------------------------------- /docs/rest-api/extensions.md: -------------------------------------------------------------------------------- 1 | # Extensions 2 | All Extension methods require `Authorization: Bearer ` present in the header. 3 | 4 | ## Add Extension 5 | 6 | There are three different methods you can use to add an Extension to your Bucket. Read more about how to build your Extension on the [Extensions documentation page](/extensions). 7 | 8 | ### 1. Upload a Zip file 9 | The only required post value is `zip` which contains the file you send. 10 | 11 | | Parameter | Required | Type | Description | 12 | | --------- | -------- | ----------------------- | ----------------------------------- | 13 | | zip | required | File Object (see below) | Zip object with specific properties | 14 | 15 | **Definition** 16 | 17 | ``` 18 | POST https://api.cosmicjs.com/v1/:bucket_slug/extensions 19 | ``` 20 | 21 | **Example Request** 22 | 23 | ```json 24 | { 25 | "zip": "your-media-multipart-form-data" 26 | } 27 | ``` 28 | 29 | **Example Response** 30 | 31 | ```json 32 | { 33 | "extension": { 34 | "id": "c62defe0-5f93-11e7-8054-873245f0e98d", 35 | "title": "Amazon Product Search", 36 | "image_url": "https://s3-us-west-2.amazonaws.com/cosmicjs/f1f1bd40-5dcd-11e7-b529-51f126a4b6ee-shopping-cart.jpg", 37 | "url": "https://cosmicjs.com/extensions/c62defe0-5f93-11e7-8054-873245f0e98d/dist", 38 | "zip_url": "https://cosmicjs.com/extensions/c62defe0-5f93-11e7-8054-873245f0e98d/src/build.zip", 39 | "installed_at": "2017-07-03T02:03:14.825Z", 40 | "font_awesome_class": "fa-shopping-basket" 41 | } 42 | } 43 | ``` 44 | 45 | #### File Object 46 | 47 | The `zip` property that includes the File Object must be an object with certain properties indicated below. If using the [multer NPM module](https://www.npmjs.com/package/multer) the file objects have these by default. Otherwise you should create an object with these properties: 48 | 49 | | Parameter | Required | Type | Description | 50 | | ------------ | -------- | ----------- | ------------------------------------- | 51 | | originalname | required | String | The name of your file (something.jpg) | 52 | | buffer | | File Buffer | The File Buffer (must be zip file) | 53 | 54 | ### 2. Upload via Zip file URL 55 | The only required post value is `zip_url` which is the URL of your Extension zip file. 56 | 57 | | Parameter | Required | Type | Description | 58 | | --------- | -------- | ----------------------- | ----------------------------------- | 59 | | zip_url | required | String | Zip file URL with valid Extension properties | 60 | 61 | **Definition** 62 | 63 | ``` 64 | POST https://api.cosmicjs.com/v1/:bucket_slug/extensions 65 | ``` 66 | 67 | **Example Request** 68 | 69 | ```json 70 | { 71 | "zip_url": "https://mycdn.com/uploads/extension.zip" 72 | } 73 | ``` 74 | 75 | **Example Response** 76 | 77 | ```json 78 | { 79 | "extension": { 80 | "id": "c62defe0-5f93-11e7-8054-873245f0e98d", 81 | "title": "Amazon Product Search", 82 | "image_url": "https://s3-us-west-2.amazonaws.com/cosmicjs/f1f1bd40-5dcd-11e7-b529-51f126a4b6ee-shopping-cart.jpg", 83 | "url": "https://cosmicjs.com/extensions/c62defe0-5f93-11e7-8054-873245f0e98d/dist", 84 | "zip_url": "https://cosmicjs.com/extensions/c62defe0-5f93-11e7-8054-873245f0e98d/src/build.zip", 85 | "installed_at": "2017-07-03T02:03:14.825Z", 86 | "font_awesome_class": "fa-shopping-basket" 87 | } 88 | } 89 | ``` 90 | 91 | ### 3. Add as URL 92 | The required post values are `title` and `url`. 93 | 94 | | Parameter | Required | Type | Description | 95 | | --------- | -------- | ----------------------- | ----------------------------------- | 96 | | title | required | String | Extension title | 97 | | url | required | String | URL to point the Extension to (iframe). Needs to have https and X-Frame Options enabled) | 98 | 99 | :::: tabs :options="{ useUrlFragment: false }" 100 | 101 | ::: tab Bash 102 | **Definition** 103 | 104 | ``` 105 | POST https://api.cosmicjs.com/v1/:bucket_slug/extensions 106 | ``` 107 | 108 | **Example Request** 109 | 110 | ```json 111 | { 112 | "zip": "your-media-multipart-form-data" 113 | } 114 | ``` 115 | 116 | **Example Response** 117 | 118 | ```json 119 | { 120 | "extension": { 121 | "id": "c62defe0-5f93-11e7-8054-873245f0e98d", 122 | "title": "My Awesome Extension", 123 | "image_url": null, 124 | "url": null, 125 | "zip_url": null, 126 | "installed_at": "2017-07-03T02:03:14.825Z", 127 | "font_awesome_class": null 128 | } 129 | } 130 | ``` 131 | 132 | ::: 133 | 134 | ::: tab Node.js 135 | **Definition** 136 | 137 | ```js 138 | bucket.addExtension() 139 | ``` 140 | 141 | **Example Request** 142 | 143 | ```js 144 | const Cosmic = require('cosmicjs')({ 145 | token: 'YOUR_ACCOUNT_TOKEN' // required 146 | }) 147 | const bucket = Cosmic.bucket({ 148 | slug: 'bucket-slug' 149 | }) 150 | 151 | bucket 152 | .addExtension({ 153 | zip_url: "https://mycdn.com/uploads/extension.zip" 154 | }) 155 | .then(data => { 156 | console.log(data) 157 | }) 158 | .catch(err => { 159 | console.log(err) 160 | }) 161 | ``` 162 | 163 | **Example Response** 164 | 165 | ```json 166 | { 167 | "extension": { 168 | "id": "c62defe0-5f93-11e7-8054-873245f0e98d", 169 | "title": "Amazon Product Search", 170 | "image_url": "https://s3-us-west-2.amazonaws.com/cosmicjs/f1f1bd40-5dcd-11e7-b529-51f126a4b6ee-shopping-cart.jpg", 171 | "url": "https://cosmicext.com/extensions/c62defe0-5f93-11e7-8054-873245f0e98d/dist", 172 | "zip_url": "https://cosmicext.com/extensions/c62defe0-5f93-11e7-8054-873245f0e98d/src/build.zip", 173 | "installed_at": "2017-07-03T02:03:14.825Z", 174 | "font_awesome_class": "fa-shopping-basket" 175 | } 176 | } 177 | ``` 178 | 179 | ::: 180 | 181 | :::: 182 | 183 | ## Get Extensions 184 | 185 | Get extensions in your Bucket. Authentication token is required in the header (see Authentication section). Must have admin level access. 186 | 187 | :::: tabs :options="{ useUrlFragment: false }" 188 | 189 | ::: tab Bash 190 | **Definition** 191 | 192 | ``` 193 | GET https://api.cosmicjs.com/v1/:bucket_slug/extensions 194 | ``` 195 | 196 | **Example Request** 197 | 198 | ```bash 199 | curl "https://api.cosmicjs.com/v1/creative-agency/extensions" \ 200 | -H "Authorization: Bearer " 201 | ``` 202 | 203 | **Example Response** 204 | 205 | ```json 206 | { 207 | "extensions": [ 208 | { 209 | "id": "023cc770-32f7-11ea-aa87-974af99bb840", 210 | "title": "Product Manager", 211 | "image_url": "https://cosmicjs.imgix.net/cf5e1020-49a1-11e7-b277-57e32e044f35-tags.jpg?w=800", 212 | "repo_url": "https://github.com/cosmicjs/product-manager", 213 | "url": "https://cosmicext.com/extensions/023cc770-32f7-11ea-aa87-974af99bb840/dist", 214 | "zip_url": "https://cosmicjs.com/extensions/023cc770-32f7-11ea-aa87-974af99bb840/src/dae868b0-089e-11e9-8afb-cfbab439bdeb-build.zip", 215 | "installed_at": "2020-01-09T15:45:08.414Z", 216 | "installed_by": "5de944d047f3cd28bbba660b", 217 | "font_awesome_class": "fa-tags", 218 | "cosmic_extension_id": "5de94da87fa6662a3f990086" 219 | }, 220 | { 221 | "id": "068e4740-32f7-11ea-aa87-974af99bb840", 222 | "title": "Deploy to Web", 223 | "image_url": "https://cosmic-s3.imgix.net/cc5647e0-c5e5-11e9-8343-8b95f624368a-deploy-to-web.jpg", 224 | "url": "https://cosmicext.com/extensions/068e4740-32f7-11ea-aa87-974af99bb840/dist", 225 | "zip_url": "https://cosmicjs.com/extensions/068e4740-32f7-11ea-aa87-974af99bb840/src/96946b90-c5e6-11e9-8343-8b95f624368a-build.zip", 226 | "installed_at": "2020-01-09T15:45:15.495Z", 227 | "installed_by": "5de944d047f3cd28bbba660b", 228 | "font_awesome_class": "fa-rocket", 229 | "cosmic_extension_id": "5de94da87fa6662a3f990089" 230 | } 231 | ], 232 | "total": 2 233 | } 234 | ``` 235 | 236 | ::: 237 | 238 | ::: tab Node.js 239 | **Definition** 240 | 241 | ```js 242 | bucket.getExtensions() 243 | ``` 244 | 245 | **Example Request** 246 | 247 | ```js 248 | const bucket = Cosmic.bucket({ 249 | slug: 'bucket-slug' 250 | }) 251 | bucket.getExtensions() 252 | .then(data => { 253 | console.log(data) 254 | }) 255 | .catch(err => { 256 | console.log(err) 257 | }) 258 | ``` 259 | 260 | **Example Response** 261 | 262 | ```json 263 | { 264 | "extensions": [ 265 | { 266 | "id": "023cc770-32f7-11ea-aa87-974af99bb840", 267 | "title": "Product Manager", 268 | "image_url": "https://cosmicjs.imgix.net/cf5e1020-49a1-11e7-b277-57e32e044f35-tags.jpg?w=800", 269 | "repo_url": "https://github.com/cosmicjs/product-manager", 270 | "url": "https://cosmicext.com/extensions/023cc770-32f7-11ea-aa87-974af99bb840/dist", 271 | "zip_url": "https://cosmicjs.com/extensions/023cc770-32f7-11ea-aa87-974af99bb840/src/dae868b0-089e-11e9-8afb-cfbab439bdeb-build.zip", 272 | "installed_at": "2020-01-09T15:45:08.414Z", 273 | "installed_by": "5de944d047f3cd28bbba660b", 274 | "font_awesome_class": "fa-tags", 275 | "cosmic_extension_id": "5de94da87fa6662a3f990086" 276 | }, 277 | { 278 | "id": "068e4740-32f7-11ea-aa87-974af99bb840", 279 | "title": "Deploy to Web", 280 | "image_url": "https://cosmic-s3.imgix.net/cc5647e0-c5e5-11e9-8343-8b95f624368a-deploy-to-web.jpg", 281 | "url": "https://cosmicext.com/extensions/068e4740-32f7-11ea-aa87-974af99bb840/dist", 282 | "zip_url": "https://cosmicjs.com/extensions/068e4740-32f7-11ea-aa87-974af99bb840/src/96946b90-c5e6-11e9-8343-8b95f624368a-build.zip", 283 | "installed_at": "2020-01-09T15:45:15.495Z", 284 | "installed_by": "5de944d047f3cd28bbba660b", 285 | "font_awesome_class": "fa-rocket", 286 | "cosmic_extension_id": "5de94da87fa6662a3f990089" 287 | } 288 | ], 289 | "total": 2 290 | } 291 | ``` 292 | 293 | ::: 294 | 295 | :::: 296 | 297 | 298 | ## Edit Extension 299 | 300 | Query parameters can be added to the iframe URL of your Extension. These are great for storing third-party API keys and info. For security, `query_params` values will be saved as JavaScript Web Tokens (JWT), but available in your Extension as decoded values. 301 | 302 | | Parameter | Required | Type | Description | 303 | | --------- | -------- | ------ | --------------------- | 304 | | query_params | | Array | Add query parameters to your Extension. Great for adding third-party service API keys. | 305 | 306 | :::: tabs :options="{ useUrlFragment: false }" 307 | 308 | ::: tab Bash 309 | **Definition** 310 | 311 | ``` 312 | PUT https://api.cosmicjs.com/v1/:bucket_slug/extensions/:extension_id 313 | ``` 314 | 315 | **Example Request** 316 | 317 | ```json 318 | { 319 | "query_params": [ 320 | { 321 | "key": "some_api_account_id", 322 | "value": "someapiid12345" 323 | }, 324 | { 325 | "key": "some_api_account_secret", 326 | "value": "supersecret12345" 327 | } 328 | ] 329 | } 330 | ``` 331 | 332 | **Example Response** 333 | 334 | ```json 335 | { 336 | "extension": { 337 | "id": "71d1ef20-c132-11e9-9883-b325a8e53f4f", 338 | "cosmic_extension_id": "5c63324e7489d71dfe2974ac", 339 | "title": "WordPress Importer", 340 | "image_url": "https://cosmic-s3.imgix.net/31cc7ee0-2d80-11e9-9636-75201e82cc8c-wordpress-to-cosmic.jpg?w=500", 341 | "repo_url": "https://github.com/cosmicjs/wordpress-post-importer", 342 | "url": "https://71d1ef20-c132-11e9-9883-b325a8e53f4f.cosmicext.com", 343 | "zip_url": "https://cosmicjs.com/extensions/71d1ef20-c132-11e9-9883-b325a8e53f4f/src/extension.zip", 344 | "installed_at": "2019-08-17T21:03:21.757Z", 345 | "installed_by": "56d66b2f903a79b904000001", 346 | "font_awesome_class": "fa-wordpress", 347 | "query_params": [ 348 | { 349 | "key": "some_api_account_id", 350 | "value": "eyJhbGciOiJIUzI1NiJ9.dHJ1ZQ.0hVNE7ES45PA8EnxK6gzAtY-4DfTpGtB0_A2fCW8SuU" 351 | }, 352 | { 353 | "key": "some_api_account_secret", 354 | "value": "eyJhbGciOiJIUzI1NiJ9.dHJ1ZQ.0hVNE7ES45PA8EnxK6gzAtY-4DfTpGtB0_A2fCW8SuU" 355 | } 356 | ] 357 | } 358 | } 359 | ``` 360 | 361 | ::: 362 | 363 | ::: tab Node.js 364 | 365 | **Definition** 366 | 367 | ```js 368 | Cosmic.editExtension() 369 | ``` 370 | 371 | **Example Request** 372 | 373 | ```js 374 | const Cosmic = require('cosmicjs')({ 375 | token: 'YOUR_ACCOUNT_TOKEN' // required 376 | }) 377 | const bucket = Cosmic.bucket({ 378 | slug: 'bucket-slug' 379 | }) 380 | bucket.editExtension({ 381 | id: 'c62defe0-5f93-11e7-8054-873245f0e98d', 382 | query_params: [ 383 | { 384 | key: "some_api_account_id", 385 | value: "someapiid12345" 386 | }, 387 | { 388 | key: "some_api_account_secret", 389 | value: "supersecret12345" 390 | } 391 | ] 392 | }) 393 | .then(data => { 394 | console.log(data) 395 | }) 396 | .catch(err => { 397 | console.log(err) 398 | }) 399 | ``` 400 | 401 | **Example Response** 402 | 403 | ```json 404 | { 405 | "extension": { 406 | "id": "71d1ef20-c132-11e9-9883-b325a8e53f4f", 407 | "cosmic_extension_id": "5c63324e7489d71dfe2974ac", 408 | "title": "WordPress Importer", 409 | "image_url": "https://cosmic-s3.imgix.net/31cc7ee0-2d80-11e9-9636-75201e82cc8c-wordpress-to-cosmic.jpg?w=500", 410 | "repo_url": "https://github.com/cosmicjs/wordpress-post-importer", 411 | "url": "https://71d1ef20-c132-11e9-9883-b325a8e53f4f.cosmicext.com", 412 | "zip_url": "https://cosmicjs.com/extensions/71d1ef20-c132-11e9-9883-b325a8e53f4f/src/extension.zip", 413 | "installed_at": "2019-08-17T21:03:21.757Z", 414 | "installed_by": "56d66b2f903a79b904000001", 415 | "font_awesome_class": "fa-wordpress", 416 | "query_params": [ 417 | { 418 | "key": "some_api_account_id", 419 | "value": "eyJhbGciOiJIUzI1NiJ9.dHJ1ZQ.0hVNE7ES45PA8EnxK6gzAtY-4DfTpGtB0_A2fCW8SuU" 420 | }, 421 | { 422 | "key": "some_api_account_secret", 423 | "value": "eyJhbGciOiJIUzI1NiJ9.dHJ1ZQ.0hVNE7ES45PA8EnxK6gzAtY-4DfTpGtB0_A2fCW8SuU" 424 | } 425 | ] 426 | } 427 | } 428 | ``` 429 | 430 | ::: 431 | 432 | :::: 433 | 434 | 435 | 436 | ## Delete Extension 437 | Make sure you include `Authorization: Bearer ` in the header. 438 | 439 | :::: tabs :options="{ useUrlFragment: false }" 440 | 441 | ::: tab Bash 442 | **Definition** 443 | 444 | ``` 445 | DELETE https://api.cosmicjs.com/v1/:bucket_slug/extensions/:extension_id 446 | ``` 447 | 448 | **Example Response** 449 | 450 | ```json 451 | { 452 | "status": "200", 453 | "message": "Extension deleted." 454 | } 455 | ``` 456 | 457 | ::: 458 | 459 | ::: tab Node.js 460 | **Definition** 461 | 462 | ```js 463 | Cosmic.deleteExtension() 464 | ``` 465 | 466 | **Example Request** 467 | 468 | ```js 469 | const Cosmic = require('cosmicjs')({ 470 | token: 'YOUR_ACCOUNT_TOKEN' // required 471 | }) 472 | const bucket = Cosmic.bucket({ 473 | slug: 'bucket-slug' 474 | }) 475 | bucket.deleteExtension({ 476 | id: 'c62defe0-5f93-11e7-8054-873245f0e98d' 477 | }) 478 | .then(data => { 479 | console.log(data) 480 | }) 481 | .catch(err => { 482 | console.log(err) 483 | }) 484 | ``` 485 | 486 | **Example Response** 487 | 488 | ```json 489 | { 490 | "status": "200", 491 | "message": "Extension deleted." 492 | } 493 | ``` 494 | 495 | ::: 496 | 497 | :::: 498 | --------------------------------------------------------------------------------