TRIGGERcmd
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    Pass parameters when using bookmark URLs?

    General Discussion
    3
    12
    2.9k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • I
      Insaneoctane
      last edited by

      I have a powershell script that I want to activate via an html button. I have seen an example on this but need to figure out how to pass a parameter via the button to my powershell script via TC. Specifically, I will build the html page that prompts for an integer between 50 and 100 and sends the bookmark URL with this parameter to TC which launches my powershell script passing the parameter. My powershell script is already complete and expects to be launched with a command line parameter. I also have it listed as an action in TC... I just need some help putting these pieces together!

      RussR 1 Reply Last reply Reply Quote 0
      • RussR
        Russ @Insaneoctane
        last edited by Russ

        @insaneoctane, I could add the ability to add a URL parameter to the bookmark URL's. Would that work?

        Like this:

        https://www.triggercmd.com/trigger/bookmark?token=bookmarktoken&params=foo
        

        EDIT: I added that capability. Now you can add &params=foo to the end of your bookmark URL to send a parameter of foo to your command. That assumes you've enabled parameters on your command of course.

        Russell VanderMey

        1 Reply Last reply Reply Quote 0
        • I
          Insaneoctane
          last edited by

          @russ said in Pass parameters when using bookmark URLs?:

          https://www.triggercmd.com/trigger/bookmark?token=bookmarktoken&params=foo

          Russ, that is fantastic that you could add that capability so quickly! I tried the API too and I'm getting the same CORS error. I'm SO not that knowledgeable with CORS/networks stuff, but I think the CORS error is because my javascript isn't being allowed to GET the bookmark (or API) without a proper header from triggercmd.com domain???? Have you seen or dealt with this before?

          Here's the errors I'm seeing in the dev console from chrome:

          Access to fetch at 'https://www.triggercmd.com/trigger/bookmark?token=XXXXX&params=75' from origin 'http://127.0.0.1' has been blocked by CORS policy: The 'Access-Control-Allow-Origin' header contains the invalid value ''. Have the server send the header with a valid value, or, if an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

          XXXX.html:74 Cross-Origin Read Blocking (CORB) blocked cross-origin response https://www.triggercmd.com/trigger/bookmark?token=XXXXX&params=75 with MIME type text/html. See https://www.chromestatus.com/feature/5629709824032768 for more details.

          RussR 1 Reply Last reply Reply Quote 0
          • RussR
            Russ @Insaneoctane
            last edited by

            @insaneoctane, I used this web page to test, and I wasn't able to reproduce the error.

            Can you send me something that would help me reproduce it?

            <!DOCTYPE html>
            <html>
            <head>
            <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
            <script>
            $(document).ready(function(){
                $("button").click(function(){
                    $.get("https://www.triggercmd.com/trigger/bookmark?token=(bookmarkToken)",
                    {
                      params: "Donald Duck",
                    },
                    function(data,status){
                        alert("Data: " + data + "\nStatus: " + status);
                    });
                });
            });
            </script>
            </head>
            <body>
            
            <button>Send an HTTP GET request to a page and get the result back</button>
            
            </body>
            </html>

            Russell VanderMey

            1 Reply Last reply Reply Quote 0
            • I
              Insaneoctane
              last edited by Insaneoctane

              @Russ,
              Just curious if you ran your script from triggercmd.com domain?

              1 Reply Last reply Reply Quote 0
              • RussR
                Russ
                last edited by Russ

                @insaneoctane, no I served that page from w3schools. Please try it here:

                https://www.w3schools.com/code/tryit.asp?filename=FX706MSHLN0A

                Russell VanderMey

                I 1 Reply Last reply Reply Quote 0
                • I
                  Insaneoctane @Russ
                  last edited by

                  @russ
                  I can't thank you enough for your time on this issue!
                  I ran the snippet from the W3 site you linked to, clicked the button and got nothing. To see what was happening (I'm in Chrome) I hit F12 and opened up the developers console and saw CORS errors. Here's a snip from the console:

                  Access to XMLHttpRequest at 'https://www.triggercmd.com/trigger/bookmark?token=(youBookmarktoken)&params=Donald Duck' from origin 'https://tryit.w3schools.com' has been blocked by CORS policy: The 'Access-Control-Allow-Origin' header contains the invalid value ''.
                  VM38:1 Cross-Origin Read Blocking (CORB) blocked cross-origin response https://www.triggercmd.com/trigger/bookmark?token=(youBookmarktoken)&params=Donald Duck with MIME type text/html. See https://www.chromestatus.com/feature/5629709824032768 for more details.
                  (anonymous) @ VM38:1
                  send @ jquery.min.js:2
                  ajax @ jquery.min.js:2
                  w.(anonymous function) @ jquery.min.js:2
                  (anonymous) @ tryit_view.php?x=0.3774193121824916:8
                  dispatch @ jquery.min.js:2
                  y.handle @ jquery.min.js:2

                  RussR 1 Reply Last reply Reply Quote 0
                  • RussR
                    Russ @Insaneoctane
                    last edited by

                    @insaneoctane, I see the same thing in the developers console, but it does actually run Notepad with Donald Duck as the parameter if I give it an actual bookmark token.

                    Did you try that?

                    Russell VanderMey

                    I 1 Reply Last reply Reply Quote 0
                    • I
                      Insaneoctane @Russ
                      last edited by

                      @russ,
                      I did try it after you asked 😉 and yes, it working even though there are CORS errors in the console. Once I saw those, I quit troubleshooting, but it appears it is working. Thanks again for your efforts and a great app!

                      1 Reply Last reply Reply Quote 0
                      • B
                        BugTrapper
                        last edited by

                        @russ

                        Can I add more than one parameter and, if yes, how is the syntax ?

                        RussR 1 Reply Last reply Reply Quote 0
                        • RussR
                          Russ @BugTrapper
                          last edited by

                          @bugtrapper, you should be able to pass multiple parameters by putting a space between them, or a %20 between them, like this:

                          https://www.triggercmd.com/trigger/bookmark?token=bookmarktoken&params=foo bar
                          

                          or

                          https://www.triggercmd.com/trigger/bookmark?token=bookmarktoken&params=foo&20bar
                          

                          Russell VanderMey

                          1 Reply Last reply Reply Quote 0
                          • B
                            BugTrapper
                            last edited by

                            Thank you 🙂

                            1 Reply Last reply Reply Quote 0
                            • First post
                              Last post