Sage X3 GraphQL Connectivity

SOLVED

As you may already know, starting Sage X3 2021 R2 (V12), a new integration pathway has been introduced; the mighty GraphQL. Invented by Facebook to used internally back in 2012, GraphQL has gained massive popularity for its lightweight query and response profiles and the good news is Sage X3 has been embracing this new technology for integration with third-party applications since mid-2021. In fact, X3's new ADC (Automated Data Collection) module uses GraphQL to integrate transactions and query data from X3.

In this discussion, I am going to show you how you can start using X3's GraphQL interface and take it for a spin using both X3's internal GraphQL IDE, called GraphiQL and Postman, so let's dig in:

First of all, you need to make sure you are on at least 2021R2. In this tutorial I am using the latest version of X3, i.e. 2022 R1. Sage is adding new queries and integrations (also called mutations in GraphQL lingo) with every release, so it is worth being on the latest version. To see the latest additions to the GraphQL interface with every release, please refer to the Release Notes on public help centre. 

Now, it's time to connect to Sage X3's GraphiQL tool to run a basic query. 

  1. Connect to Syracuse and log in as usual using your admin credentials
  2. open a new tab and navgate to: http://[YourSyracuseServer:Port]/xtrem/explorer/
    1. for instance, http://x3erpv12sqlvm:8124/xtrem/explorer/
  3. Now you should see GraphiQL's interface which looks like this:
  4. If you can see this interface, you can now test drive GraphQL to query data from X3 and write (integrate) transactions to it. As I said earlier, with every new release, there comes new query types and supported objects.
  5. We’ll start with a simple query, and get a list of products with their ID, Description 1 and whether they are of Received type. You will notice that GraphiQL will assist you in wrting code as you type, making it a very simple tool to learn.
  6. Now click the "Run" button on the top right to execute the command. You will receive a JSON response.
  7. Great right? I know. You can also use Postman to connect to the system and test the queries there, but Postman won't help you with auto-completion of code, so it is better to use both tools to achieve better results. e.g. GraphiQL to write and test the code and Postman to save and share it with others

Let's now go to Postman and run the same query, shall we?

  1. Open Postman and create a new Workspace. Let's call it "Sage X3 GraphQL" this time.
  2. Click on Create Collection button and call it GraphQL X3
    1. In the Authorization tab, choose Basic Authentication and enter your Syracuse admin credentials. You can also use other authentication methods for better security but this time we are going to use Basic Authentication
  3. Now, add a Request to your Collection  by Right Clicking on it and change its type to POST. Remember, it GraphQL, regardless of whether you are querying or integrating data, you must always use POST. Enter the following URL in the Request URL Section: http://[YourSyracuseServer:Port]/xtrem/api
    1. We will also rename this new request to "Product Query"
    2. Now make sure the Authorization tab says "Inherit from Parent" so this query uses the same authentication details of its parent, i.e. the Workspace
    3. Now go the Body of the Request and Choose GraphQL as your language of choice.
    4. This will open two columns, one for the query and one for the Variables. Noticed the similarity between this environment and X3's internal GraphiQL?
    5. You will learn more about using Variables in your Queries later by referring to the Sage Developer Portal linked below.
  4. Now Let's insert the same query into postman and run the request:
    1. We will receive the response in JSON format

To learn more about the API reference library and more examples, please go to Sage Developer portal, GraphQL section.Fast track to GraphQL | Sage Developer

I hope you enjoyed this article as much as I did writing it.

