# How I fetch the products from the shiphero by using the query method

**URL:** <https://community.shiphero.com/t/how-i-fetch-the-products-from-the-shiphero-by-using-the-query-method/818>\
**Category:** GraphQL API\
**Created:** [September 18, 2020, 7:37am UTC](https://community.shiphero.com/t/how-i-fetch-the-products-from-the-shiphero-by-using-the-query-method/818 "2020-09-18T07:37:37Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![brett](https://sea2.discourse-cdn.com/flex020/user_avatar/community.shiphero.com/brett/32/140_2.png) [@brett](https://community.shiphero.com/u/brett)\
**Post date:** [September 18, 2020, 11:52pm UTC](https://community.shiphero.com/t/how-i-fetch-the-products-from-the-shiphero-by-using-the-query-method/818/5 "2020-09-18T23:52:56Z")

</div>

Sonar,

You should be able to use low-level functions like cURL or any HTTP library (e.g. Guzzle) to manually make POST requests to your endpoint. If you use a tool like Postman (which is just like Insomnia) and they have a feature that will take your built request and convert it to a cURL request which you can manually rebuild in PHP.

The basics of it would be that the GraphQL query you build and the variables need to be wrapped in a JSON object and that object placed as the POST body:

```auto
{
  "query": "query($orderId:ID!) { order(id:$orderId) { transactions { createdAt gateway formattedGateway receipt } }}",
  "variables": { "orderId": "12345" }
}

```

Keep in mind that JSON doesn’t allow for multi-line strings. So generally the easiest thing to do would be to create an array and use `json_encode` to get the POST body:

```auto
$body = json_encode([
  "query": 'query($orderId:ID!) {
  order(id:$orderId) {
    transactions {
      createdAt
      gateway
      formattedGateway
      receipt
    }
  }
}',
  "variables": [
    "orderId": 12345,
  ]
]);

```

As for the request itself, all you need to specify is the correct headers, set the post body, and then send the request away and capture the response. A simplistic version would be:

```auto
$ch = curl_init();
curl_setopt_array($ch, [
  CURLOPT_POST => true,
  CURLOPT_POSTFIELDS => $body, // Created same as previous snippet
  CURLOPT_HTTPHEADER => [
    'Content-Type: application/json',
    'Accept: application/json',
    'Authorization: Bearer <ShipHeroAuthToken>',
  ],
  CURLOPT_RETURNTRANSFER => true,
]);
$response = curl_exec($ch);

```

Then you just need to parse the response JSON and extract the information you want/need out of it.

If you don’t want to build out your own mini-library for this, you can use Composer to install a client and use it instead (though they all basically do the same thing I just posted above).

[GraphQL PHP Client](https://packagist.org/packages/euautomation/graphql-client)  
[Gist of a minimal GraphQL client](https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=&cad=rja&uact=8&ved=2ahUKEwiSwved8fPrAhVk0FkKHWiYDQoQFjADegQIAhAB&url=https%3A%2F%2Fgist.github.com%2Fdunglas%2F05d901cb7560d2667d999875322e690a&usg=AOvVaw0yt16U1cb2-RPCxyp3wtmR)

Hope that helps. FWIW, I’m implementing something very similar using Go. The auth process has to be separate from the GraphQL stuff, but the auth process is pretty straightforward.

---

_[View the full topic](https://community.shiphero.com/t/how-i-fetch-the-products-from-the-shiphero-by-using-the-query-method/818)._
