Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mcventur created an issue. See original summary.

mcventur’s picture

Issue summary: View changes
mcventur’s picture

Issue summary: View changes

Problem/Motivation

When i send a PATCH request to my site to
/webform_rest/{webform_id}/submission/{sid}?_format=json
with the body

{
    "data":{
        "sincronizado":1
    }
}
or 

{
    "sincronizado":1
}

from postman, i've received a 500 error.

The site log displays the next error:

RuntimeException: Callable "Drupal\webform_rest\Plugin\rest\resource\WebformSubmissionResource::patch" requires a value for the "$webform_data" argument. en Drupal\Component\Utility\ArgumentsResolver->handleUnresolvedArgument() (linea 142 de /usr/home/example.com/web/core/lib/Drupal/Component/Utility/ArgumentsResolver.php).

¿Am i making a bad request? What is the $webform_data argument? My webform has a field "sincronizado", of type value.

How to reproduce

Make any trying of pàtching submission with the /webform_rest/{webform_id}/submission/{sid} resource

mcventur’s picture

Issue summary: View changes
Issue tags: -patch submission RuntimeException $webform_data +patch, +submission, +RuntimeException, +$webform_data
mcventur’s picture

Issue summary: View changes

The goal is read all submissions with "sincronizado" = 0 (GET from a view, i got it). And then, update these submissions with sincronizado = 1.

mcventur’s picture

Issue summary: View changes

If i set a default value [] for $webform_data parameter in patch function on WebformSubmissionResource.php i get the response 200 with mesage

{
    "error": {
        "message": "No data has been submitted."
    }
}
mcventur’s picture

Same problem sending sid parameter with Webform rest version 8.x-2.0-beta3.

My request exported from postman, in curl code is

curl --location --request PATCH 'http://example.com/webform_rest/webform-id-example/submission/36?_format=json' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic (admin user and password in base 64)' \
--data-raw '{  
"sincronizado":"1"
}'
mcventur’s picture

I have more info. I'm debuggin the problem and i've seen that it's generated in core/modules/rest/src/RequestHandler.php, in the delegateToRestResourcePlugin() function. Specifically in the call
$arguments = $argument_resolver->getArguments([$resource, $method]);

Then, it seems a core rest module bug, isn't it?

mcventur’s picture

Component: Miscellaneous » Code
Category: Support request » Bug report
joaomarques736’s picture

Hello mcventur,

I can't figure out why this worked on D8 but it is not working in D9.

Anyway, i fixed this with this patch.

Best regards.

joaomarques736’s picture

Status: Active » Fixed
joaomarques736’s picture

Patch with a small change in a comment

mcventur’s picture

It works great! Thank you!

Adittional question: I have verified that it is not necessary to send the X-CSRF-Token to make a PATCH. ¿It's working as designed?

joaomarques736’s picture

No problem!

I tested a PATCH in postman with drupal 9 and it appears "X-CSRF-Token request header is missing" as it is supposed. Can you show any evidence, the configurations you are using?

Best regards!

mcventur’s picture

This is the curl code of the patch request:

curl --location --request PATCH 'http://mylocalsite/webform_rest/movimientos_de_uva/submission/21c28b2e-cacd-484b-98cd-3f6265d65869?_format=json' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic [my basic auth data]=' \
--data-raw '{
    "sincronizado":1
}'

And this is the response with 200 code:

{
"sid": "21c28b2e-cacd-484b-98cd-3f6265d65869"
}

Drupal 9.0.6 and Webform Rest 4.x-dev

joaomarques736’s picture

Hello mcventur,

Ok, i confirmed that it is not necessary to send the X-CSRF-Token to make a PATCH when you are using "basic auth" (comparing with another REST Resources), so it is working as designed.

Thank you and best regards!

joaomarques736’s picture

Status: Fixed » Closed (fixed)
ram4nd’s picture

Issue tags: -patch, -submission, -RuntimeException, -$webform_data