I'm working on a project involving Declartive copilot Agent and I've trouble sending data back to HTTP post request as a part of body
Harsh Chamola
5
Reputation points
I need help with my agent to read the information when entered by the user and send it back as a body through my HTTP post request. Currently, it's not able to read anything and just show me default data when the request is created. Any help would be appreciated? This is the request I'm making it's working but not reading any data currently from COpilot
app.http('createServiceRequest', {
methods: ['POST'],
authLevel: 'anonymous',
handler: async (req, context) => {
context.log("HTTP trigger function createServiceRequest processed a request.");
try {
const requestData = {
request: {
subject: req.body.subject || "Unable to login",
description: req.body.description || "User cannot access account",
requester: {
id: req.body.requesterId || "4", // Ensure valid requester ID
name: req.body.requesterName || "administrator"
},
impact_details: req.body.impactDetails || "Default Impact Details",
resolution: { content: req.body.resolutionContent || "Default Resolution Content" },
status: { name: req.body.statusName || "Open" }
}
};
const encodedData = qs.stringify({ input_data: JSON.stringify(requestData) });
context.log("Encoded data for POST request:", encodedData);
const response = await axios.post(
'https://localhost:8080/api/v3/requests',
encodedData,
{
headers: {
'authtoken': authToken,
'Content-Type': 'application/x-www-form-urlencoded'
},
httpsAgent: new https.Agent({ rejectUnauthorized: false })
}
);
context.log("Response data:", response.data);
return { status: 201, body: JSON.stringify(response.data) };
} catch (error) {
context.log(`⛔ Error status code ${error.response?.status || 500}: ${error.message}`);
if (error.response) {
context.log("Error response data:", JSON.stringify(error.response.data, null, 2));
}
return { status: error.response?.status || 500, body: error.response?.data };
}
},
});
Sign in to answer