Here are a few examples of actually consuming the Milk API in Javascript with axios. If you are using something else, hopefully these examples will be easy enough to translate into your language of choice.
import axios from "axios";
const appUUID = "PN4BZCE3"
const params = {
access_token: "umQLjqnWwPQjQH0uSy8QhKKZfobdSr4NIjV"
};
const req = await axios.post(
"https://milkcms.com/api/cdn/" + appUUID,
params // Only parameter is the access token
);
if (req.data.error) {
console.log(req.data.error);
} else {
console.log(req.data.contents);
}
import axios from "axios";
const appUUID = "PN4BZCE3"
const params = {
access_token: "umQLjqnWwPQjQH0uSy8QhKKZfobdSr4NIjV",
content_type: "article", // Content Type must be specified to query fields
fields: {
"title": "Wandering the Pastures" // Only content with this title will be returned
}
};
const req = await axios.post(
"https://milkcms.com/api/cdn/" + appUUID,
params
);
if (req.data.error) {
console.log(req.data.error);
} else {
console.log(req.data.contents);
}
import axios from "axios";
const appUUID = "PN4BZCE3"
const params = {
access_token: "umQLjqnWwPQjQH0uSy8QhKKZfobdSr4NIjV",
content_type: "article",
fields: {
"tags": ["Agriculture", "Food"] // Content with both Agriculture and Food tags
}
};
const req = await axios.post(
"https://milkcms.com/api/cdn/" + appUUID,
params
);
if (req.data.error) {
console.log(req.data.error);
} else {
console.log(req.data.contents);
}
Same code as above with this line change:
"tags[any]": ["Agriculture", "Food"]
"any" can be replaced will "all" for the default effect
import axios from "axios";
const appUUID = "PN4BZCE3"
const params = {
access_token: "umQLjqnWwPQjQH0uSy8QhKKZfobdSr4NIjV",
content_type: "article",
field: "tags"
};
const req = await axios.post(
"https://milkcms.com/api/cdn/" + appUUID + "/field_options,
params
);
if (req.data.error) {
console.log(req.data.error);
} else {
console.log(req.data.contents);
}
If you'd prefer to use URL parameters rather than a JSON body, here's a simple example. Without a JSON body, you can you a GET request rather than a POST.
import axios from "axios";
const req = await axios.get(
`https://milkcms.com/api/cdn/PN4BZCE3?access_token=umQLjqnWwPQjQH0uSy8QhKKZfobdSr4NIjV
&content_type=article
&fields.title=Wandering the Pastures`
);
if (req.data.error) {
console.log(req.data.error);
} else {
console.log(req.data.contents);
}