I've set up a really simple SuiteLet to try a grap...
# suitescript
n
I've set up a really simple SuiteLet to try a graphql query using Axios. The library is in the correct folder with the script but when I try to do an AXIOS.post I get a "Cannot read property 'post' of undefined [at Object.onRequest (/SuiteScripts/GraphQL Test/simple_graphql_sl.js1723)]" What am I missing? (you can ignore the post section 😄 ) I feel it's probably something simple.
Copy code
**
 * @NApiVersion 2.1
 * @NScriptType Suitelet
 */
define(['N/record', 'N/ui/serverWidget','./axios.amd'],
 /**
 * @param {record} record
 * @param {serverWidget} serverWidget
 * @param {AXIOS} AXIOS
 */
       function (record, serverWidget, AXIOS) {
  function onRequest (context) {
    if (context.request.method === 'GET') {     
      let form = serverWidget.createForm({ title: 'Hi ', hideNavBar: false, id: 'get_axios' });
      const endpoint = "<https://main--space-devs.apollographos.net/graphql>";
      const headers = {"content-type": "application/json"};
      const myResponse = <http://AXIOS.post|AXIOS.post>({
          url: endpoint,
          headers: headers,
          data:`query AllAgencies {allAgencies {edges {node {country {name}}}}}`
      });
      
      let myField = form.addField({ id: 'ql_query', label: 'Query', type: serverWidget.FieldType.TEXTAREA });
      myField.defaultValue = myResponse.data;
      form.addSubmitButton({label:"Don't press me!"});
      context.response.writePage(form);
    }
    if (context.request.method === 'POST') {
      let form = serverWidget.createForm({ title: 'Hi ', hideNavBar: false, id: 'get_setup_magento_config' });
      let myField = form.addField({ id: 'ql_response', label: 'Response', type: serverWidget.FieldType.TEXTAREA });
      context.response.writePage(form)
    }
  }
  return {
    onRequest: onRequest
  };
});
c
Do the suitelet logs have any errors? Most likely its either the path is wrong, or there's something in the module thats not letting it load correctly. It's AMD so i'd expect it to load correctly though.
n
Yeah.. the error I posted 😄
Good lord, tell me there's not a string of dependencies I'd also need to include to use it... ugh
c
wasn't sure if it gave you a module loading error as well. I'm sure someone in here has done what you're doing its just not something i've done.
b
libraries that do i/o are essentially doomed unless written for netsuite
axios would have to use N/https to work
n
That was my original thought @battk but I figured the error would come at the point the module tried to make an outbound call, not complain that the module was undefined. 🤷‍♂️ Some clever soul at my company created an AWS4 module that was compatible with NS which made use of N/https. If I can figure out how he did it (no longer works for us), I might be able to do the same with the axios module.... I really needed this to work server side but I'll have a fiddle, to see if I can get it to do it in client since that's less rigid 🙂 Thanks both for your input.
b
if you really wanted to try and get it to work then you want to go through the source to find the define statement
usual causes for an undefined module is using a named module, which requires you to use a require Configuration to define the path
n
Thanks for the info, appreciated.