Skip to content

Instantly share code, notes, and snippets.

@bcamargogui
Created August 9, 2023 18:06
Show Gist options
  • Save bcamargogui/7016dfa29661ae4611ac51cef5dc3486 to your computer and use it in GitHub Desktop.
Save bcamargogui/7016dfa29661ae4611ac51cef5dc3486 to your computer and use it in GitHub Desktop.
Postman pre-request script convert body to base64 - Commercetools
// Convert part of the body to base64 (same format as messages)
var data = JSON.parse(pm.request.body.raw);
const newBody = {
...data,
message: {
data: Buffer.from(JSON.stringify(data.message.data)).toString('base64'),
}
};
let body = {
mode: 'raw',
raw: JSON.stringify(newBody),
options: {
raw: {
language: 'json'
}
}
}
pm.request.body.update(body);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment