Nextcloud API Overview and Features

Author

Reads 1.2K

Men and Women Sitting in front of Computers and a Large Screen
Credit: pexels.com, Men and Women Sitting in front of Computers and a Large Screen

Nextcloud API is designed to be highly customizable, allowing developers to extend its functionality through third-party apps and plugins.

The API provides a robust set of features for data synchronization, including real-time updates and file versioning.

Nextcloud API is built using modern web technologies, such as REST and WebSockets, making it easy to integrate with other systems and applications.

The API's flexibility and scalability make it an ideal choice for large-scale deployments, from small businesses to enterprise environments.

API

To find out which API levels are supported, you can make a request to the following route: https://yournextcloud.com/index.php/apps/news/api. This route returns an array of API levels as JSON, which you can parse to determine the supported levels.

To determine if a user is running an older News version than 8.8.0, you can make a request to https://yournextcloud.com/index.php/apps/news/api/v1-2/version. This route returns the version of the News app, which will be v1-2 if the user is running an older version.

Here's an interesting read: Https Nextcloud Docker

Credit: youtube.com, Automated API documentation for Nextcloud using OpenAPI | Nextcloud Conference 2023

You can also try making a call to the sync route first, and if it fails with an HTTP 404, then make the API level detection call. This can be a cost-effective approach, as API level detection calls can be expensive.

Here are the supported API levels that can be returned from the API level detection call:

  • v1-2
  • Other API levels (e.g. v2, v3, etc.)

Note that future News app versions may remove the v1-2 API level, so it's essential to check which API levels are actually supported.

Authentication and Authorization

Authentication can happen via username/password or OIDC tokens, depending on the specific needs of your application.

There are multiple ways to authenticate with the Nextcloud API, including HTTP Basic auth and HTTP Bearer auth.

HTTP Basic auth works with normal user credentials, such as email and other identifiers, but not all endpoints support it.

App passwords obtained through the Web UI or login flow are recommended for certain endpoints that don't work with Basic auth.

Some endpoints don't require authentication at all, while others provide extended information when a request is authenticated.

The @nextcloud/auth package provides information about the current user and session, and can be found in the Nextcloud libraries documentation.

Using the API

Credit: youtube.com, Working with Nextcloud JavaScript APIs

Using the API can be a bit overwhelming, especially for beginners. The Unit Tests should give you sufficient examples on using the Api.

To get started, you'll want to familiarize yourself with the available methods and endpoints. The Unit Tests should give you sufficient examples on using the Api.

One of the most important things to keep in mind is that the API is designed to be user-friendly, even for those who are new to programming. The Unit Tests should give you sufficient examples on using the Api.

As you explore the API, you'll find that it's incredibly flexible and can be used in a variety of ways. The Unit Tests should give you sufficient examples on using the Api.

Remember, the API is constantly evolving, so be sure to check back regularly for updates and new features. The Unit Tests should give you sufficient examples on using the Api.

Additional reading: New Relic Api

API Features and Capabilities

Credit: youtube.com, Working with Nextcloud's JavaScript APIs - Christoph Wurst

The Nextcloud API has some really cool features that make it super useful for developers.

Clients can obtain capabilities provided by the Nextcloud server and its apps via the capabilities OCS API.

This allows developers to tap into the full range of Nextcloud's functionality and build custom apps that integrate seamlessly with the platform.

Capabilities

The Capabilities API is a powerful tool that allows clients to obtain capabilities provided by the Nextcloud server and its apps via the capabilities OCS API.

You can use this API to get a list of capabilities, which will give you a better understanding of what the Nextcloud server and its apps can do.

The capabilities OCS API is a specific API that is designed to provide this information, making it easy to access and utilize the capabilities of the Nextcloud server and its apps.

This API is an important part of the Nextcloud ecosystem, and is used by clients to get the information they need to interact with the server and its apps.

Check this out: Nextcloud Server

Detailed view of a black data storage unit highlighting modern technology and data management.
Credit: pexels.com, Detailed view of a black data storage unit highlighting modern technology and data management.

The Nextcloud Router package provides helpers to generate URLs for accessing assets and REST APIs of your app or the Nextcloud server, making it easier to work with capabilities.

With the Nextcloud Router package, you can easily generate URLs for accessing capabilities, making it a valuable tool for working with the Capabilities API.

Theming Capabilities

Theming capabilities allow client developers to adjust the look of clients to the theming of different Nextcloud instances.

