I'm not sure why you would want to make an HTTP.POST call to the SOAP API to achieve this.
If you use the platform API functions available in SSJS (or AMPscript), that will take care of authentication and also resolve the correct Web Service endpoint.
Here's how you would create a Sendable DE using platform API functions in SSJS:
<script runat="server">
Platform.Load("Core","1");
var de = Platform.Function.CreateObject("DataExtension");
Platform.Function.SetObjectProperty(de, "Name", "My Sendable DE");
Platform.Function.SetObjectProperty(de, "Description", "A DE created via SSJS");
Platform.Function.SetObjectProperty(de, "IsSendable", "true");
Platform.Function.SetObjectProperty(de, "IsTestable", "false");
var deFields = Platform.Function.CreateObject("DataExtensionField");
Platform.Function.SetObjectProperty(deFields, "FieldType", "Text");
Platform.Function.SetObjectProperty(deFields, "Name", "Id");
Platform.Function.SetObjectProperty(deFields, "MaxLength", 18);
Platform.Function.SetObjectProperty(deFields, "IsPrimaryKey", "true");
Platform.Function.SetObjectProperty(deFields, "IsNillable", "false");
Platform.Function.SetObjectProperty(deFields, "IsRequired", "true");
Platform.Function.AddObjectArrayItem(de, "Fields", deFields);
Platform.Function.SetObjectProperty(de,"SendableDataExtensionField",deFields)
var deFields = Platform.Function.CreateObject("DataExtensionField");
Platform.Function.SetObjectProperty(deFields, "FieldType", "Text");
Platform.Function.SetObjectProperty(deFields, "Name", "Name");
Platform.Function.SetObjectProperty(deFields, "MaxLength", 50);
Platform.Function.AddObjectArrayItem(de, "Fields", deFields);
var deFields = Platform.Function.CreateObject("DataExtensionField");
Platform.Function.SetObjectProperty(deFields, "FieldType", "EmailAddress");
Platform.Function.SetObjectProperty(deFields, "Name", "Email Address");
Platform.Function.SetObjectProperty(deFields, "IsNillable", "false");
Platform.Function.SetObjectProperty(deFields, "IsRequired", "true");
Platform.Function.AddObjectArrayItem(de, "Fields", deFields);
var subscriberAttr = Platform.Function.CreateObject("Attribute");
Platform.Function.SetObjectProperty(subscriberAttr, "Name", "Subscriber Key");
Platform.Function.SetObjectProperty(subscriberAttr, "Value", "Id");
Platform.Function.SetObjectProperty(de, "SendableSubscriberField", subscriberAttr);
var statusAndRequestID = [0,0];
var statMsg = Platform.Function.InvokeCreate(de, StatusAndRequestID, null);
Platform.Response.Write('status message: ' + statMsg);
</script>
In the above example, I've created the Subscriber relationship based on Subscriber Key = the Id field in my DE. However you could change this relationship to be based on email address by changing the following lines:
Platform.Function.SetObjectProperty(subscriberAttr, "Name", "Subscriber Key");
Platform.Function.SetObjectProperty(subscriberAttr, "Value", "Id");
To:
Platform.Function.SetObjectProperty(subscriberAttr, "Name", "Email Address");
Platform.Function.SetObjectProperty(subscriberAttr, "Value", "Email Address");
Your header names and values need to be an array. See below example as per documentation
var url = 'http://www.example.com';
var headerNames = ["MyTestHeader1", "MyTestHeader2"];
var headerValues = ["MyTestValue1", "MyTestValue2"];
var response = HTTP.Get(url, headerNames, headerValues);
Also note Lucas' comment re space between bearer and token. In addition to this, to concatenate strings in javascript use +
as such:
var headerValues = ["Bearer " + apitoken];
The above joins the string "Bearer " with the value of the apiToken
variable and sets as first item in an array (indicated by the square brackets) which is assigned to the variable headerValues
.
Best Answer
find below a valid call from the SFMC POSTman Collection found here: https://github.com/salesforce-marketingcloud/postman
The SubscriberKey field in the valid example contains the SAME value as ContactKey, which means: try to to align both fields in your call, where the IDs seem to differ. This inconsistency should be causing the "Bad Request".
If this alone doesn't help, try aligning more closely with the example, i.e. call the field "SubscriberKey" in your DE and try to include the Email as well as all other mandatory fields in the payload (if it is in your Entry Source DE of course).