我使用了一个CakePHP的插件来调用获取某些订单。我可以调用具有特定字段的所有订单,但我想知道如何调用以获取具有特定名称或order_number
的订单?这里是调用Shopify的源代码。它已经被认证和一切:
public function call($method, $path, $params=array())
{
if (!$this->isAuthorized())
return;
$password = $this->is_private_app ? $this->secret : md5($this->secret.$this->ShopifyAuth->token);
$baseurl = "https://{$this->api_key}:$password@{$this->ShopifyAuth->shop_domain}/";
$url = $baseurl.ltrim($path, '/');
$query = in_array($method, array('GET','DELETE')) ? $params : array();
$payload = in_array($method, array('POST','PUT')) ? stripslashes(json_encode($params)) : array();
$request_headers = in_array($method, array('POST','PUT')) ? array("Content-Type: application/json; charset=utf-8", 'Expect:') : array();
$request_headers[] = 'X-Shopify-Access-Token: ' . $this->ShopifyAuth->token;
list($response_body, $response_headers) = $this->Curl->HttpRequest($method, $url, $query, $payload, $request_headers);
$this->last_response_headers = $response_headers;
$response = json_decode($response_body, true);
if (isset($response['errors']) or ($this->last_response_headers['http_status_code'] >= 400))
throw new ShopifyApiException($method, $path, $params, $this->last_response_headers, $response);
return (is_array($response) and (count($response) > 0)) ? array_shift($response) : $response;
}
private function shopApiCallLimitParam($index)
{
if ($this->last_response_headers == null)
{
return 0;
}
$params = explode('/', $this->last_response_headers['http_x_shopify_shop_api_call_limit']);
return (int) $params[$index];
}
字符串
...以及执行GET
调用的代码:
// I only want the id and title of the collections
$fields = "fields=name,id,status,financial_status,fulfillment_status,billing_address,customer";
// get list of collections
$custom_collections = $this->ShopifyAPI->call('GET', "/admin/orders.json", $fields);
$this->set('collections', $custom_collections);
型
我想我错过了一个地方,我可以把条件的调用,以获得某些订单。我已经阅读了API文档,但似乎无法得到答案。
我尝试将?name=%231001
放在.json
之后的url上,试图获得订单**#1001**,但它返回一个空数组。
然后我尝试了order_number=1001
,但它给我带来了每一个订单以及1001 D:这真的很令人困惑,有人能帮我吗?
2条答案
按热度按时间ftf50wuq1#
我发现你实际上可以使用name或order_number来获取订单。这是另一个由于某种原因没有在文档中列出的属性。但是在URL中,如果你使用另一种语言,你所要在GET中添加的就是admin/order.json?name=%2310001&status=any这是为了获得订单10001,所以只需在%23之后添加order_number。我在Shopify大学的一个论坛上看到了这个,我只是在我的代码中实现了这个错误。如果你像我一样使用CakePhp shopify插件,我所做的就是在$字段上添加?name=%23”. number ."&status=any”;
我把代码留在这里:
字符串
希望对大家有帮助:P
wnrlj8wa2#
您不需要转义#,只需删除#并进行API调用即可
像这样https://myshopify.com/admin/api/2022-01/orders.json?name=12345678&status=any
对于订单:#12345678,它将返回完全相同的响应