Client developers can adjust the look of clients to the theming of different Nextcloud instances through the capabilities API, which exposes values of the theming app.

Instead of using the primary color value, use color-element-bright for bright backgrounds and color-element-dark for dark backgrounds.

For radio buttons, input borders, and more, using color-element-bright and color-element-dark ensures that items remain visible even when the primary color is set to a dark value like #000000.

The background value can be a URL to a background image or a hex color value.

In the Nextcloud web UI, the top header uses color, while everything else uses color-element-*.

Text and icons on these elements should use color-text to ensure consistent styling.

Filtering Auto-Complete Results

Credit: youtube.com, Low-Code Feature Focus: Dropdown with Autocomplete using API Endpoint Methods

You can further filter auto-complete results on the PHP side using the OCP\Collaboration\AutoComplete\AutoCompleteEvent event.

This event gives you access to the current result set, the item and share types, and other information that can be used to limit the autocomplete results.

By using this event, you can filter the results to only include users who are actually in the current chat conversation.

This can be a useful feature for applications where only relevant results are desired.

Sharing

Sharing is a key feature of Nextcloud's API, allowing users to interact with the Files sharing app. This includes detecting if the current page is a public share.

The @nextcloud/sharing package provides helpers for interacting with the Files sharing app. It can be used to retrieve the sharing token.

Public shares can be detected using the @nextcloud/sharing package.

Expand your knowledge: Azure Web Api

Updater

The Updater API is a powerful tool for updating feeds in a more efficient way than the built-in cron updater. It can be accessed through REST or Nextcloud console API.

Colorful magnetic numbers scattered around a file labeled 'TAXES', symbolizing financial organization.
Credit: pexels.com, Colorful magnetic numbers scattered around a file labeled 'TAXES', symbolizing financial organization.

To use the Updater API, you'll need to follow a specific process. This involves cleaning up before the update, getting all feeds and user IDs, running the update for each feed and user ID, and cleaning up after the update. The reference implementation in Python can give you a good idea of how to design your own updater.

If you're using the REST API, you'll need to provide Basic Auth and ensure the user is in the admin group. On the other hand, if you're using the Nextcloud console API, no authorization is required.

Here's a summary of the REST API routes you'll need to use:

  • GET /updater/before-update (Authentication: admin)
  • GET /updater/all-feeds (Authentication: admin)

These routes will help you get started with the Updater API and update your feeds efficiently.

API Development and Tools

The Nextcloud API is a powerful tool for interacting with your cloud storage, and understanding how to use it can be a game-changer for your productivity.

Credit: youtube.com, Creating a Fever API for Nextcloud News, Part 1: Exploration / Mocking

C# classes are provided for the objects you can send to or receive from the Nextcloud API, making it easy to work with the API in your code.

To create a new group, you can use the Group.Create method, which calls the Nextcloud API to create the group. Similarly, to get group details, you can use the Group.Get method.

The Nextcloud API itself usually only returns the first few items in a list, so you'll need to use the ApiList class to get all the items. This class has a method called All(Api) that will return an IEnumerable of the listed objects, making it easy to work with large lists.

You can use Linq calls like Any or First to stop getting data when the first item that matches the selection function is found, making your code more efficient.

The Nextcloud API is compatible with multiple .NET frameworks, including .NET 5.0, .NET 6.0, and .NET 7.0, among others.

Here's a list of some of the compatible .NET frameworks:

The Nextcloud API is also compatible with multiple mobile platforms, including Android and iOS.

The API is written in TypeScript, which allows for better API documentation and ensures compatibility with the Nextcloud server.

API Security and Compatibility

Credit: youtube.com, API Security Explained

API security is crucial to prevent exploits like MITM attacks, which can be especially problematic in the mobile world where users are often connected to untrusted networks. Always enforce SSL certificate verification and never offer a way to turn it off.

All string fields in a JSON response expect an item's body are not sanitized, making them vulnerable to XSS attacks if not properly escaped before rendering. To prevent this, ensure all string fields are sanitized before rendering.

Basic Auth headers can easily be decrypted by anyone, so only send them if you're accessing an HTTPS website or display a warning if the user chooses HTTP. Storing basic auth authentication credentials in clear text is also a security risk, so warn users about this.

Here's a table of the API calls that return a list of items:

Security Guidelines

