0

I'm attempting to edit a field in Drupal using the restui module. It is a field type "Iframe" out of the iframe module and is saved to the database in the node__field_pocdart_iframe table. I can edit the title of the content node with the "Content: PATCH" resource enabled and the python script below, but when I target the iframe field inside that node, it returns 500 Service unavailable: InvalidArgumentException: Field field_pocdart_iframe is unknown. Is the restui module able to edit custom fields? The "Field" resource is read-only. If not, is there a "safe" method of doing so? I'm hoping for a solution that doesn't require editing the database table directly.

Drupal Version: 10.4.0 REST UI Version: 8.x-1.22

import requests
import base64
import json

class DrupalRequests:
    def __init__(self):
        """Init for class ZoomRequest
    
        Initializes ZoomRequest class with a number of environmental variables
    
        """
    
        # request an OAuth access token from Zoom
        clientId = "generic_user"
        clientSecret = "<redacted>"
        authString = clientId + ':' + clientSecret
        self.auth_encoded = base64.b64encode(authString.encode("utf-8")).decode("utf-8")
        # OAuth request headers
        self.headers = {
            'Authorization': 'Basic ' + self.auth_encoded,
            'Accept': 'application/vnd.api+json'
        }
        self.base_url = 'http://<my_ip>/'

    def patch_node(self, path, key, value): 
        headers = {
            'Authorization': 'Basic ' + self.auth_encoded,
            'Content-type': 'application/json'
        }
        
        endpoint = self.base_url + path + '?_format=json'

        data = {
            "title": [
                {
                    "value": "Example node title UPDATED!"
                }
            ],
            "type": [{"target_id":"article"}]
        }

        data_json = json.dumps(data)

        response = requests.patch(
            endpoint,
            headers = headers,
            data = data_json)
        return response


rest = DrupalRequests()
response = rest.patch_node('dashboard/testSchedule', 1, 2)
print(response.content)
print(response.reason)

Adjusted json with the target field:

data = {
            "field_pocdart_iframe": [
                {
                    "url":"UPDATED"

                }
            ],
            "type": [{"target_id":"article"}]
        }

Full error:

b'The website encountered an unexpected error. Try again later. InvalidArgumentException : Field field_pocdart_iframe is unknown. in Drupal\\Core\\Entity\\ContentEntityBase->getTranslatedField() (line 616 of core/lib/Drupal/Core/Entity/ContentEntityBase.php ). 
Drupal\\Core\\Entity\\ContentEntityBase->get() (Line: 140)
Drupal\\serialization\\Normalizer\\EntityNormalizer->denormalizeFieldData() (Line: 59)
Drupal\\serialization\\Normalizer\\EntityNormalizer->denormalize() (Line: 247)
Symfony\\Component\\Serializer\\Serializer->denormalize() (Line: 179)
Drupal\\rest\\RequestHandler->deserialize() (Line: 67)
Drupal\\rest\\RequestHandler->handle()
call_user_func_array() (Line: 123)
Drupal\\Core\\EventSubscriber\\EarlyRenderingControllerWrapperSubscriber->Drupal\\Core\\EventSubscriber\\{closure}() (Line: 638)
Drupal\\Core\\Render\\Renderer->executeInRenderContext() (Line: 124)
Drupal\\Core\\EventSubscriber\\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext() (Line: 97)
Drupal\\Core\\EventSubscriber\\EarlyRenderingControllerWrapperSubscriber->Drupal\\Core\\EventSubscriber\\{closure}() (Line: 181)
Symfony\\Component\\HttpKernel\\HttpKernel->handleRaw() (Line: 76)
Symfony\\Component\\HttpKernel\\HttpKernel->handle() (Line: 53)
Drupal\\Core\\StackMiddleware\\Session->handle() (Line: 48)
Drupal\\Core\\StackMiddleware\\KernelPreHandle->handle() (Line: 28)
Drupal\\Core\\StackMiddleware\\ContentLength->handle() (Line: 116)
Drupal\\page_cache\\StackMiddleware\\PageCache->pass() (Line: 90)
Drupal\\page_cache\\StackMiddleware\\PageCache->handle() (Line: 48)
Drupal\\Core\\StackMiddleware\\ReverseProxyMiddleware->handle() (Line: 51)
Drupal\\Core\\StackMiddleware\\NegotiationMiddleware->handle() (Line: 36)
Drupal\\Core\\StackMiddleware\\AjaxPageState->handle() (Line: 51)
Drupal\\Core\\StackMiddleware\\StackedHttpKernel->handle() (Line: 741)
Drupal\\Core\\DrupalKernel->handle() (Line: 19)'

500 Service unavailable (with message)
2
  • Drupal REST definitely supports editing custom fields. REST UI module is just using the underlying REST module. Even if you uninstall the REST UI module, all of your REST configuration should continue to work. Commented Jan 18 at 1:07
  • Make sure that the user you are using to make the edit has the correct permissions. Then check the docs and make sure you are formatting the request correctly: drupal.org/docs/8/core/modules/rest/… Commented Jan 18 at 1:09

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.