conscious-sapphire•2y ago
Voiceflow not seeing HTTP POST request handler's response data
I have a simple php http POST request handler (HANDLER below). When I make a request to it with my own php file , it succeeds and gets the returned status, message and data items that the HANDLER sends. (REQUESTOR OUTPUT below). However, when I call the handler using VoiceFlow's API step, it succeeds, but the response does not contain the status, message and data items, which are in the response I send. (see VOICEFLOW RESPONSE DISPLAY). Why not?
--------------------HANDLER
<?php
// Check if the request method is POST
if ($_SERVER["REQUEST_METHOD"] === "POST") {
// Process the request $postData = $_POST; // Get the POST data // Perform any necessary processing or validation // Generate response $response = array( "status" => "success!", "message" => "Request processed successfully", "data" => $postData // Return any data as needed ); // Send JSON response header('Content-Type: application/json'); echo json_encode($response); } else { // Handle other request methods (optional) http_response_code(405); // Method Not Allowed echo "This endpoint only accepts POST requests."; } ?> --------------------- REQUESTOR OUTPUT Response: {"status":"success","message":"Request processed successfully","data":{"username":"john","password":"password123"}} --------------------- VOICEFLOW RESPONSE DISPLAY (no status, message nor data included. why?) { "VF_STATUS_CODE": 200, "VF_HEADERS": { "connection": "close", "content-encoding": "gzip", "content-type": "text/html; charset=UTF-8", "date": "Fri, 01 Mar 2024 19:28:44 GMT", "strict-transport-security": "max-age=15724800; includeSubDomains", "transfer-encoding": "chunked", "vary": "Accept-Encoding", "x-powered-by": "PHP/8.1.23" } } included image of API step settings
// Process the request $postData = $_POST; // Get the POST data // Perform any necessary processing or validation // Generate response $response = array( "status" => "success!", "message" => "Request processed successfully", "data" => $postData // Return any data as needed ); // Send JSON response header('Content-Type: application/json'); echo json_encode($response); } else { // Handle other request methods (optional) http_response_code(405); // Method Not Allowed echo "This endpoint only accepts POST requests."; } ?> --------------------- REQUESTOR OUTPUT Response: {"status":"success","message":"Request processed successfully","data":{"username":"john","password":"password123"}} --------------------- VOICEFLOW RESPONSE DISPLAY (no status, message nor data included. why?) { "VF_STATUS_CODE": 200, "VF_HEADERS": { "connection": "close", "content-encoding": "gzip", "content-type": "text/html; charset=UTF-8", "date": "Fri, 01 Mar 2024 19:28:44 GMT", "strict-transport-security": "max-age=15724800; includeSubDomains", "transfer-encoding": "chunked", "vary": "Accept-Encoding", "x-powered-by": "PHP/8.1.23" } } included image of API step settings

1 Reply
conscious-sapphireOP•2y ago
I figured it out.
I was using my the php file that I was using to test/make the request as the endpoint in for the API step. It was not the endpoint. It called the endpoint, and echoed the result, which is why it looked so much like I was actually calling endpoint - same basic result came back.
DUH!