Skip to content

Commit 897e256

Browse files
readme 📝
1 parent ffd9de0 commit 897e256

File tree

7 files changed

+94
-200
lines changed

7 files changed

+94
-200
lines changed

README.md

Lines changed: 66 additions & 169 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,20 @@
1-
## Contentstack Management SDK - Java
1+
[![Contentstack](https://www.contentstack.com/docs/static/images/contentstack.png)](https://www.contentstack.com/)
22

3-
Contentstack is a headless CMS with an API-first approach. It is a CMS that developers can use to build powerful cross-platform applications in their favorite languages. All you have to do is build your application frontend, and Contentstack will take care of the rest. [Read More](https://www.contentstack.com/). This SDK uses the [Content Management API](https://www.contentstack.com/docs/developers/apis/content-management-api/) (CMA). The CMA is used to manage the content of your Contentstack account. This includes creating, updating, deleting, and fetching content of your account.
3+
## Contentstack Management Java SDK
44

5-
**Note:** _By using CMA, you can execute GET requests for fetching content. However, we strongly recommend that you always use the [Content Delivery API](https://www.contentstack.com/docs/developers/apis/content-delivery-api/) to deliver content to your web or mobile properties_.
5+
Contentstack is a headless CMS with an API-first approach. It is a CMS that developers can use to build powerful cross-platform applications in their favorite languages. All you have to do is build your application frontend, and Contentstack will take care of the rest. [Read More](https://www.contentstack.com/).
66

7-
<details open>
8-
<summary>Table of contents</summary>
7+
This SDK uses the [Content Management API](https://www.contentstack.com/docs/developers/apis/content-management-api/) (CMA). The CMA is used to manage the content of your Contentstack account. This includes creating, updating, deleting, and fetching content of your account. To use the CMA, you will need to authenticate your users with a [Management Token](https://www.contentstack.com/docs/developers/create-tokens/about-management-tokens) or an [Authtoken](https://www.contentstack.com/docs/developers/apis/content-management-api/#how-to-get-authtoken). Read more about it in [Authentication](https://www.contentstack.com/docs/developers/apis/content-management-api/#authentication).
98

10-
- [Prerequisite](#prerequisite)
11-
- [Installation](#installation)
12-
- [Initialization](#initialization)
13-
- [Authentication](#authentication)
14-
- [Users](#users)
15-
- [Organizations](#organizations)
16-
- [Stacks](#stacks)
17-
- [Content Types](#content-types)
18-
- [Global Fields](#global-fields)
19-
- [Entries](#entries)
20-
- [Assets](#assets)
21-
- [Bulk Operation](#bulk-operations)
9+
Note: By using CMA, you can execute GET requests for fetching content. However, we strongly recommend that you always use the [Content Delivery API](https://www.contentstack.com/docs/developers/apis/content-delivery-api/) to deliver content to your web or mobile properties.
2210

23-
</details>
11+
### Prerequisite
2412

25-
- Others
26-
[Create JSON Body](##RequestBody)
13+
You need Node.js version 10 or above installed on your machine to use the Contentstack Java CMS SDK.
2714

28-
## Prerequisite
29-
30-
To use the Contentstack management sdk for Java, you must have:
31-
32-
- The suitable [Java Development Environment](http://www.oracle.com/technetwork/java/javase/downloads/).
33-
- The [Contentstack](https://www.contentstack.com) account.
34-
- Login your account
35-
- Get the [Contentstack](https://www.contentstack.com) credentials (API keys and Management Token) set in your stack token section.
36-
- Should be Java 1.8 or above installed.
37-
38-
## Setup
39-
40-
To use Contentstack management sdk in our Maven project, we'll need to add the following dependency to our pom.xml:
15+
### Installation
4116

17+
Install it via maven:
4218

4319
```java
4420
<dependency>
@@ -48,200 +24,121 @@ To use Contentstack management sdk in our Maven project, we'll need to add the f
4824
</dependency>
4925
```
5026

51-
Or, for a Gradle project:
27+
Install it via gradle:
5228

5329
```java
54-
implementation 'com.contentstack.cms:{version}'
30+
implementation 'com.contentstack.sdk:cms:{version}'
5531
```
5632

57-
- Download the latest version [HERE](https://search.maven.org/artifact/com.contentstack.cma)
58-
59-
## Initialization
60-
61-
To use the Java CMA SDK, you need get the client first:
33+
To import the SDK, use the following command:
6234

6335
```java
64-
Contentstack client = new Contentstack.Builder().setAuthtoken("AUTHTOKEN").build();
65-
```
36+
package com.contentstack.cms;
6637

67-
## Authentication
38+
Contentstack client = new Contentstack.Builder().build();
39+
```
6840

69-
To use the CMA, you will need to authenticate your users with a [Management Token](https://www.contentstack.com/docs/developers/create-tokens/about-management-tokens) or an [Authtoken](https://www.contentstack.com/docs/developers/apis/content-management-api/#how-to-get-authtoken). Read more about it in [Authentication](https://www.contentstack.com/docs/developers/apis/content-management-api/#authentication)
41+
### Authentication
7042

71-
- _Using authtoken_
43+
To use this SDK, you need to authenticate your users by using the Authtoken, credentials, or Management Token (stack-level token).
7244

73-
---
45+
### Authtoken
7446

7547
An [Authtoken](https://www.contentstack.com/docs/developers/create-tokens/types-of-tokens/#authentication-tokens-authtokens-) is a read-write token used to make authorized CMA requests, and it is a **user-specific** token.
7648

7749
```java
78-
Contentstack client = new Contentstack.Builder().setAuthtoken("AUTHTOKEN").build();
50+
Contentstack client = new Contentstack.Builder().setAuthtoken("AUTHTOKEN").build();
7951
```
8052

81-
- _Using login email id and password_
53+
### Login
8254

8355
To Login to Contentstack by using credentials, you can use the following lines of code:
8456

8557
```java
86-
Contentstack client = new Contentstack.Builder().setAuthtoken("AUTHTOKEN").build();
87-
Response<ResponseBody> response = client.login("EMAIL", "PASSWORD").execute()
58+
Contentstack client = new Contentstack.Builder().build();
59+
client.login("EMAIL", "PASSWORD");
8860
```
8961

90-
- _Using management token_
62+
### Management Token
9163

9264
[Management Tokens](https://www.contentstack.com/docs/developers/create-tokens/about-management-tokens/) are **stack-level** tokens, with no users attached to them.
9365

9466
```java
9567
Contentstack client = new Contentstack.Builder().setAuthtoken("AUTHTOKEN").build();
96-
Response<ResponseBody> response = client.stack("API_KEY", "MANAGEMENT_TOKEN").contentType().execute()
68+
Stack stack = client.stack("API_KEY", "MANAGEMENT_TOKEN");
9769
```
9870

99-
## Users
71+
### Contentstack Management JavaScript SDK: 5-minute Quickstart
10072

101-
[Users](https://www.contentstack.com/docs/developers/apis/content-management-api/#users) All accounts registered with Contentstack are known as Users. A stack can have many users with varying permissions and roles.
73+
#### Initializing Your SDK
10274

103-
Access the user like below snippet:
75+
To use the JavaScript CMA SDK, you need to first initialize it. To do this, use the following code:
10476

10577
```java
106-
Contentstack client = new Contentstack.Builder().build();
107-
client.login("EMAIL", "PASSWORD");
108-
User user = client.user();
109-
Response<ResponseBody> response = user.getUser().execute();
110-
```
111-
112-
## Organizations
113-
114-
[Organization](https://www.contentstack.com/docs/owners-and-admins/about-organizations) is the top-level entity in the hierarchy of Contentstack, consisting of stacks and [stack](https://www.contentstack.com/docs/developers/set-up-stack/about-stack/) resources, and users. Organization allows easy management of projects as well as users within the Organization.
78+
package com.contentstack.cms;
11579

116-
```java
117-
Contentstack client = new Contentstack.Builder().build();
118-
client.login("EMAIL", "PASSWORD");
119-
Organization organization = contentstack.organization();
120-
Response<ResponseBody> response = organization.getAll().execute();
80+
Contentstack client = new Contentstack.Builder().setAuthtoken("AUTHTOKEN").build();
12181
```
12282

123-
## Stacks
83+
#### Fetch Stack Detail
12484

125-
A [Stack](https://www.contentstack.com/docs/developers/set-up-stack/about-stack) is a space that stores the content of a project (a web or mobile property). Within a stack, you can create content structures, content entries, users, etc. related to the project.
85+
Use the following lines of code to fetch your stack detail using this SDK:
12686

12787
```java
128-
Contentstack client = new Contentstack.Builder().build();
129-
client.login("EMAIL", "PASSWORD");
130-
Stack stack = contentstack.stack("APIKey");
88+
Stack stack = contentstack.stack("API_KEY");
13189
Response<ResponseBody> response = stack.fetch().execute();
13290
```
13391

134-
OR
135-
136-
```java
137-
Contentstack client = new Contentstack.Builder().setAuthtoken("AUTHTOKEN").build();
138-
Response<ResponseBody> response = client.stack("API_KEY").exceute()
139-
```
140-
141-
## Content Types
92+
#### Create Entry
14293

143-
[Content type](https://www.contentstack.com/docs/developers/apis/content-management-api/#content-types) defines the structure or schema of a page or a section of your web or mobile property. To create content for your application, you are required to first create a content type, and then create entries using the content type.
94+
To create an entry in a specific content type of a stack, use the following lines of code:
14495

14596
```java
146-
Contentstack contentstack = new Contentstack.Builder().build();
147-
ContentType contentType = contentstack.contentType("API_KEY", "MANAGEMENT_TOKEN");
148-
Response<ResponseBody> response = contentType.fetch(mapQuery).execute();
149-
```
150-
151-
## Global Fields
152-
153-
A [Global field](https://www.contentstack.com/docs/developers/apis/content-management-api/#global-fields) is a reusable field (or group of fields) that you can define once and reuse in any content type within your stack. This eliminates the need (and thereby time and efforts) to create the same set of fields repeatedly in multiple content types.
154-
155-
```java
156-
GlobalField globalField = new Contentstack.Builder().setAuthtoken(GLOBAL_AUTHTOKEN).build()
157-
.globalField("API_KEY", "MANAGEMENT_TOKEN");
158-
Call<ResponseBody> response = globalField.update(GlobalFiledUid,
159-
"requestBody");
160-
```
161-
162-
## Entries
163-
164-
An [entry](https://www.contentstack.com/docs/developers/apis/content-management-api/#entries) is the actual piece of content created using one of the defined content types.
97+
Stack stack = contentstack.stack("API_KEY");
98+
// Create JSONObject to upload
99+
JSONObject jsonBody = new JSONObject()
100+
jsonBody.put("key", "value");
165101

166-
```java
167-
Entry entry = new Contentstack.Builder().setAuthtoken(authToken).build()
168-
.entry("API_KEY", "MANAGEMENT_TOKEN");
169-
HashMap<String, Object> queryParams = new HashMap<>();
170-
Response<ResponseBody> response = entry.fetch(queryParams).execute();
102+
// Add Query parameters to the entry
103+
entry.addParam("locale", "en-us");
104+
Response<ResponseBody> resp = entry.create(jsonBody).execute();
105+
if (response.isSuccessful()){
106+
System.out.println(response.body(););
107+
}else {
108+
System.out.println(response.errorBody(););
109+
}
171110
```
172111

173-
## Assets
112+
#### Create Asset
174113

175-
[Assets](https://www.contentstack.com/docs/developers/apis/content-management-api/#assets) refer to all the media files (images, videos, PDFs, audio files, and so on) uploaded in your Contentstack repository for future use.
114+
The following lines of code can be used to upload assets to your stack:
176115

177116
```java
178-
Asset asset = new Contentstack.Builder().setAuthtoken("AUTHTOKEN").build().asset("API_KEY", "MANAGEMENT_TOKEN");
179-
Map<String, Object> queryParams = new HashMap<>();
180-
queryParams.put("folder", "folder_uid_some_example");
181-
queryParams.put("include_folders", true);
182-
queryParams.put("environment", "production");
183-
queryParams.put("version", 1);
184-
queryParams.put("include_publish_details", true);
185-
queryParams.put("include_count", true);
186-
queryParams.put("relative_urls", false);
187-
queryParams.put("asc_field_uid", "created_at");
188-
queryParams.put("desc_field_uid", 230);
189-
190-
Response<ResponseBody> response = asset.fetch(queryParams).execute();
191-
192-
```
193-
194-
## Bulk Operations
195-
196-
You can perform [bulk operations](https://www.contentstack.com/docs/developers/apis/content-management-api/#bulk-operations) such as Publish, Unpublish, and Delete on multiple entries or assets, or Change the Workflow Details of multiple entries or assets at the same time.
197-
198-
## Others
199-
200-
### Create RequestBody
117+
Stack stack = contentstack.stack("API_KEY");
118+
Asset asset = stack.asset();
201119

202-
- JSON Body could be created by using Map passing in the JSONObject or directly create JSONObject.
203-
Let's suppose you have to make json like below:
204-
205-
```java
206-
{
207-
"entry": {
208-
"title": "example",
209-
"url": "/example"
210-
}
120+
// Add Query parameters to the entry
121+
asset.addParam("title'","headeline")
122+
Response<ResponseBody> response = asset.uploadAsset(filePath, description).execute();
123+
if (response.isSuccessful()){
124+
System.out.println(response.body(););
125+
}else {
126+
System.out.println(response.errorBody(););
211127
}
212128
```
213129

214-
- Create request body using HashMap like below
215-
216-
```java
217-
HashMap<String, Object> mapBody = new HashMap<>();
218-
HashMap<String, Object> bodyContent = new HashMap<>();
219-
bodyContent.put("title", "example");
220-
bodyContent.put("url", "/example");
221-
requestBody.put("entry", bodyContent);
222-
JSONObject requestBody = new JSONObject(mapBody)
223-
```
224-
225-
- The other way to create RequestBody using JSONObject like below
226-
227-
```java
228-
JSONObject requestBody = new JSONObject();
229-
JSONObject bodyContent = new JSONObject();
230-
bodyContent.put("title", "example");
231-
bodyContent.put("url", "/example");
232-
requestBody.put("entry", bodyContent);
233-
```
234-
235-
### Documentation
236-
237-
- [Content Management API Docs](https://www.contentstack.com/docs/developers/apis/content-management-api/#api-reference)
238-
- [API References](https://www.contentstack.com/docs/developers/apis/content-management-api/#api-reference)
239-
240-
### Other helpful Links
130+
### Helpful Links
241131

242132
- [Contentstack Website](https://www.contentstack.com/)
243133
- [Official Documentation](https://contentstack.com/docs)
134+
- [Content Management API Docs](https://www.contentstack.com/docs/developers/apis/content-management-api)
244135

245136
### The MIT License (MIT)
246137

247-
Copyright © 2012-2022 [Contentstack](https://www.contentstack.com/). All Rights Reserved Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
138+
Copyright © 2012-2022 [Contentstack](https://www.contentstack.com/). All Rights Reserved
139+
140+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
141+
142+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
143+
144+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<artifactId>cms</artifactId>
77
<packaging>jar</packaging>
88
<name>contentstack-management-java</name>
9-
<version>1.0.0-alpha-SNAPSHOT</version>
9+
<version>1.0.0-SNAPSHOT</version>
1010
<description>Contentstack Java Management SDK for Content Management API, Contentstack is a headless CMS with an
1111
API-first approach
1212
</description>
@@ -40,7 +40,7 @@
4040
</licenses>
4141

4242
<organization>
43-
<name>Contentstack</name>
43+
<name>contentstack</name>
4444
<url>http://contentstack.com</url>
4545
</organization>
4646

src/main/java/com/contentstack/cms/Contentstack.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
2-
/**
3-
* The top most package to access contentstack instance
4-
*/
51
package com.contentstack.cms;
62

73
import com.contentstack.cms.core.AuthInterceptor;
@@ -310,10 +306,8 @@ public Stack stack() {
310306
* @return the stack instance
311307
*/
312308
public Stack stack(@NotNull Map<String, Object> header) {
313-
if (this.authtoken == null)
314-
if (header.size() == 0) {
315-
throw new IllegalStateException(PLEASE_LOGIN);
316-
}
309+
if (this.authtoken == null && header.size() == 0)
310+
throw new IllegalStateException(PLEASE_LOGIN);
317311
return new Stack(this.instance, header);
318312
}
319313

@@ -416,6 +410,7 @@ public static class Builder {
416410
* Instantiates a new Builder.
417411
*/
418412
public Builder() {
413+
// this blank builder constructor
419414
}
420415

421416
/**

src/main/java/com/contentstack/cms/organization/OrganizationService.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.contentstack.cms.organization;
22

3-
import okhttp3.RequestBody;
43
import okhttp3.ResponseBody;
54
import org.json.simple.JSONObject;
65
import retrofit2.Call;

0 commit comments

Comments
 (0)