我正在创建一个从 WordPress 调用 Shopify API 的私有应用程序。当我调用创建新的 Shopify 产品时,API 会创建产品但返回 404 Not Found 错误。我相信我的代码是正确的,因为它成功地在运行 apache 和 PHP 5.2.x 的 Windows XP 机器上的本地主机上创建了产品和适当的成功响应。当我从运行的开发服务器运行它时,我遇到了问题,我假设,Linux、apache 和 PHP 5.3.x。什么会导致 Shopify API 创建产品但返回 404?我将在下面包含通话和响应的日志。这篇文章确实成功地创建了一个产品,但由于它返回了一个错误,我无法检索新创建的产品 ID。
谢谢,史蒂夫
2012-06-05 @ 17:47:36:请求发送到 https://xxx:xxx@colab-5.myshopify.com/admin/products.json 参数:数组([方法] => POST [超时] = > 5 [redirection] => 5 [httpversion] => 1.0 [user-agent] => WordPress/3.3.2; http://xxx.colab.coop [blocking] => 1 [headers] => Array ( )
[cookies] => Array
(
)
[body] => Array
(
[product] => Array
(
[title] => Bracelet 7
[body_html] => Bracelet 7 descr
[vendor] => xxx
[product_type] => bracelet
[published] => 1
[images] => Array
(
[src] => http://xxx.colab.coop/xxx/stb-1.png
)
[variants] => Array
(
[option1] => small
[price] => 123
[inventory_management] => shopify
[sku] => 234
[grams] => 226.79618519019
[inventory_quantity] => 123
)
)
)
[compress] =>
[decompress] => 1
[sslverify] => 1
[stream] =>
[filename] =>
)
2012-06-05 @ 17:47:37:从 https://xxx:xxx@colab-5.myshopify.com/admin/products.json 收到响应传输:WP_HTTP_curl 响应:数组([标题] => 数组( [server] => nginx [date] => Tue, 05 Jun 2012 17:47:37 GMT [content-type] => text/html; charset=utf-8 [connection] => close [vary] => Accept -Encoding [status] => 404 Not Found [cache-control] => no-cache [x-request-id] => 62c48e7991c1f29cf5917727b160cee9 [x-ua-compatible] => IE=Edge,chrome=1 [x-runtime ] => 0.025681)
[body] => <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http
://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<title>404 - Not Found</title>
<link href="https://cdn.shopify.com/s/assets/dialog-ef6bd71e99b2c7a469ce6385ab855360.css" media="screen" rel="stylesheet" type="text/css" />
</head>
<body class="netural-dialog">
<div id="container">
<div id="dialog">
<h1>Not Found</h1>
<p class="c">The page you were looking for does not exist...</p>
</div> <!-- dialog -->
</div> <!-- container -->
<div id="footer">
<p><a href="http://www.shopify.com">Ecommerce Software by Shopify</a></p>
</div>
</body>
</html>
[response] => Array
(
[code] => 404
[message] => Not Found
)
[cookies] => Array
(
)
[filename] =>
)
更新更多日志。这创建了 Shopify 产品 93781002。
*** REQUEST ***
2012-06-08 @ 00:14:20: request sent to
https://xxx:xxx@colab-5.myshopify.com/admin/products.json
Parameters: Array
(
[method] => POST
[timeout] => 5
[redirection] => 5
[httpversion] => 1.0
[user-agent] => WordPress/3.3.2; http://xxx.colab.coop
[blocking] => 1
[headers] => Array
(
[Content-Type] => application/json; charset=UTF-8
)
[cookies] => Array
(
)
[body] => {"product":{"title":"Bracelet 2","body_html":"Bracelet 2 description","vendor":"Steve","product_type":"bracelet","published":true,"images":{"src":"http:\/\/lr.colab.coop\/wordpress\/wp-content\/themes\/lr\/images\/stb-1.png"},"variants":{"option1":"default","price":"123","inventory_management":"shopify","sku":"555","grams":453.59237038038,"inventory_quantity":"22"},"metafields":{"key":"wp_post_id","value":174,"value_type":"string","namespace":"inventory"}}}
[compress] =>
[decompress] => 1
[sslverify] =>
[stream] =>
[filename] =>
)
---------------------------------
*** RESPONSE **********
2012-06-08 @ 00:14:21: response received from
https://xxx:xxx@colab-5.myshopify.com/admin/products.json
Transport: WP_HTTP_curl
Response: Array
(
[headers] => Array
(
[server] => nginx
[date] => Fri, 08 Jun 2012 00:14:21 GMT
[content-type] => text/html; charset=utf-8
[connection] => close
[vary] => Accept-Encoding
[status] => 404 Not Found
[cache-control] => no-cache
[x-request-id] => ec0ff57554c9deea607c407e00c6c223
[x-ua-compatible] => IE=Edge,chrome=1
[x-runtime] => 0.012695
)
[body] => <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<title>404 - Not Found</title>
<link href="https://cdn.shopify.com/s/assets/dialog-ef6bd71e99b2c7a469ce6385ab855360.css" media="screen" rel="stylesheet" type="text/css" />
</head>
<body class="netural-dialog">
<div id="container">
<div id="dialog">
<h1>Not Found</h1>
<p class="c">The page you were looking for does not exist...</p>
</div> <!-- dialog -->
</div> <!-- container -->
<div id="footer">
<p><a href="http://www.shopify.com">Ecommerce Software by Shopify</a></p>
</div>
</body>
</html>
[response] => Array
(
[code] => 404
[message] => Not Found
)
[cookies] => Array
(
)
[filename] =>
)
---------------------------------
很抱歉在这里转储了这么多内容,但这里是 6 月 13 日的新日志。第一次调用成功创建了 Shopify 产品“Office Ring 1”,但返回了错误消息。然后我手动将 shopify id 添加到我的本地产品中,然后成功添加了一个变体“medium”,但这也返回了一条错误消息。这些来自网络农场 nix 服务器。然后我从我的 Windows 笔记本电脑上的本地 Web 服务器运行相同的一组请求。这些请求还成功创建了产品“Home Ring 1”,但返回了适当的成功消息。
*** REQUEST ***
2012-06-13 @ 12:18:38: request sent to
https://removed_aac8:removed_e2ba@colab-5.myshopify.com/admin/products.json
Parameters: Array
(
[method] => POST
[timeout] => 5
[redirection] => 5
[httpversion] => 1.0
[user-agent] => WordPress/3.3.2; http://removed.colab.coop
[blocking] => 1
[headers] => Array
(
[Content-Type] => application/json; charset=UTF-8
)
[cookies] => Array
(
)
[body] => {"product":{"title":"Office Ring 1","body_html":"Office Ring 1 description","vendor":"Steve","product_type":"ring","published":true,"variants":{"option1":"small","price":"123","inventory_management":"shopify","sku":"1234","grams":226.79618519019,"inventory_quantity":"10"},"images":{"position":1,"src":"http:\/\/lr.colab.coop\/wordpress\/wp-content\/themes\/lr\/images\/stb-1.png"}}}
[compress] =>
[decompress] => 1
[sslverify] =>
[stream] =>
[filename] =>
)
---------------------------------
*** RESPONSE **********
2012-06-13 @ 12:18:40: response received from
https://removed_aac8:removed_e2ba@colab-5.myshopify.com/admin/products.json
Transport: WP_HTTP_curl
Response: Array
(
[headers] => Array
(
[server] => nginx
[date] => Wed, 13 Jun 2012 12:18:40 GMT
[content-type] => text/html; charset=utf-8
[connection] => close
[vary] => Accept-Encoding
[status] => 404 Not Found
[cache-control] => no-cache
[x-request-id] => f5ef52645dc28af4993c1378440ad19a
[x-ua-compatible] => IE=Edge,chrome=1
[x-runtime] => 0.019331
)
[body] => <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<title>404 - Not Found</title>
<link href="https://cdn.shopify.com/s/assets/dialog-ef6bd71e99b2c7a469ce6385ab855360.css?351e96af6f2f2a94c178c053ba0d35a46ec146b4" media="screen" rel="stylesheet" type="text/css" />
</head>
<body class="netural-dialog">
<div id="container">
<div id="dialog">
<h1>Not Found</h1>
<p class="c">The page you were looking for does not exist...</p>
</div> <!-- dialog -->
</div> <!-- container -->
<div id="footer">
<p><a href="http://www.shopify.com">Ecommerce Software by Shopify</a></p>
</div>
</body>
</html>
[response] => Array
(
[code] => 404
[message] => Not Found
)
[cookies] => Array
(
)
[filename] =>
)
---------------------------------
*** REQUEST ***
2012-06-13 @ 12:22:26: request sent to
https://removed_aac8:removed_e2ba@colab-5.myshopify.com/admin/products/94072324/variants.json
Parameters: Array
(
[method] => POST
[timeout] => 5
[redirection] => 5
[httpversion] => 1.0
[user-agent] => WordPress/3.3.2; http://removed.colab.coop
[blocking] => 1
[headers] => Array
(
[Content-Type] => application/json; charset=UTF-8
)
[cookies] => Array
(
)
[body] => {"variant":{"option1":"medium","price":"123","inventory_management":"shopify","sku":"1235","grams":226.79618519019,"inventory_quantity":"11"}}
[compress] =>
[decompress] => 1
[sslverify] =>
[stream] =>
[filename] =>
)
---------------------------------
*** RESPONSE **********
2012-06-13 @ 12:22:27: response received from
https://removed_aac8:removed_e2ba@colab-5.myshopify.com/admin/products/94072324/variants.json
Transport: WP_HTTP_curl
Response: Array
(
[headers] => Array
(
[server] => nginx
[date] => Wed, 13 Jun 2012 12:22:27 GMT
[content-type] => text/html; charset=utf-8
[connection] => close
[vary] => Accept-Encoding
[status] => 200 OK
[etag] => "450e16059f610a357485485b091697f7"
[cache-control] => max-age=0, private, must-revalidate
[x-request-id] => 2ebbec10eefda01f51e06d9d5ed4004f
[x-ua-compatible] => IE=Edge,chrome=1
[set-cookie] => _secure_session_id=8efbf69a284bbc7f3652ac6f34e9a2ba; path=/; secure; HttpOnly
[x-runtime] => 0.025468
[p3p] => CP="NOI DSP COR NID ADMa OPTa OUR NOR"
)
[body] => <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<script type="text/javascript">var NREUMQ=NREUMQ||[];NREUMQ.push(["mark","firstbyte",new Date().getTime()]);</script>
<title>Shopify » Please Log In</title>
<link href="https://cdn.shopify.com/s/assets/dialog-ef6bd71e99b2c7a469ce6385ab855360.css?351e96af6f2f2a94c178c053ba0d35a46ec146b4" media="screen" rel="stylesheet" type="text/css" />
<!--[if IE 6]>
<link href="https://cdn.shopify.com/s/assets/ie-e556ea04e7e58d6a732ca8d5254a1edc.css?351e96af6f2f2a94c178c053ba0d35a46ec146b4" media="screen" rel="stylesheet" type="text/css" />
<![endif]-->
<script src="https://cdn.shopify.com/s/assets/admin/auth-0b1f81e1e47d1c2021fc18fe8772a287.js?351e96af6f2f2a94c178c053ba0d35a46ec146b4" type="text/javascript"></script>
<script type="text/javascript" language="javascript">
window.onload = function() {
if ($('login-input')) {
if ($('login-input').value == '') {
Field.activate('login-input');
}
else {
Field.activate('password');
}
}
}
</script>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-82702-18' ]);
_gaq.push(['_setDomainName', '.myshopify.com']);
_gaq.push(['_setAllowHash', false]);
_gaq.push(['_setCustomVar',
1,
'CustomerType',
'prospect',
2
]);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</head>
<body>
<div id="container">
<div id="dialog">
<div id="system_error" class="status system-error"><p>Login or password was invalid.</p></div>
<div class="ssb c">
<img alt="Shopify-logo-new" src="https://cdn.shopify.com/s/images/admin/shopify-logo-new.jpg?351e96af6f2f2a94c178c053ba0d35a46ec146b4" />
</div>
<form accept-charset="UTF-8" action="/admin/auth/login" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓" /><input name="authenticity_token" type="hidden" value="RSdZQn6QN2MfWeyb6JwkbYKlxi4wxdvLxKEAEuChE/8=" /></div>
<div id="sign-in-form" class="lform">
<noscript><p>Please note that in order to use the Shopify administration interface you need to <a href="/documents/javascript.html">enable javascript</a>.</p></noscript>
<input type="hidden" name="redirect" value="" id="redirect" />
<div id="login" >
<div class="ppb clearfix">
<label id="email_address" for="login-input">Email Address</label>
<input type="email" name="login" size="30" id="login-input" class="email" value="" class="error" tabindex=1 />
</div>
<div class="ppb clearfix">
<label id="password_label" for="password">Password</label>
<input type="password" name="password" size="16" id="password" class="error" tabindex=2 />
<div id="forgot-password">
<a href="/admin/auth/recover">Forgot your password?</a>
</div>
</div>
<div class="ppb c">
<input name="remember" type="checkbox" id="remember_checkbox" value="1" />
<label for="remember_checkbox" class="normal">Remember me on this computer</label>
</div>
</div>
<div id="open-id" style="display:none">
<div class="ppb clearfix">
<label id="open_id" for="openid-input" class="open-id">OpenID</label>
<input type="text" name="openid_url" value="" class="url" id="openid-input" class="error" />
</div>
</div>
<div class="actions">
<input class="btn" name="commit" tabindex="3" type="submit" value="Sign In" />
</div>
</div>
</form>
<script type="text/javascript" charset="utf-8">
document.observe("dom:loaded", function() {
$$('input').each(function(e) {
e.autocapitalize = false;
});
});
</script>
</div>
</div>
<div id="footer">
<div>
<span style='padding-left:10px;'>
<img alt="Google_apps-16" src="https://cdn.shopify.com/s/images/admin/icons/google_apps-16.png?351e96af6f2f2a94c178c053ba0d35a46ec146b4" />
<a href="/admin/auth/login?google_apps=1">Login with Google Apps</a>
</span>
</div>
</div>
<script type="text/javascript">if (!NREUMQ.f) { NREUMQ.f=function() {
NREUMQ.push(["load",new Date().getTime()]);
var e=document.createElement("script");
e.type="text/javascript";e.async=true;e.src="https://d1ros97qkrwjf5.cloudfront.net/38/eum/rum-staging.js";
document.body.appendChild(e);
if(NREUMQ.a)NREUMQ.a();
};
NREUMQ.a=window.onload;window.onload=NREUMQ.f;
};
NREUMQ.push(["nrfj","beacon-1.newrelic.com","fa45dcf839",151,"dl8KQUReDl4AEE1TVVhZChpXRBZaSg4NVVhb",0.0,17,new Date().getTime(),"","","","",""])</script>
</body>
</html>
[response] => Array
(
[code] => 200
[message] => OK
)
[cookies] => Array
(
[0] => WP_Http_Cookie Object
(
[name] => _secure_session_id
[value] => 8efbf69a284bbc7f3652ac6f34e9a2ba
[expires] =>
[path] => /
[domain] =>
[secure] =>
[httponly] =>
)
)
[filename] =>
)
---------------------------------
现在成功的 Home 日志
*** REQUEST ***
2012-06-13 @ 12:27:40: request sent to
https://removed_aac8:removed_e2ba@colab-5.myshopify.com/admin/products.json
Parameters: Array
(
[method] => POST
[timeout] => 5
[redirection] => 5
[httpversion] => 1.0
[user-agent] => WordPress/3.3.2; http://localhost/knowledgetown/office/wordpress
[blocking] => 1
[headers] => Array
(
[Content-Type] => application/json; charset=UTF-8
)
[cookies] => Array
(
)
[body] => {"product":{"title":"Home Ring 1","body_html":"Home Ring 1 description","vendor":"Auto Draft","product_type":"ring","published":true,"variants":{"option1":"small","price":"123","inventory_management":"shopify","sku":"1234","grams":226.79618519019,"inventory_quantity":"10"},"images":{"position":1,"src":"http:\/\/lr.colab.coop\/wordpress\/wp-content\/themes\/lr\/images\/stb-1.png"}}}
[compress] =>
[decompress] => 1
[sslverify] =>
[stream] =>
[filename] =>
)
---------------------------------
*** RESPONSE **********
2012-06-13 @ 12:27:41: response received from
https://removed_aac8:removed_e2ba@colab-5.myshopify.com/admin/products.json
Transport: WP_HTTP_curl
Response: Array
(
[headers] => Array
(
[server] => nginx
[date] => Wed, 13 Jun 2012 12:27:40 GMT
[content-type] => application/json; charset=utf-8
[connection] => close
[status] => 201 Created
[x-shopify-shop-api-call-limit] => 1/500
[http_x_shopify_shop_api_call_limit] => 1/500
[location] => https://colab-5.myshopify.com/admin/products/94072592
[cache-control] => no-cache
[x-request-id] => 36b9127191967ed4bf9b2039eb651790
[x-ua-compatible] => IE=Edge,chrome=1
[set-cookie] => _secure_session_id=15d92980d403a103a3e8da29a33c8e7f; path=/; secure; HttpOnly
[x-runtime] => 0.585917
)
[body] => {"product":{"body_html":"Home Ring 1 description","created_at":"2012-06-13T08:27:40-04:00","handle":"home-ring-1","id":94072592,"product_type":"ring","published_at":"2012-06-13T08:27:40-04:00","template_suffix":null,"title":"Home Ring 1","updated_at":"2012-06-13T08:27:40-04:00","vendor":"Auto Draft","tags":"","variants":[{"compare_at_price":null,"created_at":"2012-06-13T08:27:40-04:00","fulfillment_service":"manual","grams":226,"id":220076798,"inventory_management":"shopify","inventory_policy":"deny","option1":"small","option2":null,"option3":null,"position":1,"price":"123.00","product_id":94072592,"requires_shipping":true,"sku":"1234","taxable":true,"title":"small","updated_at":"2012-06-13T08:27:40-04:00","inventory_quantity":10}],"images":[{"created_at":"2012-06-13T08:27:40-04:00","id":187968224,"position":1,"product_id":94072592,"updated_at":"2012-06-13T08:27:40-04:00","src":"http://cdn.shopify.com/s/files/1/0157/0142/products/stb-2.png?241"}],"options":[{"name":"Title"}]}}
[response] => Array
(
[code] => 201
[message] => Created
)
[cookies] => Array
(
[0] => WP_Http_Cookie Object
(
[name] => _secure_session_id
[value] => 15d92980d403a103a3e8da29a33c8e7f
[expires] =>
[path] => /
[domain] =>
[secure] =>
[httponly] =>
)
)
[filename] =>
)
---------------------------------
*** REQUEST ***
2012-06-13 @ 12:28:13: request sent to
https://removed_aac8:removed_e2ba@colab-5.myshopify.com/admin/products/94072592/variants.json
Parameters: Array
(
[method] => POST
[timeout] => 5
[redirection] => 5
[httpversion] => 1.0
[user-agent] => WordPress/3.3.2; http://localhost/knowledgetown/office/wordpress
[blocking] => 1
[headers] => Array
(
[Content-Type] => application/json; charset=UTF-8
)
[cookies] => Array
(
)
[body] => {"variant":{"option1":"medium","price":"123","inventory_management":"shopify","sku":"1235","grams":226.79618519019,"inventory_quantity":"11"}}
[compress] =>
[decompress] => 1
[sslverify] =>
[stream] =>
[filename] =>
)
---------------------------------
*** RESPONSE **********
2012-06-13 @ 12:28:13: response received from
https://removed_aac8:removed_e2ba@colab-5.myshopify.com/admin/products/94072592/variants.json
Transport: WP_HTTP_curl
Response: Array
(
[headers] => Array
(
[server] => nginx
[date] => Wed, 13 Jun 2012 12:28:13 GMT
[content-type] => application/json; charset=utf-8
[connection] => close
[status] => 201 Created
[x-shopify-shop-api-call-limit] => 4/500
[http_x_shopify_shop_api_call_limit] => 4/500
[location] => https://colab-5.myshopify.com/admin/products/94072592/variants
[cache-control] => no-cache
[x-request-id] => fd0cfb4f0279424a850d6bf100533f1d
[x-ua-compatible] => IE=Edge,chrome=1
[set-cookie] => _secure_session_id=63dd9cc4fcd51eacb0a792ffb148de5e; path=/; secure; HttpOnly
[x-runtime] => 0.069807
)
[body] => {"variant":{"compare_at_price":null,"created_at":"2012-06-13T08:28:13-04:00","fulfillment_service":"manual","grams":226,"id":220076802,"inventory_management":"shopify","inventory_policy":"deny","option1":"medium","option2":null,"option3":null,"position":2,"price":"123.00","product_id":94072592,"requires_shipping":true,"sku":"1235","taxable":true,"title":"medium","updated_at":"2012-06-13T08:28:13-04:00","inventory_quantity":11}}
[response] => Array
(
[code] => 201
[message] => Created
)
[cookies] => Array
(
[0] => WP_Http_Cookie Object
(
[name] => _secure_session_id
[value] => 63dd9cc4fcd51eacb0a792ffb148de5e
[expires] =>
[path] => /
[domain] =>
[secure] =>
[httponly] =>
)
)
[filename] =>
)
---------------------------------