Skip to main content

Setting up for hal_json RESTful services

The development version of the app database is held on the staging site.  Note all development and testing will be completed on the staging site.

Drupal 9 uses:

  • HAL : Serializes entities using Hypertext Application Language.
  • RESTful Web Services

For testing purposes you can use either of the following Chrome extensions:

  • Postman;
  • DHC

 

RESTful query user - Drupal

The user parameters provides details about a specific user based on the following parameters:

  • User uid;

The output of this query will return user profile data only of the fields containing data.  An example of the data returned includes, but is not limited to the following:

REST API Drupal user

The user API, was originally created under the General Documenation area (see Query - user).  I'm creating a new user API document under the API documentation area.

Calling a query

To call a user query the details are required:

API REST user login the right way

If you are receiving the following 403 errors:

  • "message": "The used authentication method is not allowed on this route."
  • "message": "This route can only be accessed by anonymous users."

Then keep reading for how to resolve them.

 

Attempting to log in to a Drupal site using REST API and I had to battle a few head winds along the way.  What is worse, they were self imposed!

 

Uploading plist data to the server using an API

I had an instance where I needed to move content from a plist to the server database.  To achieve this step, I added a few lines of code where the plist was called and added a call to the API so the data would be on the server.

The original code appeared as:

Registering users via REST

Registering a user via REST is an important process particularly when the requests come from a mobile device.

In working through the process you might have come across error message like:

403 Forbidden : "Only anonymous users can register a user."

422 Unprocessable Entity : "A Password cannot be specified. It will be generated on login."

So how did I get these and what to do?

POST image Guzzle error

While I have posted an article about how to POST an image using REST in Drupal 8... the journey there can be slow.  Crawling through the errors to eventually spot the missing link.  For me the how to is as important as the solution.

On the journey I did receive the following 404 Not Found error:

POST image using RESTUI

Adding an image via RESTUI can be done in a snap... once you know how!  I have spent a good amount of time (days) researching how come my scripts weren't running correctly.

POST:

authentication: basic,

formats: hal_json

Assigning the wrong user against a new comment using REST

You have been working hard on getting comments being added (POST) through REST in Drupal 8.  However, now you are seeing the following Assigning the wrong user against a new comment - and most likely the new comment is being assigned to the site admin.  

The error here is related to the _embedded uuid.

Subscribe to REST