1

I have seen a few posts about how this can be done using oauth, but I need to use basic auth and I can't seem to get it to work. Below is an example of the code I'm using.

<script type="javascript" runat="server">

Platform.Load("core", "1.1.5");

var url = 'https://example.com/';
var contentType = 'application/json';
var header = 'auth=("username", "password")';

var payload = '{';
payload += ' "body":"This is a comment"';
payload += '}';

var result = HTTP.Post(url, contentType, payload, header);

</script>

1 Answer 1

4

You need to base64 encode your username and password like this:

var user = 'foo';
var password = 'bar';
var auth = 'Basic ' + Platform.Function.Base64Encode(user+':'+password);
var header = 'Authorization: ' + auth;

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .