Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating VCL Snippets via the PHP Library throws error: Invalid value '0' for 'dynamic', must be one of '0', '1' #50

Open
deriknelvaimo opened this issue Jun 6, 2024 · 1 comment
Labels

Comments

@deriknelvaimo
Copy link

Version

5.3.0

What happened

Trying to add VCL Snippets to a service throws: Exception when calling SnippetApi->createSnippet: Invalid value '0' for 'dynamic', must be one of '0', '1' even though dynamic is a string of '0'.

I am using this guide: https://www.fastly.com/documentation/reference/api/vcl-services/snippet/

Sample Code (sensitive bits removed):

<?php

require_once(__DIR__ . '/vendor/autoload.php');
ini_set('display_errors', 0);

$config = Fastly\Configuration::getDefaultConfiguration()->setApiToken('REDACTED');
$apiInstance = new Fastly\Api\SnippetApi(null, $config);

$options = [
    'service_id' => 'REDACTED',
    'version_id' => 1,
    'name' => 'add_detected_bot_headers_recv',
    'type' => 'recv',
    'dynamic' => '0',
    'content' => 'if (client.class.bot) { set req.http.X-Known-Bot = "1"; set req.http.X-Known-Bot-Name = client.bot.name; } else { set req.http.X-Known-Bot = "0"; }'
];

try {
    $result = $apiInstance->createSnippet($options);
    print_r($result);
} catch (Exception $e) {
    echo 'Exception when calling SnippetApi->createSnippet: ', $e->getMessage(), PHP_EOL;
    print_r($options);
}

Returns:

Exception when calling SnippetApi->createSnippet: Invalid value '0' for 'dynamic', must be one of '0', '1'

With Options Array:

Array
(
    [service_id] => REDACTED
    [version_id] => 1
    [name] => add_detected_bot_headers_recv
    [type] => recv
    [dynamic] => 0
    [content] => if (client.class.bot) { set req.http.X-Known-Bot = "1"; set req.http.X-Known-Bot-Name = client.bot.name; } else { set req.http.X-Known-Bot = "0"; }
)
@deriknelvaimo deriknelvaimo changed the title Creating VCL Snippets via the PHP LIbrary throws error: Invalid value '0' for 'dynamic', must be one of '0', '1' Creating VCL Snippets via the PHP Library throws error: Invalid value '0' for 'dynamic', must be one of '0', '1' Jun 6, 2024
@deriknelvaimo
Copy link
Author

Checked in the Portal and it adds the snippet but throws an exception error so the code breaks but the snippet is actually added:

SCR-20240606-gqij

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant