API PUT via CURL: maximum redirects issue

Cole_Henley
Shopify Partner
2 0 1

I'm using a PHP library to post (put) data to update the products in my Shopify store via a Private App.
I can get information out just fine but when it comes to sending data to update product information I get the following error: 

Curl error: Maximum (3) redirects followed

Any ideas how to resolve this or what this signifies?

Am testing primarily with localhost but same issue experienced on hosted server. The response header from my curl request as follows:

[url] => https://nmsshop.myshopify.com/admin/auth/login
[content_type] => text/html; charset=utf-8
[http_code] => 303
[header_size] => 10636
[request_size] => 987
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 3
[total_time] => 2.138236
[namelookup_time] => 1.4E-5
[connect_time] => 1.6E-5
[pretransfer_time] => 5.4E-5
[size_upload] => 5
[size_download] => 112
[speed_download] => 52
[speed_upload] => 2
[download_content_length] => 0
[upload_content_length] => -1
[starttransfer_time] => 5.8E-5
[redirect_time] => 1.832385
[redirect_url] =>
[primary_ip] => 23.227.38.35
[primary_port] => 443
[local_ip] => 192.168.1.113
[local_port] => 58536

The shop in question is nmsshop.myshopify.com and the API key is 4bf32fb06e5fc1b2dbde39e17690a20e.

Cheers,

Cole

0 Likes
Cole_Henley
Shopify Partner
2 0 1

The PHP code am working with:

<?php

    require 'libs/shopify.php';
    define('SHOPIFY_API_KEY', '4bf32fb06e5fc1b2dbde39e17690a20e');
    define('SHOPIFY_SECRET', 'XXXX');
    define('SHOPIFY_SHOP', 'nmsshop.myshopify.com');

    $variant = array(
        'sku' => 'tieRed',
        'id' => 1109059849,
        'title' => 'Red',
        'inventory_quantity'=>'17'
        );
    $product = array(
        'id' =>  422795077,
        'variants' => array($variant)
        );
    $json['product'] = $product;
    
    $stock = json_encode($json);
    
    $sc = new ShopifyClient(SHOPIFY_SHOP, 'XXXX', SHOPIFY_API_KEY, SHOPIFY_SECRET);        

    try {
        $put = $sc->call('PUT', '/admin/products/#422795077.json',$stock);
        if ($put > 0) {
            echo $stockVal . ': success';
        } else {
            echo 'fail';
        }
    } catch (ShopifyApiException $e)
        {
            echo 'API fail';
            print_r($e);
        }
        catch (ShopifyCurlException $e)
        {   
            echo 'Curl fail (PUT)';
            print_r($e);
        }
    

 

Caleb_Andrada
Shopify Partner
3 0 0

Hi Cole,

I am currently having the same problem. I just wanted to know if you have found a solution to this?

 

0 Likes
Caleb_Andrada
Shopify Partner
3 0 0

Greetings,

I've figured out what was causing this and it's so simple that it's almost hard to catch. The URL call should not contain a '#' character therefore:

$put = $sc->call('PUT', '/admin/products/#422795077.json',$stock);

should be

$put = $sc->call('PUT', '/admin/products/422795077.json',$stock);

That solves the problem in this case.

 

I hope this helps newbies like me that comes accross this particular problem.

 

P.S.

I think this is such a basic mistake that could've been answered/pointed out so easily and yet OP's post was just sitting here for 3 months before I stumbled on this. To be honest, I find it frustrating that shopify's API documentation is really lacking in terms of defining what the example for a call is and what's not.

0 Likes
kneeki
Excursionist
23 2 4

Hey Caleb,

 

Thanks for posting this solution. I came across the same issue when trying to update the note field of an Order.

WRONG

curl_setopt($this->curl, CURLOPT_URL, $this->url . "/orders/#$id.json");

CORRECT

curl_setopt($this->curl, CURLOPT_URL, $this->url . "/orders/$id.json");

 

0 Likes
ChuckWatson
Excursionist
21 2 2

Thought i'd add to the discussion. This error just started for me today and I don't use the # for order id (never have). Currently clueless on why this would start suddenly today.

There's no meat in this?
0 Likes