A bash script that causes 403 ERROR for more than FIVE days

Hi, team!

Could you please review a bash script that causes 403 ERROR for more than FIVE days((((

#!/usr/bin/env bash


# Set up authentication:
API_KEY="MyAPIkeyFormBinanceWebInterface"
PRIVATE_KEY_PATH="Private/Key/Path"

# Set up your request:
API_METHOD="GET"
API_CALL="api/v3/account"
API_PARAMS=""

# Calculate the signature:
timestamp=$(date +%s000)
api_params_with_timestamp="$API_PARAMS&timestamp=$timestamp"

echo -n "$api_params_with_timestamp" > message.bin

signature=$(openssl pkeyutl -sign -inkey $PRIVATE_KEY_PATH -rawin -in message.bin | openssl enc -base64 -A)

rm -f message.bin

# send request:
curl -H "X-MBX-APIKEY: $API_KEY" -X "$API_METHOD" \
    "https://api.binance.com/$API_CALL?$api_params_with_timestamp" \
    --data-urlencode "signature=$signature"

When I send the request without the signature I get response:

{“code”:-1102,“msg”:“Mandatory parameter ‘signature’ was not sent, was empty/null, or malformed.”}

Team help me, please!

Thanks!

Hey,
What happens if you omit $API_PARAMS& from the api_params_with_timestamp parameter, and replace--data-urlencode "signature=$signature" by adding &signature=$signature at the end of the URL?

Otherwise, you can check this out: 403 ERROR: The request could not be satisfied - #6 by Sanjeev_B"

1 Like

After I change:


api_params_with_timestamp=“$API_PARAMS&timestamp=$timestamp”

to

api_params_with_timestamp=“timestamp=$timestamp”


and


# send request:
curl -H “X-MBX-APIKEY: $API_KEY” -X “$API_METHOD”
https://api.binance.com/$API_CALL?$api_params_with_timestamp
–data-urlencode “signature=$signature”

to

# send request:
curl -H “X-MBX-APIKEY: $API_KEY” -X “$API_METHOD”
https://api.binance.com/$API_CALL?$api_params_with_timestamp&signature=$signature


I’ve got the first ever valid response:


{“makerCommission”:10,“takerCommission”:10,“buyerCommission”:0,“sellerCommission”:0,“commissionRates”:{“maker”:“0.00100000”,“taker”:“0.00100000”,“buyer”:“0.00000000”,“seller”:“0.00000000”},“canTrade”:true,“canWithdraw”:true,“canDeposit”:true,“brokered”:false,“requireSelfTradePrevention”:false,“preventSor”:false,“updateTime”:1711954224957,“accountType”:“SPOT”,“balances”:[{“asset”:“BTC”,“free”:“0.00000818”,“locked”:“0.00000000”},



Thank you very much!