Skip to main content

Why can't I instantiate Api()?



  • Itay Taragano

    I assume you're using the v1 of our PHP SDK?

    If so, please make sure that in your `conposer.json` file, you have the following set-up

      "require": {
        "cloudinary/cloudinary_php": "^1"

    And then run:

    composer update

    Lastly, you'd need to set your credentials differently, either via an environment variable, or inside the application via 'Config'. For more information:

    Please let us know if this works for you?

  • Anthony Bartoli

    Thanks for your help! I got interesting results.

    First, I want to use v2 of the PHP SDK because v1 is "legacy." And this is where I'm having problems.

    I updated my composer.json to v1 as you instructed and this code works:

    require "vendor/autoload.php";


    $api = new \Cloudinary\Api();

    $folders = $api->root_folders();
    echo "<pre>";
    echo "</pre>";

    But because I want to use v2 of the SDK, I updated my composer back to:

    "require": {
    "cloudinary/cloudinary_php": "^2"

    I run "composer update" to go back to v2 and I get the same error as my original post.

    I suppose I can use v1 for now but I don't understand why this simple code fails on v2 but not v1.

  • Tia Esguerra

    Hi Anthony. 
    I'm not too familiar with PHP, but I will do my best to look into this and see if I can provide some answers. In the meantime,  and since you mention that you would prefer to use v2 of the SDK, I'm wondering if you've had a chance to look over our migration guide here 

  • Anthony Bartoli

    Thanks @Tia. I'll check out the migration guide.

  • Erwin Lukas

    Hi Anthony,

    SDK v1 and v2 has a different syntax and there are some code migration that you need to perform (as mentioned by Tia above) if you have an existing code that's written with PHP v1 SDK. 

    However, if you just start a new project with PHP v2 SDK, I would recommend to check the following documentation:

    And I think you could also benefit to take the following course to get started with PHP v2:

    On this course, it will guide you on how to setup your environment, upload, transformations, and other topics.

    Hope this helps!


Post is closed for comments.