How to remove whitespaces from the base64 while updating script

#!/bin/bash

scriptfile=Test_script.js

if [ -e “$scriptfile” ]
then
script=$(cat “$scriptfile”)
echo “$script”

base64 encode script

encoded=echo "$script" | base64
echo “$encoded”
scriptPayload=’{“scriptText”:"’$encoded’"}’

echo “$scriptPayload”
curl -v -X PUT
-H ‘X-Api-Key: NRAA-435h4lj344rnmnnrm34nrb34r34’
-H ‘Content-Type: application/json’
https://synthetics.newrelic.com/synthetics/api/v3/monitors/r4rkjkr2-kbjkj32- n2r3nbkjrk2-54khbk/script’
-d $scriptPayload
echo “Script uploaded”
fi

Here i am getting whitespace = at the end of BASE64 ,which causing error while updating script in newrelic using shell/bash script

How to get rid of this = sign from base64
W5mby5pc0FjdGl2ZSwgdHJ1ZSk7DQogICB9DQopOwo="}

A post was merged into an existing topic: Remove Whitelist(=) from the BASE64 encoded format in shell script for updating script