Problem with connecting to Opensearch with Basic Auth


I'm trying to connect to our Opensearch db via (the new) Basic Auth option. I can access via Basic Auth from Postman with this username/password to this host without any problems. But on Retool (Test Connection) I get the following error:

statusCode: 422
error: "Unprocessable Entity"
message: "First argument must be a number (400+): 200"
data: null

Has anyone experienced the same problem and found a solution maybe?


Hi @rroukens,

Welcome to the community!

The error message "Unprocessable Entity" indicates that the request is well-formed but cannot be processed because of semantic errors. In this case, the semantic error is that the first argument to the Basic Auth request must be a number, but Retool is passing the string "200" as the first argument.

You can try a workaround to connect to OpenSearch using Basic Auth by using a JavaScript block to manually construct the Basic Auth header and add it to the request.

The following JavaScript code can be used to construct the Basic Auth header:

function constructBasicAuthHeader(username, password) {
  const encodedCredentials = btoa(`${username}:${password}`);
  return `Basic ${encodedCredentials}`;

To use the constructBasicAuthHeader() function to connect to OpenSearch using Basic Auth, you can add a JavaScript block to your Retool Workflow and add the following code:

const basicAuthHeader = constructBasicAuthHeader('YOUR_USERNAME', 'YOUR_PASSWORD');

// Add the Basic Auth header to the request.
workflow.setRequestHeader('Authorization', basicAuthHeader);

// Send the request.
const response = workflow.callApi('https://YOUR_OPENSEARCH_ENDPOINT');

Replace YOUR_USERNAME and YOUR_PASSWORD with the username and password for your OpenSearch account. Replace YOUR_OPENSEARCH_ENDPOINT with the endpoint for your OpenSearch cluster.

Once you have added the JavaScript block to your Retool Workflow, you can connect it to the other blocks in your workflow and run the workflow. Retool will send the request with the Basic Auth header, and you should be able to connect to OpenSearch.

I hope this helps!



Hi Patrick,

Thank you very much for your quick and elaborate answer. I can try this, although I never worked with workflows before. We currently only build apps and use resources to interact with data sources. Can I use a workflow as a resource as well? With this workaround I also lose all 'elasticaearch' related functionality in the resources definition, right? To pass queries for example? So, I will be rebuilding the elastic resource functionality of Retool with a workflow?

So, I can only see this solution as a workaround as you mention. Because what you describe is, I think, the normal logic that needs to be done to transform a username/password combination to do basic authentication. What you describe is in my opinion basis authentication. When I select the option 'Basic Auth' from the authentication options, I expect this to happen 'under the hood'.

That's exactly why I mentioned Postman as a reference. I'll attach screenshots of the Postman authentication interface and Retool's interface. The similarity is quite obvious I think. Postman works (read: does the transformation you described for me) and Retool doesn't.

So, should this be passed on to some development team? How does that work?


Ok, after some playing with workflows and some out-of-the-box thinking, I just changed my opensearch resource from an 'Elasticsearch' type resource to a normal REST API resource and Basic Auth works perfect in that one :rofl:. So, that will be my solution.

1 Like

Great to hear! Thank you for the feedback!