Last active
August 6, 2020 09:11
-
-
Save Twansparant/d786d57c83406b4cfc5e81473523786e to your computer and use it in GitHub Desktop.
REST API v2 /forms/[FORM_ID]/submissions response with page confirmation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
My custom api endpoint: | |
// Post Gravity Form submission | |
public static function postGravityForm($request) { | |
$data = $request->get_params(); | |
if (isset($data['form_id'])) { | |
$gf_url = get_rest_url() . 'gf/v2/forms/'. $data['form_id'] .'/submissions'; | |
// Send request | |
$response = wp_remote_request($gf_url, | |
array( | |
'method' => 'POST', | |
'body' => json_encode($data), | |
'headers' => [ | |
'Content-type' => 'application/json' | |
] | |
) | |
); | |
// Results in WP_Error | |
print_r($response); | |
// Format response | |
$code = wp_remote_retrieve_response_code($response); | |
$body = wp_remote_retrieve_body($response); | |
$message = wp_remote_retrieve_response_message($response); | |
return $body; | |
} else { | |
return new WP_Error('401', __('Your request is invalid.', 'headless-wp')); | |
} | |
} | |
Response from endpoint: | |
WP_Error Object | |
( | |
[errors | |
] => Array | |
( | |
[http_request_failed | |
] => Array | |
( | |
[ | |
0 | |
] => cURL error 7: Failed to connect to mydomain.test port 3000: Connection refused | |
) | |
) | |
[error_data | |
] => Array | |
( | |
) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment