-
Notifications
You must be signed in to change notification settings - Fork 33
Add getJsonBody util to plugin-sdk and document it #263
Copy link
Copy link
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Add getJsonBody util to plugin-sdk and document it
relates to #239
Decoding Raw JSON Body
For JSON POST requests, the body is in raw[].bytes as a number array:
function getJsonBody(request) {
if (!request.requestBody?.raw?.[0]?.bytes) return null;
// Convert number array to string
const bytes = request.requestBody.raw[0].bytes;
const text = String.fromCharCode(...bytes);
try {
return JSON.parse(text);
} catch {
return text;
}
}
function main() {
const requests = useRequests({ method: 'POST' });
const targetRequest = requests.find(r => r.url.includes('/api/endpoint'));
if (targetRequest) {
const body = getJsonBody(targetRequest);
// Use body data...
}
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request