Troubleshooting: Resolving API Call Issues
# 🤝help
l
I have been working on integrating an API into my Botpress application. The API processes images and provides the URL link of the processed images. I have successfully implemented the code for calling the API, and the URL link of the processed image is stored in the variable "workflow.idcard," which is a string variable. What I want to do: I want the bot to output the URL link when I call the "workflow.idcard" variable. What I expect to happen: When I call "workflow.idcard," I expect the bot to return the URL link obtained from "response.data.image_url_png." What is actually happening: Instead of the expected URL link, I am receiving a blank response from the bot when I call "workflow.idcard." To troubleshoot, I attempted to use JSON.stringify on the "workflow.idcard" variable, but it still resulted in an empty string. I would greatly appreciate any help in resolving this issue and successfully retrieving the URL link from "response.data.image_url_png" through "workflow.idcard."
r
Hi! In the event debugger, you should see an execute code card with the actual API request details (input and output). Can you check / screenshot the output ?
l
@rich-battery-69172 Yes, here is the screenshot
r
Oh just realized you are doing a GET. Looks like this should be a post with json body right ?
l
@rich-battery-69172 Thanks for the suggestion, I used POST using Axios in botpress but, I'm getting a 403 error. While the API is working fine on VS Code. Code: try { var data = { "template": "nxOjMA5gX1M3DprE63", "modifications": [ { "name": "text_container_3", "text": "John Doe", "color": null, "background": null }, { "name": "image_container_rectangle_4", "image_url": "https://cdn.bannerbear.com/sample_images/welcome_bear_photo.jpg" } ], "webhook_url": null, "transparent": false, "metadata": null }; // Step 1: Create the image const createResponse = await axios.post('https://api.bannerbear.com/v2/images', data, { headers: { 'Content-Type': 'application/json', 'Authorization':
Bearer ${env.idapi}
} }); if (createResponse.status === 202) { const imageId = createResponse.data.uid; // Step 2: Wait for the image to be processed let getResult; do { // Wait for 1 second before checking the result await new Promise(resolve => setTimeout(resolve, 4000)); getResult = await axios.get(
https://api.bannerbear.com/v2/images/${imageId}
, { headers: { 'Authorization':
Bearer ${env.idapi}
} }); // Continue polling until the status is no longer "processing" } while (getResult.status === 'pending'); // Step 3: Retrieve the final result if (getResult.status === 'completed') { console.log('Image created successfully:', getResult.data.image_url_png) } else { console.error('Image processing failed:', getResult.data); } workflow.idCard=getResult.data.image_url_png ; } } catch (error) { console.error('Error:', error.message); }
14 Views