Security Guidelines are crucial to prevent security exploits. Always enforce SSL certificate verification and never offer a way to turn it off, as this is especially important in the mobile world where users are almost always connected to untrusted networks.

Recommended read: Nextcloud Security

Credit: youtube.com, Understanding The Fundamentals of API Security | How APIs are Attacked and How to Secure Them

A user running a self-signed certificate on their server should be directed to one of the many ways to sign their certificate for free, such as letsencrypt.com. This will help prevent MITM attacks.

Don't forget to sanitize all string fields in a JSON response's item body to prevent XSS attacks. This is crucial because unsanitized strings can be used to inject malicious code.

Basic Auth headers can be decrypted by anyone, so only send them if you're accessing an HTTPS website or display a clear warning to the user if they choose HTTP. This is because base64 is an encoding, not an encryption.

When creating a feed, be aware that adding basic auth authentication credentials must be stored in clear text. This means anyone with access to your database can read and use them to access the website, so warn the user about this.

To prevent your app from being targeted by an XSS attack, remember to set the window.opener property to null and/or add a rel="noreferrer" to your link when building a client in JavaScript or using a link with target="blank".

Here are some key security guidelines to keep in mind:

  • Enforce SSL certificate verification.
  • Sanitize all string fields in a JSON response's item body.
  • Only send Basic Auth headers over HTTPS or display a clear warning.
  • Warn users about storing basic auth credentials in clear text.
  • Set the window.opener property to null and/or add a rel="noreferrer" to prevent XSS attacks.

Compatibility

Credit: youtube.com, What is API security? | Cyber Work Podcast

Compatibility is crucial for smooth API interactions. The provided packages are designed to be compatible with all supported Nextcloud releases.

Major version bumps in the packages may indicate non-backwards compatible changes. This is because the developers may have to change an API in a non-backwards compatible way in the future.

Read the changelogs carefully to stay informed about any changes.

API Data Management

API Data Management is crucial for Nextcloud, as it provides a centralized platform for managing and securing data. Nextcloud's API allows for seamless integration with various applications and services.

Data stored in Nextcloud is encrypted, ensuring that sensitive information remains protected. This encryption is a key feature of Nextcloud's API, allowing users to control access and permissions for their data.

By using the Nextcloud API, users can automate tasks, integrate with other services, and create custom applications, making data management more efficient and streamlined.

Here's an interesting read: What Is Azure Api Management

L10n

L10n is a crucial aspect of API data management, and it's great to see that Nextcloud has a dedicated package for it. The @nextcloud/l10n package provides everything around localization, including access to the current user's locale.

This package is a one-stop-shop for all your localization needs, and it's well-documented at https://nextcloud-libraries.github.io/nextcloud-l10n/.

Files

A Man Looking at Files at an Office
Credit: pexels.com, A Man Looking at Files at an Office

The Files package provides methods to access the public API of the Files app, which can be accessed through the Nextcloud-libraries GitHub page. This package is a crucial tool for working with files and folders in Nextcloud.

Nextcloud-files is a package that offers helper functions to access Nextcloud files using WebDAV, making it easier to manage and interact with files across different platforms.

API Endpoints and Methods

The Nextcloud API has a well-structured set of endpoints that can be accessed using getters on the NextcloudClient.

Endpoints are grouped by app, and most apps also group their endpoints again, making it easy to navigate and find what you need.

To create a folder, you'll need to send a POST request to the /folders route, which requires authentication.

You can create a feed by sending a POST request to the /feeds route, also requiring authentication.

Here are the details of the POST request for creating a feed:

Initial State

Credit: youtube.com, What is an API Endpoint?

To use the Nextcloud API, you need to provide an Api Username and Password, which can be done through OAuth2 for some calls, but not for admin ones.

The Api instance is created by passing an object that implements ISettings, such as the default Settings class that reads settings from a json file.

You can use the @nextcloud/initial-state package to retrieve your stored data on page load, which is the counterpart for the \OCP\IInitialStateService on the back-end.

The package can be found in the documentation at https://nextcloud-libraries.github.io/nextcloud-initial-state/.

Endpoints

Endpoints are grouped by app, making it easier to navigate the API.

Most apps group their endpoints again, which can be accessed using getters on the NextcloudClient.

This means you can access the endpoints of each app in a more organized and structured way.

The NextcloudClient provides a convenient way to access the endpoints, making it simpler to use the API.

Creating a Folder

