admin管理员组文章数量:1129246
I’m currently working with an API and Elementor, and I’m trying to send form information to the platform API. However, I’m encountering a 400 Bad Request error when making a request to my server. The error message indicates that some parameters are missing from my request. Here’s the error from debug_log:
{
"code": "400",
"error": "Bad Request",
"msg": "Some parameters are required",
"schema": [
{
"customer_name": "my name",
"customer_last_name": "my last name",
"id_type": "CC",
"customer_id": "113xxxx00",
.....
}
]
}
This is the error from admin-ajax.php :
array(4) { ["code"]=> string(3) "400" ["error"]=> string(11) "Bad Request" ["msg"]=> string(28) "Some parameters are required" ["schema"]=> array(1) { [0]=> array(37) { ["customer_name"]=> string(7) "my name" ["customer_last_name"]=> string(12) "my last name" ["id_type"]=> string(2) "CC" ["customer_id"]=> string(9) "113xxxx00" ["age"]=> string(2) "30" ["gender"]=> string(1) "M" ["country"]=> string(3) "COL" ["state"]=> string(0) "" ["city"]=> string(0) "" ["zone"]=> string(0) "" ["address"]=> string(0) "" ["opt1"]=> string(0) "" ["opt2"]=> string(0) "" ["opt3"]=> string(0) "" ["opt4"]=> string(0) "" ["opt5"]=> string(0) "" ["opt6"]=> string(0) "" ["opt7"]=> string(0) "" ["opt8"]=> string(0) "" ["opt9"]=> string(0) "" ["opt10"]=> string(0) "" ["opt11"]=> string(0) "" ["opt12"]=> string(0) "" ["tel1"]=> string(11) "9301500xxxx" ["tel2"]=> string(0) "" ["tel3"]=> string(0) "" ["tel4"]=> string(0) "" ["tel5"]=> string(0) "" ["tel6"]=> string(0) "" ["tel7"]=> string(0) "" ["tel8"]=> string(0) "" ["tel9"]=> string(0) "" ["tel10"]=> string(0) "" ["tel_extra"]=> string(0) "" ["email"]=> string(0) "" ["recall_date"]=> string(14) "YYYYmmddHHiiss" ["recall_telephone"]=> string(11) "9301500xxxx" } } }
I have already added the parameters as indicated by the schema, but it doesn’t seem to work. I’m still getting the same error.This is my code:
function send_to_external_api( $record, $handler ) {
$form_name = $record->get_form_settings( 'form_name' );
if ( 'Testing' !== $form_name ) {
return;
}
$raw_fields = $record->get( 'fields' );
$fields = [];
foreach ( $raw_fields as $id => $field ) {
$fields[ $id ] = $field['value'];
}
$body = array(
'customer_name' => $fields['customer_name'],
'customer_last_name' => $fields['customer_last_name'],
'id_type' => $fields['id_type'],
'customer_id' => $fields['customer_id'],
'age' => $fields['age'],
'gender' => $fields['gender'],
'country' => $fields['country'],
'state' => '',
'city' => '',
'zone' => '',
'address' => '',
'opt1' => '',
'opt2' => '',
'opt3' => '',
'opt4' => '',
'opt5' => '',
'opt6' => '',
'opt7' => '',
'opt8' => '',
'opt9' => '',
'opt10' => '',
'opt11' => '',
'opt12' => '',
'tel1' => '',
'tel2' => '',
'tel3' => '',
'tel4' => '',
'tel5' => '',
'tel6' => '',
'tel7' =>'',
'tel8' => '',
'tel9' => '',
'tel10' => '',
'tel_extra' => '',
'email' => '',
'recall_date' => $fields['recall_date'],
'recall_telephone' => $fields['recall_telephone']
);
$response = wp_remote_post('', [
'headers' => [
'wolkvox-token' => '',
'Content-Type' => 'application/json'
],
'body' => json_encode($body),
'redirection' => 10,
'httpversion' => '1.1',
]);
error_log(print_r($body, true));
if ( is_wp_error( $response ) ) {
$error_message = $response->get_error_message();
} else {
$body = wp_remote_retrieve_body( $response );
$decoded_response = json_decode( $body, true );
var_dump( $decoded_response );
}
}
add_action( 'elementor_pro/forms/new_record', 'send_to_external_api', 10, 2 );
According to Wolkvox, there shouldn't be any issue with leaving those parameters empty.
Any help would be greatly appreciated. Thanks in advance!
I’m currently working with an API and Elementor, and I’m trying to send form information to the platform API. However, I’m encountering a 400 Bad Request error when making a request to my server. The error message indicates that some parameters are missing from my request. Here’s the error from debug_log:
{
"code": "400",
"error": "Bad Request",
"msg": "Some parameters are required",
"schema": [
{
"customer_name": "my name",
"customer_last_name": "my last name",
"id_type": "CC",
"customer_id": "113xxxx00",
.....
}
]
}
This is the error from admin-ajax.php :
array(4) { ["code"]=> string(3) "400" ["error"]=> string(11) "Bad Request" ["msg"]=> string(28) "Some parameters are required" ["schema"]=> array(1) { [0]=> array(37) { ["customer_name"]=> string(7) "my name" ["customer_last_name"]=> string(12) "my last name" ["id_type"]=> string(2) "CC" ["customer_id"]=> string(9) "113xxxx00" ["age"]=> string(2) "30" ["gender"]=> string(1) "M" ["country"]=> string(3) "COL" ["state"]=> string(0) "" ["city"]=> string(0) "" ["zone"]=> string(0) "" ["address"]=> string(0) "" ["opt1"]=> string(0) "" ["opt2"]=> string(0) "" ["opt3"]=> string(0) "" ["opt4"]=> string(0) "" ["opt5"]=> string(0) "" ["opt6"]=> string(0) "" ["opt7"]=> string(0) "" ["opt8"]=> string(0) "" ["opt9"]=> string(0) "" ["opt10"]=> string(0) "" ["opt11"]=> string(0) "" ["opt12"]=> string(0) "" ["tel1"]=> string(11) "9301500xxxx" ["tel2"]=> string(0) "" ["tel3"]=> string(0) "" ["tel4"]=> string(0) "" ["tel5"]=> string(0) "" ["tel6"]=> string(0) "" ["tel7"]=> string(0) "" ["tel8"]=> string(0) "" ["tel9"]=> string(0) "" ["tel10"]=> string(0) "" ["tel_extra"]=> string(0) "" ["email"]=> string(0) "" ["recall_date"]=> string(14) "YYYYmmddHHiiss" ["recall_telephone"]=> string(11) "9301500xxxx" } } }
I have already added the parameters as indicated by the schema, but it doesn’t seem to work. I’m still getting the same error.This is my code:
function send_to_external_api( $record, $handler ) {
$form_name = $record->get_form_settings( 'form_name' );
if ( 'Testing' !== $form_name ) {
return;
}
$raw_fields = $record->get( 'fields' );
$fields = [];
foreach ( $raw_fields as $id => $field ) {
$fields[ $id ] = $field['value'];
}
$body = array(
'customer_name' => $fields['customer_name'],
'customer_last_name' => $fields['customer_last_name'],
'id_type' => $fields['id_type'],
'customer_id' => $fields['customer_id'],
'age' => $fields['age'],
'gender' => $fields['gender'],
'country' => $fields['country'],
'state' => '',
'city' => '',
'zone' => '',
'address' => '',
'opt1' => '',
'opt2' => '',
'opt3' => '',
'opt4' => '',
'opt5' => '',
'opt6' => '',
'opt7' => '',
'opt8' => '',
'opt9' => '',
'opt10' => '',
'opt11' => '',
'opt12' => '',
'tel1' => '',
'tel2' => '',
'tel3' => '',
'tel4' => '',
'tel5' => '',
'tel6' => '',
'tel7' =>'',
'tel8' => '',
'tel9' => '',
'tel10' => '',
'tel_extra' => '',
'email' => '',
'recall_date' => $fields['recall_date'],
'recall_telephone' => $fields['recall_telephone']
);
$response = wp_remote_post('', [
'headers' => [
'wolkvox-token' => '',
'Content-Type' => 'application/json'
],
'body' => json_encode($body),
'redirection' => 10,
'httpversion' => '1.1',
]);
error_log(print_r($body, true));
if ( is_wp_error( $response ) ) {
$error_message = $response->get_error_message();
} else {
$body = wp_remote_retrieve_body( $response );
$decoded_response = json_decode( $body, true );
var_dump( $decoded_response );
}
}
add_action( 'elementor_pro/forms/new_record', 'send_to_external_api', 10, 2 );
According to Wolkvox, there shouldn't be any issue with leaving those parameters empty.
Any help would be greatly appreciated. Thanks in advance!
Share Improve this question edited Nov 22, 2023 at 22:30 Diane Rendel asked Nov 22, 2023 at 16:30 Diane RendelDiane Rendel 32 bronze badges1 Answer
Reset to default 0Diane, I've been trying to provide help but I'm not getting answers to my comments from any of your questions. You'll likely get a better response if you add to one question rather than continuing to add new questions to the stack. Error 400 is bad parameters not bad field data. (although last name could be a required field)
On one of your last questions you posted your URL as this:
https://wv{{wolkvox_server}}.wolkvox.com/api/v2/campaign.php?api=add_record&type_campaign=predictive&campaign_id={{campaign_id}}&campaign_status={{campaign_status}}
Someone answered that you need to replace the variables with the correct information. You didn't respond to that question. Did you change this and set it up correctly? If you didn't that could be your first error. If you want help we need to get answers to the questions being asked back to you. It clearly states in the wolkvox documentation: "In the json the parameters are added according to the operation or process to be performed." Which means if you didn't fix this URL, parameters can't be defined.
More though, it may be that you need to encode the body (the entire body is a parameter):
'body' => json_encode(array()),
or you need other parameters besides timeout (which should be set to 0 according to the wolkvox docs) and blocking:
'redirection' => 10,
'httpversion' => '1.1',
I'm guessing and providing options. Without seeing the results of what you're sending or testing directly (did you look at postman yet?) this is the best I can think of to assist.
本文标签: phpEncountering 400 Bad Request Error When Sending Form Information to API through Elementor
版权声明:本文标题:php - Encountering 400 Bad Request Error When Sending Form Information to API through Elementor 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736740703a1950493.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论