• Resolved ciberg

    (@ciberg)


    Hi,

    I am having a problem trying to use the API to create a Product Category with an image.
    I am using the Ruby gem but I have the same problem using a standard call via Postman.

    This is what I am sending in the request, if I send it without image it works fine but with an image I get “woocommerce_api_product_category_image_upload_error – Error getting remote image”

    
    {
        "product_category":
        {
    
                    "name": "Categoria uma2", 
                    "slug": "Categoriauma2", 
                    "description": "nil", 
                    "image": 
                        {
                            "src": "https://same_server_as_wordpress.com/wp-content/uploads/2020/09/2a.jpg"
                        }
        }
    }
    

    It is a test server and no other plugins are installed, the image is accessible in the WP server.
    I debugged WP and it is not a connection problem, as the URL is never really used, this is the error:
    ltrim() expects parameter 1 to be string, array given in /var/www/html/wp-includes/formatting.php on line 4313

    This corresponds to the function esc_url that receives the URL and escapes it, the function expects the URL to be a string but it is receiving an array instead.
    I examined the array and it is part of the request:
    a:1:{s:3:”src”;s:71:”https://wordpress.stable.wrightia.com/wp-content/uploads/2020/09/2a.jpg”;}

    Backtracing the call of the esc_url function, I see it is called by WP_Scripts, but when I get to this point there is nothing I can do on my side to solve this, as I do not want to edit WP or WC files.

    What am I missing here? The request is correct and according to the documentation and I have both WP and WC updated (please remind that without image the creation works).

    I am driving nuts as I am looking for a solution for days, can someone please shed a light on this.

    
    ### WordPress Environment ###
    
    WordPress address (URL): https://my_server.com
    Site address (URL): https://my_server.com
    WC Version: 4.5.2
    REST API Version: ? 4.5.2
    WC Blocks Version: ? 3.1.0
    Action Scheduler Version: ? 3.1.6
    WC Admin Version: ? 1.5.0
    Log Directory Writable: ?
    WP Version: 5.5.1
    WP Multisite: –
    WP Memory Limit: 1,000 MB
    WP Debug Mode: ?
    WP Cron: ?
    Language: pt_PT
    External object cache: –
    
    ### Server Environment ###
    
    Server Info: Apache/2.4.38 (Debian)
    PHP Version: 7.3.18
    PHP Post Max Size: 300 MB
    PHP Time Limit: 600
    PHP Max Input Vars: 1000
    cURL Version: 7.64.0
    OpenSSL/1.1.1d
    
    SUHOSIN Installed: –
    MySQL Version: 8.0.21
    Max Upload Size: 300 MB
    Default Timezone is UTC: ?
    fsockopen/cURL: ?
    SoapClient: ? Your server does not have the SoapClient class enabled - some gateway plugins which use SOAP may not work as expected.
    DOMDocument: ?
    GZip: ?
    Multibyte String: ?
    Remote Post: ?
    Remote Get: ?
    
    ### Database ###
    
    WC Database Version: 4.5.2
    WC Database Prefix: wp_
    Total Database Size: 3.31MB
    Database Data Size: 1.94MB
    Database Index Size: 1.37MB
    wp_woocommerce_sessions: Data: 0.09MB + Index: 0.02MB + Engine InnoDB
    wp_woocommerce_api_keys: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
    wp_woocommerce_attribute_taxonomies: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
    wp_woocommerce_downloadable_product_permissions: Data: 0.02MB + Index: 0.06MB + Engine InnoDB
    wp_woocommerce_order_items: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
    wp_woocommerce_order_itemmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
    wp_woocommerce_tax_rates: Data: 0.02MB + Index: 0.06MB + Engine InnoDB
    wp_woocommerce_tax_rate_locations: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
    wp_woocommerce_shipping_zones: Data: 0.02MB + Index: 0.00MB + Engine InnoDB
    wp_woocommerce_shipping_zone_locations: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
    wp_woocommerce_shipping_zone_methods: Data: 0.02MB + Index: 0.00MB + Engine InnoDB
    wp_woocommerce_payment_tokens: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
    wp_woocommerce_payment_tokenmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
    wp_woocommerce_log: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
    wp_actionscheduler_actions: Data: 0.02MB + Index: 0.11MB + Engine InnoDB
    wp_actionscheduler_claims: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
    wp_actionscheduler_groups: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
    wp_actionscheduler_logs: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
    wp_commentmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
    wp_comments: Data: 0.02MB + Index: 0.08MB + Engine InnoDB
    wp_links: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
    wp_options: Data: 1.03MB + Index: 0.03MB + Engine InnoDB
    wp_postmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
    wp_posts: Data: 0.02MB + Index: 0.06MB + Engine InnoDB
    wp_term_relationships: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
    wp_term_taxonomy: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
    wp_termmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
    wp_terms: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
    wp_usermeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
    wp_users: Data: 0.02MB + Index: 0.05MB + Engine InnoDB
    wp_wc_admin_note_actions: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
    wp_wc_admin_notes: Data: 0.02MB + Index: 0.00MB + Engine InnoDB
    wp_wc_category_lookup: Data: 0.02MB + Index: 0.00MB + Engine InnoDB
    wp_wc_customer_lookup: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
    wp_wc_download_log: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
    wp_wc_order_coupon_lookup: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
    wp_wc_order_product_lookup: Data: 0.02MB + Index: 0.06MB + Engine InnoDB
    wp_wc_order_stats: Data: 0.02MB + Index: 0.05MB + Engine InnoDB
    wp_wc_order_tax_lookup: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
    wp_wc_product_meta_lookup: Data: 0.02MB + Index: 0.09MB + Engine InnoDB
    wp_wc_reserved_stock: Data: 0.02MB + Index: 0.00MB + Engine InnoDB
    wp_wc_tax_rate_classes: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
    wp_wc_webhooks: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
    
    ### Post Type Counts ###
    
    attachment: 2
    page: 6
    post: 2
    
    ### Security ###
    
    Secure connection (HTTPS): ?
    Hide errors from visitors: ?
    
    ### Active Plugins (1) ###
    
    WooCommerce: by Automattic – 4.5.2
    
    ### Inactive Plugins (2) ###
    
    Akismet Anti-Spam: by Automattic – 4.1.6
    Hello Dolly: by Matt Mullenweg – 1.7.2
    
    ### Settings ###
    
    API Enabled: ?
    Force SSL: –
    Currency: EUR (€)
    Currency Position: left
    Thousand Separator: .
    Decimal Separator: ,
    Number of Decimals: 2
    Taxonomies: Product Types: external (external)
    grouped (grouped)
    simple (simple)
    variable (variable)
    
    Taxonomies: Product Visibility: exclude-from-catalog (exclude-from-catalog)
    exclude-from-search (exclude-from-search)
    featured (featured)
    outofstock (outofstock)
    rated-1 (rated-1)
    rated-2 (rated-2)
    rated-3 (rated-3)
    rated-4 (rated-4)
    rated-5 (rated-5)
    
    Connected to WooCommerce.com: –
    
    ### WC Pages ###
    
    Shop base: #6 - /loja/
    Cart: #7 - /carrinho/
    Checkout: #8 - /finalizar-compra/
    My account: #9 - /minha-conta/
    Terms and conditions: ? Page not set
    
    ### Theme ###
    
    Name: Twenty Twenty
    Version: 1.2 (update to version 1.5 is available)
    Author URL: https://www.ads-software.com/
    Child Theme: ? – If you are modifying WooCommerce on a parent theme that you did not build personally we recommend using a child theme. See: How to create a child theme
    WooCommerce Support: ?
    
    ### Templates ###
    
    Overrides: –
    
    ### Action Scheduler ###
    
    Complete: 1
    Oldest: 2020-09-23 15:49:54 +0000
    Newest: 2020-09-23 15:49:54 +0000
    
    
    • This topic was modified 4 years ago by ciberg.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Support Stuart Duff – a11n

    (@stuartduff)

    Automattic Happiness Engineer

    Hey @ciberg,

    What I’d initally suggest is using the Postman APP to test out your REST API calls to see if it provides any further information. WooCommerce has some information on testing API calls using the Postman APP and I’ve referenced that for you below you.

    https://github.com/woocommerce/woocommerce/wiki/Getting-started-with-the-REST-API

    Sometimes Postman App will reveal some error messages WordPress + WooCommerce would not.

    Thread Starter ciberg

    (@ciberg)

    Hi, using Postman I get exactly the same error:

    {
        "errors": [
            {
                "code": "woocommerce_api_product_category_image_upload_error",
                "message": "Erro ao obter imagem remota . Erro: O URL fornecido é inválido."
            }
        ]
    }

    note: the message is in Portuguese and translates as “Error getting remote image – invalid URL”

    The behaviour is the same with the ruby gem and with Postman.
    The request I use is on the first post.

    Please check the image to see if I am doing something wrong.
    Postman print

    jessepearson

    (@jessepearson)

    Automattic Happiness Engineer

    @ciberg It seems like this is an issue with the server being able to get the image for some reason. It may be timing out, or the url for the image is not accessible for some other reason? Are you able to ssh into the server to try to ping the url for the image to see if there’s a response? Maybe a small script on the server that tries to read the url could be another test.

    I just tested the API myself without any issues:


    Link to image: https://d.pr/i/QTQ6cZ

    This is my request:

    
    {
      "name": "API Test",
      "image": 
        {
          "src": "https://local.test/wp-content/uploads/2020/01/tron-2.jpg"
        }
    }
    

    Any my response:

    
    {
        "id": 298,
        "name": "API Test",
        "slug": "api-test",
        "parent": 0,
        "description": "",
        "display": "default",
        "image": {
            "id": 135486,
            "date_created": "2020-10-08T08:59:08",
            "date_created_gmt": "2020-10-08T11:59:08",
            "date_modified": "2020-10-08T08:59:08",
            "date_modified_gmt": "2020-10-08T11:59:08",
            "src": "https://local.test/wp-content/uploads/2020/10/tron-2-1.jpg",
            "name": "tron-2-1.jpg",
            "alt": ""
        },
        "menu_order": 0,
        "count": 0,
        "_links": {
            "self": [
                {
                    "href": "https://local.test/wp-json/wc/v3/products/categories/298"
                }
            ],
            "collection": [
                {
                    "href": "https://local.test/wp-json/wc/v3/products/categories"
                }
            ]
        }
    }
    

    And the category in the admin:


    Link to image: https://d.pr/i/8mijqm

    Thread Starter ciberg

    (@ciberg)

    @jessepearson You are a life saver.
    The problem was in the POST URL, I was using:
    /wc-api/v3/products/categories

    And it worked fine with without images but failed with image.

    Seeing your example I changed to /wp-json/wc/v3/products/categories and it worked with the image.

    Thank you!

    • This reply was modified 4 years ago by ciberg. Reason: clarify text
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Image URL related error creating category via REST API’ is closed to new replies.