Please don't hesitate to comment your thoughts and queries below and I will do my best to respond promptly.

  • 0

    Hi , I'm trying to integrate some interfaces to a SAGE X3 client system, and I tried to follow up your instructions, but I think my client doesn't have configurated a Xtreem service, when I enter the endpoint "{{server}}/xtrem/explorer/" I get below error

    ETNA or XTreeM service URL must be configured

    Is there any manual or instruction of how to configure it? 

    Thanks and regards

  • 0 in reply to Nick Ward

    Thank you Nick, I will check the documentation, so after install the "X3Services_NewADC" the endpoint will be {{server}}/xtrem/api right?

  • 0 in reply to Cesar Nandez

    The {{server}}/xtrem/api url is correct.

  • 0

    Hi,

    I have installed the Sage X3 Services and confirmed I could test /handheld.

    For GraphQL side,

    I have tried to to access https://{{server}}:{{port}}/xtrem/explorer but I kept getting redirected back to https://{{server}}:{{port}}.

    Checking on syracuse log does not show anything.

     

    For the GraphQL api side, on-premise setup,

    https://{{server}}:{{port}}/xtrem/api without logging in provides: Error 401

    https://{{server}}:{{port}}/xtrem/api after logging in provides: {"errors":[{"message":"Must provide query string."}]}

    Running the on-premise GraphQL API program based from: https://developer.sage.com/x3/graphql/on-premise/create-nodejs-client-app/

    Note: URL is: https://{{server}}:{{port}}/xtrem/api

    Token validity is 60 for above screenshot

    If I do it that way, the Error is 401.

    If I reduce lifetime to 60, the Error is 404.

    From syracuse log:

    ```

    2022-10-18T14:29:28.870Z | 0456b7395e9f | | 183 | login.authentication | error | 401 Error 27: Invalid token null null
    2022-10-18T14:29:28.876Z | 0456b7395e9f | | 183 | session | error | ensureAuthenticated null Error 27: Invalid token Error: Error 27: Invalid token
    at error (C:\Sage\SyracuseComponent\syracuse\bin\node_modules\@sage\syracuse-lib\src\auth\helpers.jsc:211:15)
    at Function.authenticateJwt [as fiberized-0] (C:\Sage\SyracuseComponent\syracuse\bin\node_modules\@sage\syracuse-lib\src\auth\bearer.jsc:118:30)
    at Object.authenticate (C:\Sage\SyracuseComponent\syracuse\bin\node_modules\@sage\syracuse-lib\src\auth\bearer.jsc:23:58)
    at Function._ensureAuthenticated [as fiberized-0] (C:\Sage\SyracuseComponent\syracuse\bin\node_modules\@sage\syracuse-lib\src\auth\dispatcher.jsc:129:46)
    at Object.ensureAuthenticated (C:\Sage\SyracuseComponent\syracuse\bin\node_modules\@sage\syracuse-lib\src\auth\dispatcher.jsc:41:64)
    at (C:\Sage\SyracuseComponent\syracuse\bin\node_modules\syracuse-main\lib\route\authHelper.jsc:39:209)
    2022-10-18T14:29:28.878Z | 0456b7395e9f | | 183 | console | error | Error: Cannot render headers after they are sent to the client.
    at ClientActionWriteStream.writeHead (C:\Sage\SyracuseComponent\syracuse\bin\node_modules\@sage\syracuse-lib\src\load-balancer\mock\clientAction\stream\clientActionWriteStream.es5:170:23)
    at Function._ensureAuthenticated [as fiberized-0] (C:\Sage\SyracuseComponent\syracuse\bin\node_modules\@sage\syracuse-lib\src\auth\dispatcher.jsc:163:34)
    at Object.ensureAuthenticated (C:\Sage\SyracuseComponent\syracuse\bin\node_modules\@sage\syracuse-lib\src\auth\dispatcher.jsc:41:64)
    at (C:\Sage\SyracuseComponent\syracuse\bin\node_modules\syracuse-main\lib\route\authHelper.jsc:39:209)
    2022-10-18T14:29:28.879Z | | | | system.process | error | Uncaught exception Cannot render headers after they are sent to the client. Error: Cannot render headers after they are sent to the client.
    at ClientActionWriteStream.writeHead (C:\Sage\SyracuseComponent\syracuse\bin\node_modules\@sage\syracuse-lib\src\load-balancer\mock\clientAction\stream\clientActionWriteStream.es5:170:23)
    at handleRequestError (C:\Sage\SyracuseComponent\syracuse\bin\node_modules\syracuse-main\lib\route\authHelper.jsc:15:30)
    at C:\Sage\SyracuseComponent\syracuse\bin\node_modules\syracuse-main\lib\route\authHelper.jsc:42:24
    2022-10-18T14:32:38.783Z | d53ecb24a066 | | 184 | sdata | error | post /xtrem/api: 404 Not found: Endpoint not found: application x3, contract erp, dataset SEED_SEED
    2022-10-18T14:32:38.827Z | d53ecb24a066 | | 184 | sdata | error | xtrem dispatch /xtrem/api error: Error: not found
    at SdataContext.Context.exception (C:\Sage\SyracuseComponent\syracuse\bin\node_modules\@sage\syracuse-lib\src\sdata\sdataContext.jsc:835:18)
    at SdataContext.Context.notFound (C:\Sage\SyracuseComponent\syracuse\bin\node_modules\@sage\syracuse-lib\src\sdata\sdataContext.jsc:841:21)
    at xtremForwarder (C:\Sage\SyracuseComponent\syracuse\bin\node_modules\@sage\syracuse-lib\src\sdata\sdataDispatch.jsc:184:36)
    at (C:\Sage\SyracuseComponent\syracuse\bin\node_modules\syracuse-main\lib\syracuse.jsc:189:24)
    at (C:\Sage\SyracuseComponent\syracuse\bin\shadow-modules\win32-x64-83\node_modules\ez-streams\lib\fibers\node-wrappers.ts:629:22)

    ```

    Please advise.

  • 0 in reply to chunheng

    Whoops for on-premise one.

    Adjusting lifetime to 60 to match Connected Application 60 works.

    My Endpoint changed to SEED (the folder name and code is SEED) worked.

    Now, I am just stuck at: https://{{server}}:{{port}}/xtrem/explorer but I kept getting redirected back to https://{{server}}:{{port}}.

  • 0 in reply to chunheng

    Try adding / to the end of your URL

    https://{{server}}:{{port}}/xtrem/explorer/

  • +1 in reply to Nick Ward
    verified answer

    ...it's amazing how adding a forward slash at the end makes a difference.

    Fixed!

  • 0

    Is graphql available in 12.0.24 version?

  • 0

    Is graphql available in 12.0.24 version?

  • 0 in reply to ftballguy45

    It's been available since 2021R2 which is 12.0.25 if I am not mistaken.

  • 0

    Hi,

    I can access xtrem/explorer/ for my endpoint but when I click run, I just get this vague contact your administrator warning. Is there something that isn't configured?

    Regards,

    Andrew