2

I would like post submissions in webform using core's JSON:API. I've created a webform, then added the fields I need. I've installed JSON:API Extras to be able customize some API properties per resource. I'm able to create submissions, override the remote address, post the referenced entity except to the field values.

I've also tried a couple of data formats, but still no luck.

Here's what I've done so far.

Headers

  • api-key: 4bxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  • Content-Type: application/vnd.api+json
  • Accept: application/vnd.api+json

POST URL

http://example.com.com/api/webform_submission/contact

POST data

{
    "data": {
        "type": "webform_submission--contact",
        "attributes": {
            "entity_type": "node",
            "entity_id": "5",
            "remote_addr": "",

            // Format 1
            "email": "[email protected]",
            "name": [{"value": "Loremipsum"}],

            // Format 2
            "data": [{
                "email": "[email protected]",
                "message": ["Please ignore this email."],
                "name": [{"value": "Loremipsum"}],
                "subject": "Testing contact webform"
            }],
            
            // Format 3
            "data": [{
                "email": "[email protected]",
                "message": "Please ignore this email.",
                "name": "Loremipsum",
                "subject": "Testing contact webform"
            }]
        }
    }
}

Results

{
    "jsonapi": {
        "version": "1.0",
        "meta": {
            "links": {
                "self": {
                    "href": "http://jsonapi.org/format/1.0/"
                }
            }
        }
    },
    "data": {
        "type": "webform_submission--contact",
        "id": "035de1b3-01ef-49a9-89ab-3bf8b2b641ea",
        "links": {
            "self": {
                "href": "http://example.com.com/api/webform_submission/contact/035de1b3-01ef-49a9-89ab-3bf8b2b641ea"
            }
        },
        "attributes": {
            "serial": 211,
            "drupal_internal__sid": 62,
            "token": "xjIywCTtW9gqpgnYIAtVIIO_LpUB7pKIKnYfjIf1Z8U",
            "uri": "/api/webform_submission/contact",
            "created": "2020-11-05T01:26:51+00:00",
            "completed": "2020-11-05T01:26:51+00:00",
            "changed": "2020-11-05T01:26:51+00:00",
            "in_draft": false,
            "current_page": null,
            "remote_addr": null,
            "langcode": "en",
            "entity_type": "node",
            "entity_id": "5",
            "locked": false,
            "sticky": false,
            "notes": null
        },
        "relationships": {
            "uid": {
                "data": null,
                "links": {
                    "self": {
                        "href": "http://example.com.com/api/webform_submission/contact/035de1b3-01ef-49a9-89ab-3bf8b2b641ea/relationships/uid"
                    }
                }
            },
            "webform_id": {
                "data": null,
                "links": {
                    "self": {
                        "href": "http://example.com.com/api/webform_submission/contact/035de1b3-01ef-49a9-89ab-3bf8b2b641ea/relationships/webform_id"
                    }
                }
            }
        }
    },
    "links": {
        "self": {
            "href": "http://example.com.com/api/webform_submission/contact"
        }
    }
}

Drupal version: 9.x

Webform version: 6.0.0-alpha20

JSON:API Extras version: 8.x-3.16

Am I missing something?

1 Answer 1

1

According to the issue, Support submitting webforms through JSON API Closed (won't fix)

POSTing a WebformSubmission entity requires an administrative permission (or requires crafting custom access hooks)

enter image description here

The expectation is to use the contrib module Webform REST instead.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.