Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
umbraco-restapi
Advanced tools
Javascript Client Library for working with the Umbraco Rest API
Install the umbraco-restapi package through npm:
npm install umbraco-restapi
Get access to the api by including it in your project and supplying site and credentials:
var umbraco = require('umbraco-restapi');
//this is bound to change as we roll out proper auth
var siteConfiguration = {
host: "https://domain.s1.umbraco.io",
username: "email@umbraco.dk",
password: "secret"
};
//to use async / await we must run all code inside a async function
async function run(){
//create a new instance of the client
var umb = new umbraco.client();
//then connect to authenticate and generate a token
//this step will change when authentication is updated
await umb.connect(siteConfiguration);
//client is connected and ready
//get the site
var site = await umb.content.site();
//returns {representation, resource};
console.log("site name: " + site.representation.body.name);
//returns {representation, resource}
//representation holds children as embedded resources
var children = await umb.content.children(site.resource);
//embedded is a dictionary of content with the url as key so fetch all values
//iterate through the names of all content
Object.values(children.representation.embedded).forEach(x => {
console.log(x.name);
});
}
//run the async function
run();
Copy the entire code above into a file called app.js and run the file with node:
node app.js
Create as a new and connect using a site configuration using async connect(config)
var umbraco = require('umbraco-restapi');
var client = new umbraco.client();
umb.connect({host,login,password}).then(function() {
//ready
});
All methods are async so must be returned as either a promise or using async/await:
async function run(){
var content = await client.content.get(1123);
console.log(content.representation);
}
run();
//or
client.content.get(1123).then(function(response){
console.log(response.representation);
});
All functions return a combination of a representation of the data and a resource which describes where the data comes from.
All methods returning collecions are paged and have a pagesize of 100 set by default.
Represents the data retrieved and follows the HAL/Api json spec:
{
body: {
name: "Hello",
id: 1234,
url: "/hello/hello
properties: {
bodyText: "World",
summary: "Such summary"
}
},
//contains links to related urls to call
links : []
//contains content collections - used when multiple items
//are returned, such as .children, descendants or .search
embedded: []
}
A HAL-compatible resource is returned to allow users to follow the provided HAL-links into the API without hardcoding urls in their code.
var content = await client.content.get(1234);
var children = await content.follow('children');
Documentation on link follows are available on: https://github.com/evert/ketting
Read-only api using published content
Available on the client as client.content - eg client.content.get(1234)
Given a integer id - returns a single content item as
{representation, resource}
returns the first root content item
returns all root content items
returns all children below a given parent, parent can be a number
a resource
or a options object:
{
id: 1234,
page: 0,
size: 100
}
returns all descendants below a given parent, parent can be a number
a resource
or a options object:
{
id: 1234,
page: 0,
size: 100
}
returns all acestors above a given content item, item can be a number
a resource
or a options object
:
{
id: 1234,
page: 0,
size: 100
}
Searches all published content - query can be string
or a options object
- the query must a lucene compatible query.
{
query: 'bodyText:hey AND summary:Jan',
page: 0,
size: 100
}
Queries all published content - query can be string
or a options object
- the query must a XPATH compatible query.
The Id provided is the root of where the query should start
{
query: '/root/homepage/products',
page: 0,
size: 100,
id: 1234 (optional)
}
Returns a single content item matching the given url - url must be a string
Returns a collection of published content tagged with the given tag, query can be either a string
or a options object
{
tag: 'umbraco',
group: 'news'
size: 100,
page: 0
}
Read and write api for all media
Available on the client as client.media - eg client.media.get(1234)
Given a integer id - returns a single media item as
{representation, resource}
Creates a new media item - media is a object following the representation syntax:
var media = {
parent: 1234,
name: "My new media",
properties: {
property: 1234,
bodyText: "hello!"
}
}
await client.media.create(media);
Updates an exisitng item - id is a number
media is an object following the representation syntax:
var media = {
parent: 1234,
name: "My new media",
properties: {
property: 1234,
bodyText: "hello!"
}
}
await client.media.update(id, media);
Deletes an exisitng item - id is a number
returns all root media items
returns all children below a given parent, parent can be a number
a resource
or a options object:
{
id: 1234,
page: 0,
size: 100
}
returns all descendants below a given parent, parent can be a number
a resource
or a options object:
{
id: 1234,
page: 0,
size: 100
}
Searches all media - query can be string
or a options object
- the query must a lucene compatible query.
{
query: 'umbracoFile:hey AND name:Jan',
page: 0,
size: 100
}
Read and write api for all members
Available on the client as client.members - eg client.members.get(1234)
Given a integer id - returns a single member item as
{representation, resource}
Creates a new member - member is a object following the representation syntax:
var member = {
name: "My name is",
email: "email@domain.com",
password: "secret",
properties: {
property: 1234,
bodyText: "hello!"
}
}
await client.members.create(member);
Updates an exisitng item - id is a number
member is an object following the representation syntax:
var member = {
name: "Jon Snow,
properties: {
property: 1234,
bodyText: "So cold!"
}
}
await client.members.update(id, member);
Deletes an exisitng item - id is a number
Searches all media - query can be string
or a options object
- the query must a lucene compatible query.
{
query: 'umbracoFile:hey AND name:Jan',
page: 0,
size: 100
}
Read and write api for relations between media, content and members only
Available on the client as client.relations - eg client.relations.get(1234)
Given a integer id - returns a single relation as
{representation, resource}
Creates a new relation item - media is a object following the representation syntax:
var relation = {
parent: 1234,
child: 2234
}
await client.relations.create(realtion);
Updates an exisitng relation - id is a number
relation is an object following the representation syntax:
var relation = {
parent: 1234,
child: 2234
}
await client.relations.update(id, relation);
Deletes an exisitng relation - id is a number
returns all child relations of a given parent
returns all parent relations of a given child
FAQs
Javascript library for accessing Umbraco website API
The npm package umbraco-restapi receives a total of 1 weekly downloads. As such, umbraco-restapi popularity was classified as not popular.
We found that umbraco-restapi demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.