API calls within Actions.
I am making an API call within an Action , but need to attach an HTTP only cookie . I tried passing in the cookie through a input passing in { { cookies .acces _token } } and have tried through javascript selection as well , but the DOM seems to be blocking it or something . Either way it seems that my header in the API call is a string literal "Bearer { { cookies .access token } } " instead of the access token . I have 2 ideas on how to solve it , the first is asking here as it could be a backend Nordcraft setup that I just dont know . The second is a callback from the action so when a button is pressed it triggers a workflow or action outside of the action i am in . . . is this possible ? If yes , where can I learn about it or can someone explain how I can access something outside of the action ? The http only cookie can only be read server side so you would need to make sure you proxy the request (in the advanced settings of the API ) . That will use the Nordcraft proxy that finds the { { cookies .access _token } } and replaces it with the actual cookie value . If you need to pass the http only cookie in the body of the request you also want to check the "Inject cookies in body " in the Advanced settings of the API . You cannot access formulas and actions from within your javascript within a custom action . To use the Nordcraft proxy I would suggest still creating an API . If you need to pass information into the API from your custom js you could make use of Events ( https://docs.nordcraft.com/actions/working-with-actions#set-up-events ) . That way when you call your action you can setup a workflow once the action triggers that event and in that workflow you would call the API using the nordcraft trigger rather than javascript . If you need custom code to run after the api call you can use the events "On success " , "On error " or "On message " events in the api panel to trigger you custom action . Thanks for the clarification ! I understand generally how to use actions . In this particular case I have a complex piece of javascript generating visuals including a button . However when that button is pressed I need to send data back to my database . To make the call securely I need to attach the access token cookie into the Bearer auth . When using my admin secret without that cookie , the call completed just fine , but making it securely has now broken the complex action element . I know actions are probably not to be used to create visuals , however making something like an operational calendar is just too complex a piece to quickly get done for the prototype with a client . So , I am wondering how to get this button to either make a callback to the API or trigger the workflow so I can possibly accomplish this without having to recreate it all . Example of what I mean . This is not the component I am working on , but it is effectively the same . This entire calendar view is generated by Javascript . Obviously not the intention of an Action ( I assume ) . When I click the button , I am able to make calls to my backend , and "reserve " my spot . However , that is using my admin -secret totally exposed . So doing this the right way using Bearer Auth , works outside of the action ( I have that working across my app ) , it just breaks on this button . I tried passing in the access _token cookie as an input , but as we discussed . . . no luck . I would like to avoid having to create an entire booking calendar component within the editor and then map stuff to the Calendar view , especially in the age of LLMs that can assist with that to speed it up . If there is a way to get that access _token attached within the call that works with the admin secret , that would be awesome . However , if the button can trigger a workflow instead that uses the API call , I am fine with that too . . . I am just not seeing in the documentation how to trigger a workflow from an action (and maybe that is just not possible ) . I havent actually tried manipulating DOM from the custom action like that but if you create your button in there and attach a click event to that maybe you would be able to trigger a Nordcraft event from within that click event ? So if you add an event in the left panel to the action called buttonClick something like this might work ? buttonRef.addEventListener("click", function() {
ctx.triggerActionEvent("buttonClick", data)
});Then whereever you trigger the actual custom event you would see the "buttonClick " callback you can open up and trigger your API @Kedde THANK YOU ! Saving me here ! !

.jpeg/public)