Skip to content
Developer home
X3

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.

To activate Postman’s Autocomplete feature for GraphQL , please follow this link for a complete guide how to importing ourGraphQL schema with our latest SDL schema file.

You can also download the introspection result of our GraphQL API here.

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 \
    --header "Content-Type: application/json" \
    --request POST \
    --data '{"query":"{sage {x3Sales { salesOrder (first: 5, orderBy: \"{ id: 1 }\") { edges { node { id, soldToCustomer {companyName } } } } } } }","variable":""}' \
    https://apidemo.sagex3.com/demo/service/X3CLOUDV2_SEED/graphql/
    
  • Windows Powershell terminal

    curl -Uri "https://apidemo.sagex3.com/demo/service/X3CLOUDV2_SEED/graphql/" -Method "POST"  -ContentType "application/json;charset=UTF-8" -Body "{`"query`":`"{ sage { x3Sales { salesOrder(first: 5, orderBy: \`"{ id: 1 }\`") { edges { node { id, soldToCustomer { companyName } } } } } } }`",`"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.

    let requestOriginal = require('request');
    
    let callEndpoint = async function(){
    
        var endpoint:String= "https://apidemo.sagex3.com/demo/service/X3CLOUDV2_SEED/graphql/";
        var data = {"query":"{sage {x3Sales { salesOrder (first: 5, orderBy: \"{ id: 1 }\") {  edges { node { id, soldToCustomer {companyName } } } } } } }","variable":""};
    
        requestOriginal.post({headers: {'content-type' : 'application/json'},
                              url: endpoint,
                              body: JSON.stringify(data)}, function (error, response, body) {
            if (!error) {
              console.log(body);
            } else {
              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 request
    
  • 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.

    let requestOriginal = require('request');
    
    let callEndpoint = async function(){
    
        var endpoint = "https://apidemo.sagex3.com/demo/service/X3CLOUDV2_SEED/graphql/";
        var data = {"query":"{sage {x3Sales { salesOrder (first: 5, orderBy: \"{ id: 1 }\") {  edges { node { id, soldToCustomer {companyName } } } } } } }","variable":""};
    
        requestOriginal.post({headers: {'content-type' : 'application/json'},
                              url: endpoint,
                              body: JSON.stringify(data)}, function (error, response, body) {
            if (!error) {
              console.log(body);
            } else {
              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 request
    
  • You execute the output file:

    node test.js
    

Sample App

In order to help you get started quickly with your own application development, we are providing sample application which cover the basic GraphQL API calls to the X3 application.