I just created the webform and added fields.
I need to create a Webform Submission Using Rest API POST method. I just installed Rest & Rest UI modules for this.
But when I try to test my API using API tester its showing the error like this :
{"message":"Could not determine entity type bundle: \u0022webform_id\u0022 field is missing."}
But I have already determined the webform_id and here is my configuration :
POST URL : http://example.com/entity/webform_submission?_format=json
Headers :
Content-Type : application/json
POST Data :
{
"type": {
"webform_id": "my_form"
},
"your_mobile":[{"value":"123456789"}],
"your_name":[{"value":"Test"}],
"your_email":[{"value":"test@gmail.com"}]
}
Drupal Version : 8.6.4
Rest UI version : 8.x-1.16
Webform Module version : 8.x-5.1
Why its not working?
Comments
Comment #2
wim leersI agree this is a pain to figure out 😞
I recommend you to use https://www.drupal.org/project/jsonapi instead, its JSON structure is much clearer!
Try this instead:
Comment #3
Selva.M commentedI just installed and configured the JSON API module https://www.drupal.org/project/jsonapi but its showing the error below :
{"errors":[{"title":"Internal Server Error","status":500,"detail":"The controller result claims to be providing relevant cache metadata, but leaked metadata was detected. Please ensure you are not rendering content too early. Returned object class: Drupal\\jsonapi\\ResourceResponse.","links":{"via":{"href":"http:\/\/example.com\/jsonapi\/webform_submission\/my_form"},"info":{"href":"http:\/\/www.w3.org\/Protocols\/rfc2616\/rfc2616-sec10.html#sec10.5.1"}},"source":{"file":"\/srv\/bindings\/eeb03678ba3e4b03a62651b67ec4650b\/code\/modules\/contrib\/jsonapi\/src\/EventSubscriber\/DefaultExceptionSubscriber.php","line":43}.............Here is my Configuration :
POST URL : http://example.com/jsonapi/webform_submission/my_form
Headers :
Accept : application/vnd.api+json
Content-Type : application/vnd.api+json
Authorization : Basic c2VsdmEukZXN0aTEyMw==
POST Data :
I hope I have added this in a proper way. But why its not showing this error?
Comment #4
wim leersNow you're mixing up two things. Can you please try what I suggested in #2 using the REST module first?
Comment #5
Selva.M commentedHi, for your kind information I didn't mixing up, Here I just only used only JSON API and modified the POST Data according to that but got the error like above.
Also I have found that Webform_Rest Module for Webform submission through REST API.
What would you recommend?
Thanks.
Comment #6
wim leersPlease don't use that. Use the REST API. Please send exactly what I suggested in #2. And then let me know the result.
Comment #7
jrockowitz commented@Wim Leers I pinpointed the cause for the issue described in #3. Basically, webform submission label's support tokens and WebformSubmission::label is called very early in the call stack before any rendering. I only tested this issue via JSONAPI but I think the REST API would throw the same error.
@Selva.M Please review and test the patch provided in https://www.drupal.org/project/webform/issues/3010727#comment-12928067
Comment #8
wim leers#3010727: Error processing Webform Tokens, sending leaked metadata was fixed! :)
Comment #9
sowndharya commented@Wim Leers I tried to send post method to create submission
Content is
{
"webform_id":{
target_id":"contact"
},
"name":[{"value":"Test"}],
"email":[{"value":"test@gmail.com"}],
"subject":[{"value":"123456789"}],
"message":[{"value":"hai hello"}]
}
and URL is http://local.com/jsonapi/webform_submission/contact
I used JSON API and REST module but I am getting 403 error(X-CSRF-Token request header is invalid). Is any changes in config side?.Please help me with this.
Comment #10
tsega commented@sowndharya I believe you need to send the
X-CSRF-Tokenin the header of your request. Here is an example of how to send it:Notice: Simplifying the 'webform_id' property structure as above works for me or else I get an error saying it can't find the webform_id.
Comment #11
sowndharya commented@tsega Thank you that error got resolved.
But I am getting 400 bad request
URL:http://example.com/jsonapi/webform_submission/contact
body: which you mentioned in comment #10
header: token,basic_auth,content-type,accept-type
Comment #12
sowndharya commentedComment #13
tsega commented@sowndharya what is the error message that you get in the response?
FYI, I haven succeeded in posting using webforms and REST module, looking for the solution myself. Will share here once it does work for me.
Comment #14
sowndharya commented@tsega Error is 400 Bad Request.
Please share the steps once it is done
Thanks