Ad

Php Curl With Shopify Trouble In Output

- 1 answer

So basically I just grab a code from here and test run it.

This is the code:

<?php

$url = "https://230******************dc20:b0817***************[email protected]*********s.myshopify.com/admin/customers.json";

$shopcurl = curl_init();
curl_setopt($shopcurl, CURLOPT_URL, $url);
curl_setopt($shopcurl, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($shopcurl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($shopcurl, CURLOPT_VERBOSE, 0);
curl_setopt($shopcurl, CURLOPT_HEADER, 1);
curl_setopt($shopcurl, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($shopcurl, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec ($shopcurl);
curl_close ($shopcurl);
echo "<pre>";
print_r($response);

?>

and i get this response:

HTTP/1.1 200 OK
Server: nginx
Date: Tue, 21 Feb 2017 09:24:50 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Vary: Accept-Encoding
Vary: Accept-Encoding
X-Frame-Options: DENY
X-ShopId: 17203005
X-ShardId: 4
X-Shopify-Shop-Api-Call-Limit: 1/40
HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT: 1/40
X-Stats-UserId: 0
X-Stats-ApiClientId: 1529067
X-Stats-ApiPermissionId: 40137419
X-Request-Id: cc57cc1a-da08-4460-bb34-53733b411c6d
Content-Security-Policy: default-src 'self' https://* shopify-pos://*;
X-Content-Type-Options: nosniff
X-Download-Options: noopen
X-Permitted-Cross-Domain-Policies: none
X-XSS-Protection: 1; mode=block; report=/xss-report?source%5Baction%5D=index&sour
P3P: CP="NOI DSP COR NID ADMa OPTa OUR NOR"
X-Dc: ash
X-Content-Type-Options: nosniff

{"orders":[{"id":4243430853,"email":"[email protected]","closed_at":null,"created_at":"2017-01-31T11:11:05+08:00","updated_...

all I need Is just the last line, And I just don't know how to remove the other lines. This tutorial here http://www.codefixup.com/create-app-and-getting-started-with-shopify-api-in-php/ just shows how to connect with the shopify but doesn't says how. Can anyone help me. Sorry for bad English.

Ad

Answer

The best way is to use some OOP Wrapper like this one

It give's you more control on curl request (headers, body, status code)

$curl = new Curl\Curl();
$curl->get($url);

if ($curl->error) {
    echo $curl->error_code;
}
else {
    echo $curl->response;
}
Ad
source: stackoverflow.com
Ad