optimistic-gold
optimistic-gold2y ago

API variable always = 0

hey guys, i get this API Response : { "count": 3, "rooms": [ { "id": 1, "name": "Deluxe Room", "status": "available", "price": 120, "description": "A spacious room with a king-sized bed, en-suite bathroom, and a beautiful city view.", "amenities": [ "WiFi", "Air conditioning", "Flat-screen TV", "Room service", "Mini-bar" ], "occupancy": { "maxAdults": 2, "maxChildren": 1 }, "size": "30m²", "bedType": "King", "images": [ "http://localhost:3000/images/room1.jpg" ], "cancellationPolicy": "Free cancellation within 48 hours of booking. After that, cancel up to 24 hours before check-in for a full refund." }, { "id": 2, "name": "Standard Room", "status": "available", "price": 80, "description": "Comfortable room with a queen-sized bed, private bathroom, and modern amenities.", "amenities": [ "WiFi", "Air conditioning", "Flat-screen TV" ], "occupancy": { "maxAdults": 2 }, "size": "20m²", "bedType": "Queen", "images": [ "http://localhost:3000/images/room2.jpg" ], "cancellationPolicy": "Non-refundable." }, { "id": 3, "name": "Suite", "status": "available", "price": 200, "description": "An elegant suite with separate living area, king-sized bed, and panoramic views.", "amenities": [ "WiFi", "Air conditioning", "Flat-screen TV", "Room service", "Mini-bar", "Jacuzzi" ], "occupancy": { "maxAdults": 2, "maxChildren": 2 }, "size": "50m²", "bedType": "King", "images": [ "http://localhost:3000/images/room3.jpg" ], "cancellationPolicy": "Free cancellation up to 7 days before check-in. After that, cancel up to 48 hours before check-in for a 50% refund." } ], im trying to get the "count" variable in a local "total_rooms" variable (response.count) It always displays '0' when display {total_rooms} into a textbox, i dont know why. Thanks for your time and help !
8 Replies
Tico | Voiceflow Assistant
It sounds like you're having trouble capturing the "count" variable from your API response into a local variable named "total_rooms" in Voiceflow. This issue typically occurs if the path to the variable in the "Capture Response" section of your API block is not correctly specified. To ensure you're capturing the "count" correctly, follow these steps: 1. Make sure you're using the correct path in the "Capture Response" section. For capturing the "count" from your response, the path should be response.count. 2. Double-check that the variable total_rooms is correctly set up in your Voiceflow project to store the value. 3. Test the API request again to confirm if the issue persists. If it does, ensure that your API call is configured correctly and that you're receiving the expected response. Remember, the path always begins with "response" followed by the specific key you want to map from the JSON object. If you're still facing issues, it might be helpful to review the API call configuration and ensure that the API is returning the expected response. For more detailed guidance on working with API blocks and capturing responses, you might find these resources helpful: - API Integration in Voiceflow - Working with Variables and API Responses
optimistic-gold
optimistic-goldOP2y ago
i verified everything, the get request should only contain the url and the capture response, right ?
adverse-sapphire
adverse-sapphire16mo ago
any update here please ? same issue ... spent more than 4 hours on it and still struggeling ! https://www.loom.com/share/e0c266bb37d54addb5f9f35d23f57b8b as you can notice on the video, i GET 0 all the time ... no matter what my external API sent to VoiceFlow ... @Tico | Voiceflow Assistant
W. Williams (SFT)
try dumping the full response to a variable and see what is being returned. You will need to JSON.stringify() the debug var.
adverse-sapphire
adverse-sapphire16mo ago
what is JSON.stringify() for ? why i would need to debug the var. ? can you elaborate ? @Ethan
W. Williams (SFT)
my guess is that there is an issue with the response there is an error you need to see the response when testing your bot. So to do this you need to store the full response in a var like debugOutput. The use a Set step to set debugOutput = JSON.stringify(debugOutput) and then output it in a Text step.
adverse-sapphire
adverse-sapphire16mo ago
done it was "response" in our API thanks for the quick reply @W. Williams (SFT)
W. Williams (SFT)
Sweet

Did you find this page helpful?