Skip to content
Developerhome

Examples - queries, mutations and more

  Less than to read

Example Queries for Live GraphiQL Demo

GraphiQL is an in-browser IDE for writing, validating, and testing GraphQL queries. You can use GraphiQL to explore and interact with the X3 GraphQL API using the demo data provided.

Type queries into the left hand side panel of the endpoint screen, and you’ll see intelligent typeaheads aware of the current GraphQL type schema, live syntax, and validation errors highlighted within the text.

Some useful keyboard shortcuts are:

  • Prettify Query: Shift-Ctrl-P (or press the Prettify button)
  • Run Query: Ctrl-Enter (or press the Run button)
  • Auto Complete: Ctrl-Space (or just start typing)

Note: Queries are limited to 20 results on the demo endpoint.

The following example queries have been provided to help fast track your knowledge of our GraphQL service, and the GraphQL Query language. They are gathered together by available business objects.

Using Postman

Click “Run in Postman” to load the collection into Postman. We recommend using the Postman desktop app.

Run in Postman

Or, manually import the Postman collection:

  1. Download the Postman collection for X3 Endpoints.
  2. Open Postman and click Import.
  3. Select the downloaded Postman Collection file.
  4. The Collection are now ready to use in Postman.

Query the GraphQL Demo Endpoint Directly

Yes, you can query our GraphQL demo endpoint direct from the command line, or your own App!

The demo endpoint is unauthenticated, and although we’ve imposed read-only access, with a maximum return of 20 results per query, you can quickly demonstrate a working integration and/or proof of concept.

Using cURL

A simple example, which demonstrates how you can query our GraphQL demo endpoint direct from the command line:

  • Unix terminal

    curl \
    -H 'content-type: application/json;charset=UTF-8' \
    --request POST  --data-raw $'{"query":"{ xtremX3Structure{   address {     query(filter: \\"{ code: { _eq : \'002\' }, entity: { _eq : \'AO004\' } } \\"){       edges{         node {           code           description           entity           entityType         }       }     }   } }\\n}","variables":null}' \
    'https://apidemo.sagex3.com/demo/service/X3CLOUDV2_SEED/api'
    
  • Windows Powershell terminal

    curl -Uri "https://apidemo.sagex3.com/demo/service/X3CLOUDV2_SEED/api" `
    -Method "POST" `
    -ContentType "application/json;charset=UTF-8" `
    -Body "{`"query`":`"{\n  xtremX3Structure{\n    address {\n      query(filter: \`"{ code: { _eq : '002' }, entity: { _eq : 'AO004' } } \`"){\n        edges{\n          node {\n            code\n            description\n            entity\n            entityType\n          }\n        }\n      }\n    }\n  }\n}`",`"variables`":null}"  | Select-Object -Expand Content
    

TypeScript

Our development language of choice; a typed superset of JavaScript that compiles to plain JavaScript. Here’s an example of how you can use it to query our GraphQL demo endpoint:

  • First, you save the following code into a file. Let’s say that the filename is test.ts.

    const axios = require('axios');
    
    const callEndpoint = function() {
        const endpoint:string = "https://apidemo.sagex3.com/demo/service/X3CLOUDV2_SEED/api";
      const payload = {
          "query": "{  xtremX3Structure{ address { query(filter: \"{ code: { _eq : '002' }, entity: { _eq : 'AO004' } } \"){  edges{ node { code description entity entityType  } } } } } }",
          "variables": null
      };
      const options = {
          headers: {
              'Content-Type': 'application/json'
          }
      };
      axios.post(endpoint, JSON.stringify(payload), options).then(response => {
              console.log(JSON.stringify(response.data));
          })
          .catch(error => {
              console.log(error);
          });
    }
    
    callEndpoint();
    
  • Then start Visual Studio Code and open the folder where the previously saved file belongs.

  • Start a new terminal in Visual Studio Code, you need to install the required libraries:

    npm install @types/node
    npm install axios
    
  • You transcript the typescript into runnable javascript:

    tsc test.ts
    
  • You execute the output file:

    node test.js
    

JavaScript

A slight difference to our TypeScript example (see above), but we did it anyway.

  • First, you save the following code into a file. Let’s say the filename is test.js.

    const axios = require('axios');
    
    const callEndpoint = function() {
      const endpoint = "https://apidemo.sagex3.com/demo/service/X3CLOUDV2_SEED/api";
      const payload = {
          "query": "{  xtremX3Structure{ address { query(filter: \"{ code: { _eq : '002' }, entity: { _eq : 'AO004' } } \"){  edges{ node { code description entity entityType  } } } } } }",
          "variables": null
      };
      const options = {
          headers: {
              'Content-Type': 'application/json'
          }
      };
      axios.post(endpoint, JSON.stringify(payload), options).then(response => {
              console.log(JSON.stringify(response.data));
          })
          .catch(error => {
              console.log(error);
          });
    }
    
    callEndpoint();
    
  • Go the folder of the previously saved file in command line (Unix shell or Windows cmd), you need to install the required libraries:

    npm install axios
    
  • You execute the output file:

    node test.js