Utilizing Drupal Developer Content material API Adam Balsam Thu, 08/17/2017 – 13 Drupal 10 Upkeep and Assist Service41 Lightning 2.1.7 features a new top-level element Drupal 10 Upkeep and Assist Service Content material API. Its objective is to present a really primary server-side framework for constructing decoupled apps utilizing Lightning as a backend. It has no robust opinions about how Drupal Developer “front-end” of such an software is applied — out of Drupal Developer field, it merely supplies instruments to ship entities in accordance with Drupal Developer JSON API specification. Typically talking, you possibly can work together with API anonymously in Drupal Developer identical method that an nameless consumer can work together with an ordinary website. So you are able to do issues like get a single piece of content material, or an inventory of content material with out authenticating. For different actions — Drupal Developer sort that might usually require you to be logged in to — you will want to supply an OAuth entry token in Drupal Developer header of your request. Tokens are associated to a consumer and an OAuth consumer, which is related to any variety of consumer roles. You may acquire a token by making a selected HTTP request for it. Let’s undergo some frequent, generic, use instances. I will use cURL in my instance so as to simply take a look at them out for your self. Getting an inventory of content material Drupal Developer API endpoints typically observe Drupal Developer following sample Drupal 10 Upkeep and Assist Service “/jsonapi/{entity-type}/{bundle}”. So if we needed to get an inventory of Primary Web page content material, we might ship a GET request to “/jsonapi/node/web page” Drupal 10 Upkeep and Assist Service curl –request GET –url https Drupal 10 Upkeep and Assist Service//instance.com/jsonapi/node/web page Which might return one thing like this Drupal 10 Upkeep and Assist Service { “information” Drupal 10 Upkeep and Assist Service [ { “type” Drupal 10 Maintenance and Support Service “node–page”, “id” Drupal 10 Maintenance and Support Service “api_test-unpublished-page-content”, “attributes” Drupal 10 Maintenance and Support Service { “nid” Drupal 10 Maintenance and Support Service 1, “uuid” Drupal 10 Maintenance and Support Service “api_test-unpublished-page-content”, “vid” Drupal 10 Maintenance and Support Service 1, “langcode” Drupal 10 Maintenance and Support Service “en”, “status” Drupal 10 Maintenance and Support Service false, “title” Drupal 10 Maintenance and Support Service “Unpublished Page”, “created” Drupal 10 Maintenance and Support Service 1502985175, “changed” Drupal 10 Maintenance and Support Service 1502985175, “promote” Drupal 10 Maintenance and Support Service false, “sticky” Drupal 10 Maintenance and Support Service false, “revision_timestamp” Drupal 10 Maintenance and Support Service 1502985175, “revision_log” Drupal 10 Maintenance and Support Service null, “revision_translation_affected” Drupal 10 Maintenance and Support Service true, “default_langcode” Drupal 10 Maintenance and Support Service true, “path” Drupal 10 Maintenance and Support Service null, “body” Drupal 10 Maintenance and Support Service { “value” Drupal 10 Maintenance and Support Service “–TESTING–“, “format” Drupal 10 Maintenance and Support Service null, “summary” Drupal 10 Maintenance and Support Service null } }, “relationships” Drupal 10 Maintenance and Support Service { “type” Drupal 10 Maintenance and Support Service { “data” Drupal 10 Maintenance and Support Service { “type” Drupal 10 Maintenance and Support Service “node_type–node_type”, “id” Drupal 10 Maintenance and Support Service “8bae5c5c-697d-4b8a-ab22-b72e895a3b24” }, “links” Drupal 10 Maintenance and Support Service { “self” Drupal 10 Maintenance and Support Service “https Drupal 10 Maintenance and Support Service//headlessnightlytfrimmmkug.devcloud.acquia-sites.com/jsonapi/node/page/api_test-unpublished-page-content/relationships/type”, “related” Drupal 10 Maintenance and Support Service “https Drupal 10 Maintenance and Support Service//headlessnightlytfrimmmkug.devcloud.acquia-sites.com/jsonapi/node/page/api_test-unpublished-page-content/type” } }, “uid” Drupal 10 Maintenance and Support Service { “data” Drupal 10 Maintenance and Support Service { “type” Drupal 10 Maintenance and Support Service “user–user”, “id” Drupal 10 Maintenance and Support Service “4d7eb3c7-db6d-4a01-8b3d-7d706d314f87” }, “links” Drupal 10 Maintenance and Support Service { “self” Drupal 10 Maintenance and Support Service “https Drupal 10 Maintenance and Support Service//headlessnightlytfrimmmkug.devcloud.acquia-sites.com/jsonapi/node/page/api_test-unpublished-page-content/relationships/uid”, “related” Drupal 10 Maintenance and Support Service “https Drupal 10 Maintenance and Support Service//headlessnightlytfrimmmkug.devcloud.acquia-sites.com/jsonapi/node/page/api_test-unpublished-page-content/uid” } }, “revision_uid” Drupal 10 Maintenance and Support Service { “data” Drupal 10 Maintenance and Support Service { “type” Drupal 10 Maintenance and Support Service “user–user”, “id” Drupal 10 Maintenance and Support Service “4d7eb3c7-db6d-4a01-8b3d-7d706d314f87” }, “links” Drupal 10 Maintenance and Support Service { “self” Drupal 10 Maintenance and Support Service “https Drupal 10 Maintenance and Support Service//headlessnightlytfrimmmkug.devcloud.acquia-sites.com/jsonapi/node/page/api_test-unpublished-page-content/relationships/revision_uid”, “related” Drupal 10 Maintenance and Support Service “https Drupal 10 Maintenance and Support Service//headlessnightlytfrimmmkug.devcloud.acquia-sites.com/jsonapi/node/page/api_test-unpublished-page-content/revision_uid” } }, “moderation_state” Drupal 10 Maintenance and Support Service { “data” Drupal 10 Maintenance and Support Service { “type” Drupal 10 Maintenance and Support Service “moderation_state–moderation_state”, “id” Drupal 10 Maintenance and Support Service “1a5f02e6-3f14-46a7-a40c-65590c8729a9” }, “links” Drupal 10 Maintenance and Support Service { “self” Drupal 10 Maintenance and Support Service “https Drupal 10 Maintenance and Support Service//headlessnightlytfrimmmkug.devcloud.acquia-sites.com/jsonapi/node/page/api_test-unpublished-page-content/relationships/moderation_state”, “related” Drupal 10 Maintenance and Support Service “https Drupal 10 Maintenance and Support Service//headlessnightlytfrimmmkug.devcloud.acquia-sites.com/jsonapi/node/page/api_test-unpublished-page-content/moderation_state” } }, “scheduled_update” Drupal 10 Maintenance and Support Service { “data” Drupal 10 Maintenance and Support Service [ ] } }, “hyperlinks” Drupal 10 Upkeep and Assist Service { “self” Drupal 10 Upkeep and Assist Service “https Drupal 10 Upkeep and Assist Service//headlessnightlytfrimmmkug.devcloud.acquia-sites.com/jsonapi/node/web page/api_test-unpublished-page-content” } }, … That is fairly verbose. We might simplify Drupal Developer response by including Drupal Developer “fields” parameter. On this instance, we solely need Drupal Developer “title” and “created” fields Drupal 10 Upkeep and Assist Service curl –request GET –url https Drupal 10 Upkeep and Assist Service//instance.com/jsonapi/node/web page ?fields[node–page]=title,created # Word that I am utilizing `[` and `]` right here for readability. These characters must be # encoded with `%5B` and `%5D` respectively if you wish to truly use these # examples. Which might return one thing like this Drupal 10 Upkeep and Assist Service { “information” Drupal 10 Upkeep and Assist Service [ { “sort” Drupal 10 Upkeep and Assist Service “node–page”, “id” Drupal 10 Upkeep and Assist Service “0bee8eb7-0f06-4986-9ca0-e340021a0af3”, “attributes” Drupal 10 Upkeep and Assist Service { “title” Drupal 10 Upkeep and Assist Service “A Web page”, “created” Drupal 10 Upkeep and Assist Service 1502985175 }, “hyperlinks” Drupal 10 Upkeep and Assist Service { “self” Drupal 10 Upkeep and Assist Service “https Drupal 10 Upkeep and Assist Service//{DOMAIN.COM}/jsonapi/node/web page/0bee8eb7-0f06-4986-9ca0-e340021a0af3” } }, { “sort” Drupal 10 Upkeep and Assist Service “node–page”, “id” Drupal 10 Upkeep and Assist Service “4d7eb3c7-db6d-4a01-8b3d-7d706d314f87”, “attributes” Drupal 10 Upkeep and Assist Service { “title” Drupal 10 Upkeep and Assist Service “One other Web page”, “created” Drupal 10 Upkeep and Assist Service 1502985175 }, … Getting a selected piece of content material We are able to request a selected piece of content material by specifying its UUID in Drupal Developer URL Drupal 10 Upkeep and Assist Service curl –request GET –url https Drupal 10 Upkeep and Assist Service//instance.com/jsonapi/node/web page/0bee8eb7-0f06-4986-9ca0-e340021a0af3 Which might return one thing like this (however extra verbose since we did not use Drupal Developer “area” parameter) Drupal 10 Upkeep and Assist Service { “information” Drupal 10 Upkeep and Assist Service { “sort” Drupal 10 Upkeep and Assist Service “node–page”, “id” Drupal 10 Upkeep and Assist Service “0bee8eb7-0f06-4986-9ca0-e340021a0af3”, “attributes” Drupal 10 Upkeep and Assist Service { “title” Drupal 10 Upkeep and Assist Service “A Web page”, “created” Drupal 10 Upkeep and Assist Service 1502985175 }, “hyperlinks” Drupal 10 Upkeep and Assist Service { “self” Drupal 10 Upkeep and Assist Service “https Drupal 10 Upkeep and Assist Service//instance.com/jsonapi/node/web page/0bee8eb7-0f06-4986-9ca0-e340021a0af3” } }, “hyperlinks” Drupal 10 Upkeep and Assist Service { “self” Drupal 10 Upkeep and Assist Service “https Drupal 10 Upkeep and Assist Service//instance.com/jsonapi/node/web page/0bee8eb7-0f06-4986-9ca0-e340021a0af3?fieldspercent5Bnode–pagepercent5D=titlepercent2Ccreated” } } Getting a token You have to to supply an entry token for any request that nameless customers should not licensed to execute. Tokens are granted through Drupal Developer “/oauth/token” endpoint, and requests for a token should embrace a client_id, client_secret, username, and password. OAuth purchasers inherit Drupal Developer permissions of normal consumer roles by deciding on a number of roles on Drupal Developer consumer’s configuration kind, underneath “Scopes”. A typical setup would contain Drupal Developer following steps Drupal 10 Upkeep and Assist Service Create a position (“/admin/entry/roles”) with Drupal Developer permissions you need Drupal Developer consuming app to be allowed to carry out. Create a consumer (“/admin/folks/create”) that Drupal Developer API will use and assign that consumer Drupal Developer position you simply created. Create an OAuth2 consumer (“/admin/config/folks/simple_oauth/oauth2_client/add”) and assign it Drupal Developer identical position as Drupal Developer consumer you simply created through Drupal Developer Scopes part. As soon as that is carried out, you need to use Drupal Developer following to acquire an entry token, the place Drupal 10 Upkeep and Assist Service CLIENT_ID = Drupal Developer OAuth2 consumer UUID, displayed after creation of Drupal Developer consumer in Step 3 at “/admin/entry/purchasers” SECRET = Drupal Developer “New Secret” you selected when creating Drupal Developer consumer in Step 3 USERNAME = Drupal Developer username of Drupal Developer consumer you created in Step 2 PASSWORD = Drupal Developer password you gave Drupal Developer consumer in Step 2 curl -X POST -d “grant_type=password &client_id={CLIENT_ID} &client_secret={SECRET} &username={USERNAME} &password={PASSWORD}” https Drupal 10 Upkeep and Assist Service//instance.com/oauth/token Which ought to generate a response like this Drupal 10 Upkeep and Assist Service { “token_type” Drupal 10 Upkeep and Assist Service “Bearer”, “expires_in” Drupal 10 Upkeep and Assist Service 300, “access_token” Drupal 10 Upkeep and Assist Service “eyJ0eXAiOiJKV1QiLCJhbGciOiJSUz…”, “refresh_token” Drupal 10 Upkeep and Assist Service “def50200bdb9093a7a6cc837dhcd1…” } If you wish to give it a attempt with out your individual sandbox setup, Headless Lightning has a nightly construct deployed to https Drupal 10 Upkeep and Assist Service//headlessnightlytfrimmmkug.devcloud.acquia-sites.com with a consumer and consumer preconfigured. So you need to have the ability to use Drupal Developer “/oauth/token” endpoint there to get a sound token to our sandbox in case you’re curious. Give it a attempt! Copy and paste Drupal Developer following right into a terminal window Drupal 10 Upkeep and Assist Service curl –request POST –data “grant_type=password &client_id=api_test-oauth2-client &client_secret=oursecret &username=api-test-user &password=admin” https Drupal 10 Upkeep and Assist Service//headlessnightlytfrimmmkug.devcloud.acquia-sites.com/oauth/token Utilizing a token Upon getting a token, it is easy to get information that nameless customers aren’t licensed to entry. Simply add an Authorize header to your request, like so (changing {ACCESS_TOKEN} with Drupal Developer access_token worth in Drupal Developer /oauth/token response) Drupal 10 Upkeep and Assist Service –header ‘authorization Drupal 10 Upkeep and Assist Service Bearer {ACCESS_TOKEN}’ So as an instance we needed to get a selected piece of content material identical to Drupal Developer “Get a selected piece of content material” instance above. However on this case, Drupal Developer content material is unpublished and due to this fact nameless customers will not have the ability to entry it. On condition that Drupal Developer token was acquired Drupal 10 Upkeep and Assist Service For an OAuth consumer that has a scope with Drupal Developer “View unpublished content material” permission For consumer account that has a job with Drupal Developer identical permission We are able to efficiently make Drupal Developer identical request for an unpublished piece of content material if we embrace Drupal Developer token in an authorization header like this Drupal 10 Upkeep and Assist Service curl –request GET –header ‘authorization Drupal 10 Upkeep and Assist Service Bearer {ACCESS_TOKEN}’ –url https Drupal 10 Upkeep and Assist Service//instance.com/jsonapi/node/web page/api_test-unpublished-page-content # The place `api_test-unpublished-page-content` is Drupal Developer UUID of some piece of # unpublished content material Word how this request is similar to Drupal Developer nameless request above besides that it Drupal 10 Upkeep and Assist Service Requests a useful resource that requires authorization Consists of an “authorization” header Given Drupal Developer authorization header, Content material API will authenticate Drupal Developer request after which authorize it (or not) based mostly on Drupal Developer permissions of Drupal Developer related consumer and consumer. Creating content material You may create new content material by sending a POST request to “jsonapi/{entity-type}/{bundle}”. You will want to incorporate a selected Content material-Kind header, and most configurations would require Authorization as nicely since nameless customers often cannot create content material. For instance Drupal 10 Upkeep and Assist Service curl –request POST –data ‘{“information” Drupal 10 Upkeep and Assist Service {“sort” Drupal 10 Upkeep and Assist Service “node–page”,”attributes” Drupal 10 Upkeep and Assist Service {“title” Drupal 10 Upkeep and Assist Service “Created through JSON API”}}}’ –header ‘Content material-Kind Drupal 10 Upkeep and Assist Service software/vnd.api+json’ –header ‘authorization Drupal 10 Upkeep and Assist Service Bearer {ACCESS_TOKEN}’ –url https Drupal 10 Upkeep and Assist Service//instance.com/jsonapi/node/web page Content material vs Configuration Entities makes a distinction between Content material and Configuration entities. Typically content material entities are additional distinguished as being renderable and/or bundle-able. Content material API makes no such distinctions. In case your API consumer/consumer have permission to work together with an entity, it will possibly accomplish that by way of Drupal Developer API. Meaning you are able to do issues like add fields to a content material sort through Drupal Developer API, or edit a moderation state transition. Headless Lightning The whole lot described right here will be carried out with Lightning. However in case you’re constructing a decoupled software, you would possibly wish to take a look at Headless Lightning, which has a couple of extra options (and some options eliminated) which make it extra appropriate for decoupled Drupal 10 functions. Drupal 10 Improvement and Assist
Acquia Lightning Weblog Drupal 10 Upkeep and Assist Service Utilizing Drupal Developer Content material API

