[Special Summer Sale] 40% OFF All Magento 2 Themes

Cart

shopify how to get product data using php in my localhost

  • This topic is empty.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #9572
    akgola
    Participant

    I am looking a php script to get shopify product data by using php in my localhost server.I have already created storefront api but don’t have idea about it that how we will call using api key and fetch data.

    I read a lot of document which are related to same but nothing explore for php.
    https://help.shopify.com/api/storefront-api/getting-started#using-curl
    If anybody know about it please help me.

    #9574
    drip
    Participant

    If you only need to get the Products with PHP you can simply use their Rest API.

    Once you create a private app you get a similar URL:
    https://APIKEY:[email protected]/admin/products.json

    Where you will need to replace your APIKEY, PASSWORD and STORENAME with your own.

    And from there on if you know PHP it will be very easy to pull the JSON response from this URL.

    That’s all.

    #9575
    bhargav-kaklotara
    Participant

    you can make simple curl request for getting products detail using shopify
    admin api

    Request Pattern

    https://{api_key}:{shared_secrete}@shop_url.myshopify.com/admin/products.json
    

    Here i am using , Guzzle ( PHP HTTP client ) to create curl reuqest.

    But , you can also make curl request to make api call

    giving you one example

     $requestUrl = 'https://'.$username.':'$password.'@'.$shop_domain. '/admin/products.json';
    
     $client = new \GuzzleHttp\Client();
    
     $response = $client->request('GET', $requestUrl, [
        'headers' => [
            'Content-Type' => 'application/json',
            'Accept' => 'application/json'
         ]
     ]);
    
     $products = json_decode($response->getBody());
    

    So, Here you will get the products detail in json format

    But , remember this is for private app only for the public app you need a access-token from shopify API while sent in the call back after app install on the shop. save it on your local database. attach this token in each request to API and get data

    #9573
    denis-k
    Participant

    The simplest solution to get the list of products from a public APP using Guzzle:

    $url = "https://{$shopId}.myshopify.com/admin/api/2021-04/products.json";
    $client = new GuzzleHttp/Client();
    $headers = [
      'X-Shopify-Access-Token' => $oauthToken,
      'Content-Type' => 'application/json',
    ];
    $response = $client->get($url, ['verify' => false, 'headers' => $headers]);
    return (string) $response->getBody();
    
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.