Alteryx IO Discussions

Customize and extend the power of Alteryx with SDKs, APIs, custom tools, and more.

How to access the python backend code without starting Alteryx workflow?

scar101
5 - Atom

I’m developing a custom tool using the Alteryx Platform SDK and need some assistance. I’m trying to trigger a backend Python API call when a user clicks a button on the tool’s interface. The purpose of this API call is to retrieve data that will populate dropdowns on the interface.

I initially attempted to make this API call using the React framework, but I encountered CORS errors due to using React for the call. I’m now exploring whether there’s a way to handle this directly within the backend, possibly through a Python function triggered by the button click.

Has anyone faced a similar challenge, or could anyone provide guidance on how to properly trigger a Python API call to handle this within the Alteryx Platform SDK? Any code examples, tips, or documentation references would be greatly appreciated!


Thanks in advance for your help!

3 REPLIES 3
aneeshnazar
Alteryx
Alteryx

There isn't really a way to send information from the Python backend back to the frontend, unfortunately - it's intended to be a one-way, one-time connection, just for configuring the tool. However, you should be able to make that API call from the frontend - have you tried using Axios to make the HTTP request? We use it internally, so it might work for your use case as well:  https://axios-http.com/docs/api_intro  if not, could you post the error message? We might be able to help debug CORS errors

scar101
5 - Atom

Hi Aneesh,

Thanks for your response! We did try making the request with Axios, but we’re still encountering CORS errors. Here’s the specific error message we’re getting:

 

I believe the issue stems from the fact that the React frontend is hosted from a different domain than the API, causing the CORS policy to block the request.

 

Thanks for your help!

aneeshnazar
Alteryx
Alteryx

Ah, I see, that makes sense - OK, there's another option  We have a JsEvent called MakeWebRequest available in Designer - here's an example for how to use JsEvents: https://alteryx.github.io/react-comms/#/Utils/JsEvent

and that dictionary should just be standard HTTP config details - so something like:

const resp = await JsEvent('MakeWebRequest', {
    body: {
        uri: 'alteryx.com',
        method: 'GET',
        headers: {}
    }
});

definitely play around with it a little more, though, I'm not 100% certain if that 'body' tag is necessary