Facility Control

 View Only
  • 1.  Dashboard asyncPost to GraphQL Apollo Server

    Posted 12-10-2023 22:47

    Has anyone had any experience with Dashboard and GraphQL?

    I've got a button that contains the following task:

              ogscript.debug("1")
     
              queryTest = 'query Domains {  domains {    name    status {      clocking      connectivity      latency      subscriptions      summary    }  }}';
     
              ogscript.asyncPost("http://172 * * */graphql?api_key=examplekey", queryTest, null, true);
     
              ogscript.debug("2")
    The query is formatted to match what the server is expecting but the debug window is returning an HTTP 400 error after '1' and '2'.
               '16:30:19:864: Server returned HTTP response code: 400 for URL: http://172. * * */graphql?api_k.-'..
    Is this an issue with how the ogscript.asyncPost object works with authentication headers? The documentation for Dashboard's 9.7 dev guide has no examples to reference.
    Thank you


    ------------------------------
    Syed Abbas
    Solution Architect
    Gencom Technologies
    ------------------------------


  • 2.  RE: Dashboard asyncPost to GraphQL Apollo Server

    Ross Staff
    Posted 01-04-2024 09:40

    Hi Syed

    The posted snippet should work provided a) The server will accept HTTP POST messages as opposed to just HTTP GET messages and that it allows the API KEY authentication to be sent as part of the QUERY STRING as opposed to part of the HTTP HEADERS.

    If your server is expecting the key as part of the headers, you will need to use ogscript.asyncHTTP to inject the new header fields:

    ogscript.asyncHTTP("http://172 * * */graphql", "POST", {'api_key': 'examplekey'}, queryTest, null, true);

    You should also check the casing (uppercase/lowercase/mixed) of the field names to make sure you are sending what the server is expecting.



    ------------------------------
    James Peltzer
    Ross Video
    ------------------------------



  • 3.  RE: Dashboard asyncPost to GraphQL Apollo Server

    Posted 03-17-2024 19:33

    Hey James,

    Thank you for the response. We've been slowly working through this issue in the background and have an update for you.

    This is our current script returning a 200 error message from the server. (Good news, we're in the right place.)

    ogscript.debug("1");

    function callback (result){

       ogscript.debug(ogscript.jsonToString(result));

    }

    queryTest = {"query":"query {Domains {  domains {    name    status {      clocking      connectivity      latency      subscriptions      summary    }  }}"};

    queryTest2 = {"query":"query { __typename }"};

    queryTest3 = {"query": "query Domains {domains {name status{clocking connectivity latency subscriptions summary}}}"};

    apikey = {'api_key':'OUR-API-KEY-HERE' };

    ogscript.asyncHTTP("http://172.23.5.201/graphql", "POST", 'application/json', queryTest3, callback, true);

    ogscript.debug("2");

    The debug window showing the 200 error due to the lack of authentication:

    11:54:55:372: 1

    11:54:55:380: 2

    11:54:55:390: {"responseCode":200,"contentType":"application/json; charset=utf-8","url":"http://172.23.5.201/graphql","value":"{\u0022errors\u0022:[{\u0022message\u0022:\u0022Unauthenticated user or user not found\u0022,\u0022locations\u0022:[{\u0022line\u0022:1,\u0022column\u0022:16}],\u0022path\u0022:[\u0022domains\u0022],\u0022extensions\u0022:{\u0022code\u0022:\u0022UNAUTHENTICATED\u0022}}],\u0022data\u0022:null}\n","bytes":[123,34,101,114,114,111,114,115,34,58,91,123,34,109,101,115,115,97,103,101,34,58,34,85,110,97,117,116,104,101,110,116,105,99,97,116,101,100,32,117,115,101,114,32,111,114,32,117,115,101,114,32,110,111,116,32,102,111,117,110,100,34,44,34,108,111,99,97,116,105,111,110,115,34,58,91,123,34,108,105,110,101,34,58,49,44,34,99,111,108,117,109,110,34,58,49,54,125,93,44,34,112,97,116,104,34,58,91,34,100,111,109,97,105,110,115,34,93,44,34,101,120,116,101,110,115,105,111,110,115,34,58,123,34,99,111,100,101,34,58,34,85,78,65,85,84,72,69,78,84,73,67,65,84,69,68,34,125,125,93,44,34,100,97,116,97,34,58,110,117,108,108,125,10]}

    Now this script below is the exact same but including the insertion of the authentication header in your post:

    ogscript.debug("1");

    function callback (result){

       ogscript.debug(ogscript.jsonToString(result));

    }

    queryTest = {"query":"query {Domains {  domains {    name    status {      clocking      connectivity      latency      subscriptions      summary    }  }}"};

    queryTest2 = {"query":"query { __typename }"};

    queryTest3 = {"query": "query Domains {domains {name status{clocking connectivity latency subscriptions summary}}}"};

    apikey = {'api_key':'OUR-API-KEY-HERE'};

    ogscript.asyncHTTP("http://172.23.5.201/graphql", "POST", {'api_key': 'apikey'}, 'application/json', queryTest3, callback, true);

    ogscript.debug("2");

    Here is what the debug window shows (I have highlighted the important area in bold):

    12:02:56:421: 1

    12:02:56:432: OGScript exception in script named >>>anonymousLabelTask<<< with content

    function thisIsTheDashBoardReservedFunctionName() {

    /*********          The line above was added by DashBoard because ogScript tasks are functions.      *********/

    Here our script is just printed out as it is above..

    /*********          The lines below were added by DashBoard because ogScript tasks are functions.      *********/

    }

    thisIsTheDashBoardReservedFunctionName()

    // This is the end of the ogScript

    EXCEPTION MESSAGE:

    org.mozilla.javascript.EvaluatorException: Can't find method com.rossvideo.common.oglml.ogscript.AbstractOGScriptCommands.asyncHTTP(string,string,object,string,object,function,boolean). (anonymousLabelTask#18)

                   and more org.mozilla.javascript runtime reports.. quite a few.

    --------------------------------------------------------------------------------

    I'm under the impression that by adding the authentication header for the api key we invalidate the expected fields in how asyncHTTP is as a command.

    We have successfully queried the graphQL server using powershell with the data in queryTest3 as well as the api key to make sure what we are trying to send is correct. We are attempting to do the same in dashboard now.

    Is there a way to include the authentication header without invalidating the content type field? We have tried the queryTest3 object before and after the content type field as well. 

    Thank you for your eyes on this,



    ------------------------------
    Syed Abbas
    Solution Architect
    Gencom Technologies
    ------------------------------



  • 4.  RE: Dashboard asyncPost to GraphQL Apollo Server

    Ross Staff
    Posted 03-18-2024 10:41

    Hi Syed

    The header fields argument replaces the content-type argument so you will need to manually add the content-type header yourself:

    ogscript.asyncHTTP("http://172.23.5.201/graphql", "POST", {'api_key': 'apikey', 'Content-Type': 'application/json'} , queryTest3, callback, true);



    ------------------------------
    James Peltzer
    Ross Video
    ------------------------------



  • 5.  RE: Dashboard asyncPost to GraphQL Apollo Server

    Posted 03-20-2024 20:20

    Hey James,

    We've now got a working query! Thank you very much for all the assistance.

    This did the trick and successfully queried the server:

    ogscript.asyncHTTP("http://172.23.5.201/graphql", "POST", {'api_key': 'apikey', 'Content-Type': 'application/json'}, query1, callback, true);

    Using the correctly formatted asyncHTTP command I am now attempting to make crosspoint changes on dante devices (through a dante domain) with a custom dashboard panel on an Ultritouch panel - very exciting!

    Thank you once again for all your assistance.

    Cheers,

    Calvin (Gencom Technology)



    ------------------------------
    Syed Abbas
    Solution Architect
    Gencom Technologies
    ------------------------------