Creating a Folder is a straightforward process that requires a POST request to the /folders route. This method is authenticated, so you'll need to be logged in to create a new folder.

Elderly man wearing a face shield organizes files in a black and white office archive.
Credit: pexels.com, Elderly man wearing a face shield organizes files in a black and white office archive.

To create a folder, you'll need to send a POST request to the /folders route. You can do this using a tool like Postman or by writing code that makes the request.

The response to a successful folder creation will be a 200 status code, along with the created or existing folder in full. This is useful if you need to access the folder's details.

Here are the possible responses you might get when creating a folder:

  • 200: Folder was created successfully
  • 400: Folder creation error, check the error object:
  • code: 1: folder name is empty

Creating a Feed

Creating a feed is a straightforward process that requires a POST request to the /feeds route. Authentication is necessary for this request.

The request should include the following parameters: url, folderId, and optionally name, basicAuthUser, basicAuthPassword, ordering, isPinned, and fullTextEnabled.

Here are the details for each parameter:

  • url: This should be the full schema of the URL, such as https://the-url.com. If the user omits the schema, it's recommended to prepend https.
  • folderId: This is a 64-bit integer that represents the feed's folder. If no folder is specified, use 0.
  • name (optional): If specified, this will be the feed's name. If not provided, the name will be taken from the RSS/Atom feed.
  • basicAuthUser (optional) and basicAuthPassword (optional): If provided, these will be used to send basic auth headers for the feed.
  • ordering (optional), isPinned (optional), and fullTextEnabled (optional): These parameters are explained in the Feeds section.

The response will be a 200 status code if the feed is created successfully, or a 400 status code with an error object if there's an issue.

API Integration and Interoperability

Credit: youtube.com, Nextcloud integration topics by Julius Härtl 🆒 #COOLDays 2023

The Nextcloud API allows for seamless integration with other applications and services, making it a versatile and adaptable platform.

Nextcloud's API is built on top of the REST architecture, which enables developers to easily interact with the platform's features and data.

This architecture allows for easy integration with other applications, enabling users to access their data from multiple sources.

One of the key benefits of Nextcloud's API is its ability to handle large amounts of data, making it suitable for applications that require high scalability.

Nextcloud's API also supports various authentication methods, including OAuth and JWT, which provide secure and flexible authentication options.

The API's flexibility and scalability make it an ideal choice for developers looking to build custom applications on top of Nextcloud.

See what others are reading: Google Data Studio Api

API Libraries and Frameworks

Nextcloud API libraries provide a convenient way to interact with the Nextcloud server. They handle authentication and special headers for you, so you can focus on your app development.

Credit: youtube.com, Nextcloud client with provider registration API

The @nextcloud npm packages offer the current front-end APIs for Nextcloud apps. You can use them to build your own apps and integrations.

@nextcloud/axios is a specific package that provides an Axios HTTP client instance. This instance is ready to send requests to the Nextcloud server, making it easy to get started with API requests.

Npm Packages

Npm Packages are a crucial part of Nextcloud apps, providing the current front-end APIs.

@nextcloud npm packages are specifically designed for Nextcloud apps, making them a go-to choice for developers.

These packages offer a range of benefits, including ease of use and integration with Nextcloud's existing infrastructure.

@nextcloud npm packages have become the standard for Nextcloud app development, with many developers relying on them for their projects.

By using @nextcloud npm packages, developers can save time and effort, focusing on building innovative features rather than reinventing the wheel.

Axios

Axios is a popular HTTP client library that makes sending requests to a Nextcloud server a breeze. The @nextcloud/axios package provides an Axios instance ready to use, eliminating the need to worry about authentication and special headers.

This package is well-documented and can be found at https://nextcloud-libraries.github.io/nextcloud-axios/. It's a convenient solution for developers who want to focus on building their application without getting bogged down in the details of HTTP requests.

Frequently Asked Questions

Is Nextcloud a WebDAV?

Nextcloud supports the WebDAV protocol, allowing seamless synchronization with Nextcloud Files. You can connect and access your files using WebDAV.

Katrina Sanford

Writer

Katrina Sanford is a seasoned writer with a knack for crafting compelling content on a wide range of topics. Her expertise spans the realm of important issues, where she delves into thought-provoking subjects that resonate with readers. Her ability to distill complex concepts into engaging narratives has earned her a reputation as a versatile and reliable writer.

Love What You Read? Stay Updated!

Join our community for insights, tips, and more.