Created
August 9, 2023 18:06
-
-
Save bcamargogui/7016dfa29661ae4611ac51cef5dc3486 to your computer and use it in GitHub Desktop.
Postman pre-request script convert body to base64 - Commercetools
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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