Shopify脚本标记api返回400 HTTP错误

时间:2016-02-06 22:26:23

标签: php api curl shopify

当我向脚本标记请求创建脚本时,Shopify返回HTTP 400错误。

HTTP/1.1 400 Bad Request
Server: nginx
Date: Sat, 06 Feb 2016 22:16:00 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Status: 400 Bad Request
X-Frame-Options: DENY
X-ShopId: 11511010
X-ShardId: 2
X-Shopify-Shop-Api-Call-Limit: 1/40
HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT: 1/40
X-Stats-UserId: 0
X-Stats-ApiClientId: 1253884
X-Stats-ApiPermissionId: 17250892
X-XSS-Protection: 1; mode=block; report=/xss-report/30fa40b7-e2b9-44a1-b6ef-a3b43b8b95e3?source%5Baction%5D=create&source%5Bcontroller%5D=admin%2Fscript_tags&source%5Bsection%5D=admin
X-Request-Id: 30fa40b7-e2b9-44a1-b6ef-a3b43b8b95e3
X-Dc: chi2,ash

{"errors":{"script_tag":"Required parameter missing or invalid"}}

这是我的代码格式:

$request_headers[] = "X-Shopify-Access-Token:".$token_id;
$request_headers[] = "Content-Type : application/json";

$ch = curl_init('https://revestore.myshopify.com/admin/script_tags.json');
curl_setopt($ch , CURLOPT_HEADER, TRUE);
curl_setopt($ch , CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch , CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch , CURLOPT_MAXREDIRS, 3);
curl_setopt($ch , CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch , CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch , CURLOPT_TIMEOUT, 30);
curl_setopt($ch , CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch , CURLOPT_POSTFIELDS, $args); 
curl_setopt($ch , CURLOPT_HTTPHEADER, $request_headers);

$response = curl_exec($ch);
curl_close($ch);            
print_r($response);

如果有人知道相关解决方案,请帮助我。 在此先感谢。

2 个答案:

答案 0 :(得分:1)

如果您想创建新的ScriptTag资源,您需要的唯一参数/ $ args是eventsrc

设置id是我想象的导致问题

(另外,丢失created_atupdated_at,它们应该分别在创建/修改资源时由Shopify创建。

有关创建ScriptTag资源的文档: https://docs.shopify.com/api/uiintegrations/scripttag#create

答案 1 :(得分:0)

解决我的问题。这里一切都很好。只需要http_build_query($ query_string);处理JSON字符串。