Base 64 encode username:password for basic auth

Does anyone know how to base64 encode a username:password in rest api call in appgyver? basically need to duplicate this:

jQuery.ajax({ url: 'http://wordpressmu-19393-42425-140587.cloudwaysapps.com/wp-json/wp/v2/posts/50', method: 'DELETE', crossDomain: true, beforeSend: function ( xhr ) { xhr.setRequestHeader( 'Authorization', 'Basic ' + Base64.encode( 'username:password' ) );

1 Like

Hi, there’s a ENCODE_BASE64 formula function that you could use.

I saw that, but could not find a way to use formulas in the rest api connector field where we create the headers and parameters for rest api calls. Am I missing something?

Have you ever used it? I tried creating a string variable from username and password inputs in a login form with this and it is not returning anything an all.

ENCODE_BASE64(“appVars.userName” + “:” + “appVars.password”)

I also tried:

ENCODE_BASE64(appVars.userName + “:” + appVars.password)

Hi, if I first create a resource with non-static header “Authorization”

Then on “Test” tab bind that to a formula that uses ENCODE_BASE64

This is what I get in the request:

You get the same result when binding the formula to the Authorization field in a flow function node. Maybe still make sure that the variables you are using in the formula are actually populated and not empty, if they were not working previously. :slight_smile:

Adding here that it’s a known issue that the ENCODE_BASE64 formula is not working on mobile, you can follow this ticket for a fix:

thank you very much. I will try it to at least get it working on web.

I wonder if there is an api which i could call to return a base64 string on mobile until the bug is fixed? I will look and see. Thank you.

There’s a possible workaround with the JS node mentioned in this topic: