Forum Replies Created

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter imjb87

    (@imjb87)

    @3sonsdevelopment it seems that I get these JSON syntax errors, but when I check the rest API logs in the WP admin using a logging plugin, it’s reporting that the update ran fine and returned a 200 success.

    Indeed when I check the product variation the updates seem to take place successfully despite the random error I get back through using the PHP wrapper.

    Would you suggest that I just used a plain REST interface such as guzzle, rather than trying to utilise the PHP wrapper?

    Thanks.

    Thread Starter imjb87

    (@imjb87)

    Please note that we provide no warranty or support for custom code or 3rd party plugins (meaning we cannot not help you further with this code snippet or www.remarpro.com / GitHub plugins). Use them at your own risk.

    So the REST API client is not official?

    Thread Starter imjb87

    (@imjb87)

    I’m assuming this PHP client is just a wrapper around CURL and makes HTTP requests, leaving the payload untouched. I could just use the guzzle package that plugs into Laravel quite well if this is potentially an issue.

    Thread Starter imjb87

    (@imjb87)

    I’m using the PHP client described here: https://github.com/woocommerce/wc-api-php

    A client has a third party EPOS which we poll every 10 minutes for stock updates, price updates etc. so I built a Laravel application to consume those changes, format them in a way that’s friendly to the Woo API and then make requests using the PHP client wrapper to put/post those changes.

    It’s difficult to give you a full request really because I’ve used my own wrapper class, but the idea is simple:

            $this->client = new Client(
                config('woocommerce.url'),
                config('woocommerce.key'),
                config('woocommerce.secret'),
                [
                    'wc_api' => true,
                    'version' => 'wc/v3'
                ]
            );

    This is inside the constructor of the class, setting a private variable for use across all methods:

    $response = collect($this->client->put("products/$productId/variations/$variationId", $data));

    This is inside a method called “updateProductVariation”:

                                $data = [
                                    "stock_quantity" => $CrossoverStockLevel['StockLevel']
                                ];
    
                                $Woocommerce->updateProductVariation($WoocommerceProduct->id, $WoocommerceVariation->id, $data);

    This is the request to that method (I grab IDs by SKU prior to making this request which works fine). The only bit that intermittently fails is the update, even though the syntax is the same every time.

    Thread Starter imjb87

    (@imjb87)

    It seems that the API doesn’t like updating anything through it, I’m now updating a top level product and get a similar JSON Syntax error with no explanation.

    This is the payload:

    array(
        'name' => 'Big Max Heaven 5 Golf Pencil bag',
        'description' => '',
        'short_description' => '',
        'regular_price' => '59.99',
        'categories' =>
        array(
          0 =>
          array(
            'name' => 'Bags',
            'id' => 172,
          ),
          1 =>
          array(
            'name' => 'Pencil Bags',
            'id' => 7704,
          ),
        ),
        'attributes' =>
        array(
          0 =>
          array(
            'name' => 'brand',
            'position' => 0,
            'visible' => true,
            'variation' => false,
            'options' =>
            array(
              0 => 'Big Max',
            ),
          ),
          1 =>
          array(
            'name' => 'colour',
            'position' => 0,
            'visible' => true,
            'variation' => true,
            'options' =>
            array(
              0 => 'Charcoal',
              1 => 'Red',
              2 => 'Colbalt Blue',
            ),
          ),
        ),
      )
    Thread Starter imjb87

    (@imjb87)

    Well yeah, I won’t be updating new stock quantities which is the whole point of why I’m doing this.

Viewing 6 replies - 1 through 6 (of 6 total)