404
5 |{{ getMsg() }}6 |
{{ getMsg() }}6 |
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 | -------------------------------------------------------------------------------- /docs/.vuepress/theme/components/Sidebar.vue: -------------------------------------------------------------------------------- 1 | 2 | 8 | 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 |
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 |
2 |
22 |
23 |
24 |
87 |
--------------------------------------------------------------------------------
/docs/.vuepress/public/cosmicjs.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
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 |
26 | 30 | {{ title }} 31 |
32 |33 | {{ description }} 34 |
35 |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: Bearer13 | {{ data.tagline || $description || 'Welcome to your VuePress site' }} 14 |
15 | 16 |
20 |
{{ feature.details }}
38 |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 |
2 |
31 |
35 | ←
36 |
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
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