APIv3-php-library icon indicating copy to clipboard operation
APIv3-php-library copied to clipboard

getSmtpTemplates need string `true` to work

Open giak opened this issue 6 years ago • 7 comments

need to set as parameter 1 or 0 instead true / false as string in GET.

WORK with templateStatus=true https://api.sendinblue.com/v3/smtp/templates?templateStatus=true&limit=50&offset=0 DONT WORK with templateStatus=1 https://api.sendinblue.com/v3/smtp/templates?templateStatus=1&limit=50&offset=0

giak avatar Feb 15 '19 13:02 giak

Same issue here

Exception when calling SMTPApi->getSmtpTemplates: [400] Client error: GET https://api.sendinblue.com/v3/smtp/templates?templateStatus=1&limit=50&offset=0resulted in a400 Bad Request response: {"code":"invalid_parameter","message":"Template status should be either true or false"}

It's look like: ObjectSerializer::toQueryValue($templateStatus); is causing the problem because is casting the boolean to string.

Spensolin avatar Apr 13 '20 14:04 Spensolin

Hi @giak

The API expects template status to be a boolean value. Please set the templateStatus to true instead of 1.

rajatsib avatar Jul 16 '20 08:07 rajatsib

The issue here is located in the PHP API, not @giak code: ->getSmtpTemplates( true, 500 ) results in:

[400] Client error: `GET https://api.sendinblue.com/v3/smtp/templates?templateStatus=1&limit=500&offset=0&sort=desc` resulted in a `400 Bad Request` response:\n
           {"code":"invalid_parameter","message":"Template status should be either true or false"}\n
           """,

@Spensolin is right, the ObjectSerializer::toQueryValue($templateStatus) call is probably in cause here.

psaikali avatar Mar 08 '21 09:03 psaikali

FYI https://github.com/swagger-api/swagger-codegen/issues/10939 https://github.com/guzzle/psr7/issues/264

pierrre avatar Mar 08 '21 14:03 pierrre

Hi, as a workaround you could pass "true" with quotes and even is not a logic solution (because its a string, not a bool) code is working.

Example:

<?php
require_once(__DIR__ . '/vendor/autoload.php');

// ...
// ...

$templateStatus = "true";   //<---  "true" (string) and not true (bool)
$limit = 50;
$offset = 0;
$sort = "desc";

try {
    $result = $apiInstance->getSmtpTemplates($templateStatus, $limit, $offset, $sort);
    print_r($result);
} catch (Exception $e) {
    echo 'Exception when calling TransactionalEmailsApi->getSmtpTemplates: ', $e->getMessage(), PHP_EOL;
}
?>

flavioski avatar Mar 25 '21 16:03 flavioski

The DocBlock is incorrect, it says that it expects a boolean, however that will not work, so this should be a string. This is the right change to fix this:

-     * @param  bool $templateStatus Filter on the status of the template. Active &#x3D; true, inactive &#x3D; false (optional)
+     * @param  string $templateStatus Filter on the status of the template. Active &#x3D; true, inactive &#x3D; false (optional)

Or as an alternative, booleans should be converted to true and false instead of 1 and 0 when used in query strings. In that case, a change in the method ObjectSerializer::toString() could solve this.

jeroennoten avatar Jun 17 '21 13:06 jeroennoten

This is still an issue today.

corsacca avatar Mar 31 '23 11:03 corsacca