Call Us: 1(800)730-2416
Pixeldust is a 20-year-old web development agency specializing in Drupal and WordPress and working with clients all over the country. With our best in class capabilities, we work with small businesses and fortune 500 companies alike. Give us a call at 1(800)730-2416 and let’s talk about your project.

FREE Drupal SEO Audit
Test your site below to see which issues need to be fixed. We will fix them and optimize your Drupal site 100% for Google and Bing. (Allow 30-60 seconds to gather data.)
Acquia Lightning Weblog Drupal 10 Upkeep and Assist Service Utilizing Drupal Developer Content material API
On-Site Drupal SEO Master Setup
We make sure your site is 100% optimized (and stays that way) for the best SEO results.
With Pixeldust On-site (or On-page) SEO we make changes to your site’s structure and performance to make it easier for search engines to see and understand your site’s content. Search engines use algorithms to rank sites by degrees of relevance. Our on-site optimization ensures your site is configured to provide information in a way that meets Google and Bing standards for optimal indexing.
This service includes:
- Pathauto install and configuration for SEO-friendly URLs.
- Meta Tags install and configuration with dynamic tokens for meta titles and descriptions for all content types.
- Install and fix all issues on the SEO checklist module.
- Install and configure XML sitemap module and submit sitemaps.
- Install and configure Google Analytics Module.
- Install and configure Yoast.
- Install and configure the Advanced Aggregation module to improve performance by minifying and merging CSS and JS.
- Install and configure Schema.org Metatag.
- Configure robots.txt.
- Google Search Console setup snd configuration.
- Find & Fix H1 tags.
- Find and fix duplicate/missing meta descriptions.
- Find and fix duplicate title tags.
- Improve title, meta tags, and site descriptions.
- Optimize images for better search engine optimization. Automate where possible.
- Find and fix the missing alt and title tag for all images. Automate where possible.
- The project takes 1 week to complete.
