Binance API Auto Invest plan creation not authorized

Hello guys,

Do I need to request a special access for endpoint /lending/auto-invest/plan/add ?
I’m facing issue when I try to call the auto invest plan creation.

Here is the log request:

POST https://api.binance.com/sapi/v1/lending/auto-invest/plan/add?sourceType=MAIN_SITE&planType=SINGLE&subscriptionAmount=3.00&subscriptionCycle=WEEKLY&subscriptionStartTime=5&sourceAsset=EUR&flexibleAllowedToUse=false&details[0].targetAsset=BTC&details[0].percentage=100&timestamp=1725463475719&signature=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

and the response:
Exception in thread "main" com.business.connector.client.exceptions.BinanceClientException: {"code":-1002,"msg":"You are not authorized to execute this request."}

Same issue for /lending/auto-invest/one-off endpoint.

But, I’m able to successfully perform a call for others endpoint with no issue, Ex: /lending/auto-invest/plan/list and /lending/auto-invest/plan/edit-status.

Thanks for your help
Regards,
A. Cabral.

Hey,
Do you have a Binance Turkey account? Do you currently have 100 auto-invest plans? Have you tried doing this through the UI?

Otherwise, this issue is usually caused by one of the following:

  • A signature was not attached to the request.
  • No API key settings were saved.
  • A signature was attached, but it is incorrect. It is advised to double-check how the signature is generated.
  • The API key was not sent in the X-MBX-APIKEY header.
  • An API key different from the intended one was used.

Hello
Thank you for the advice.

It is not a Turkey account and I have a few plan create through the GUI.

I suspected that the issue is on this url encoded part &details[0].percentage=100&timestamp=1725463475719

Because, I’m able to successfully perform a call to the /lending/auto-invest/plan/edit-status endpoint using the same signature.

Regards,
Adilson

Can you check if URL you’re referring to, &details[0].percentage=100&timestamp=1725463475719, is correctly URL-encode parameters in PHP, ensuring the brackets and other special characters are handled properly…

<?php // Base parameters $params = [ 'sourceType' => 'MAIN_SITE', 'planType' => 'SINGLE', 'subscriptionAmount' => '3.00', 'subscriptionCycle' => 'WEEKLY', 'subscriptionStartTime' => '5', 'sourceAsset' => 'EUR', 'flexibleAllowedToUse' => 'false', 'timestamp' => 1725463475719 ]; // Complex nested parameters $details = [ ['targetAsset' => 'BTC', 'percentage' => 100] ]; // Encode the nested details array foreach ($details as $index => $detail) { foreach ($detail as $key => $value) { $params["details[$index].$key"] = $value; } } // Generate the query string $queryString = http_build_query($params); // Append to the base URL $url = "https://api.binance.com/sapi/v1/lending/auto-invest/plan/add?" . $queryString; echo "Encoded URL: " . $url; ?>

The above script:

  • Constructs the query parameters as an array, handling both simple and complex (nested) data.
  • Uses PHP’s http_build_query to correctly encode all parameters, including arrays, ensuring that characters like brackets are correctly encoded.
  • Appends the encoded query string to the base URL.

The use of http_build_query automatically handles URL encoding based on RFC 3986 standards, which should resolve issues related to incorrect manual encoding.