I am trying to learn how to use the Journey Builder API to enter a record from a Cloud Page into a Journey. I am able to get my access token from the auth endpoint but when I make the API request to the Journey Builder API I get a 400 Bad Request error.
This attempt is super simple. The Data Extension has just 1 field, ContactKey. I've ensured that the Event Definition Key in the Journey matches what is in my code. Finally, the installed package has an API Integration Component that is of type Server-to-Server with scope of "journeys_read" and "list_and_subscribers_read"
Can someone please tell me what I am missing or doing wrong?
%%[
set @url = 'https://mySubdomainHere.auth.marketingcloudapis.com/v2/token'
set @content = 'application/json'
set @payload = '{
"grant_type": "client_credentials",
"client_id": "xxxxxxxxxxxx",
"client_secret": "yyyyyyyyyyyy"
}'
var @response, @callstatus
set @HTTP1 = HTTPPost2(@url, @content, @payload, true, @response, @callstatus)
]%%
<script runat="server" language="javascript">
var str = Platform.Variable.GetValue('@response');
var obj = Platform.Function.ParseJSON(str);
var accessToken = obj.access_token;
Platform.Variable.SetValue("@accessToken", accessToken);
</script>
%%[
set @accessToken = Concat('Bearer ', @accessToken)
set @url2 = 'https://mySubdomainHere.rest.marketingcloudapis.com/interaction/v1/events/'
set @content2 = 'application/json'
set @payload2 = '{
"ContactKey": "[email protected]",
"EventDefinitionKey": "APIEvent-yada-yada-yada",
"EstablishContactKey": true
}'
var @response2, @callstatus2
set @HTTP2 = HTTPPost2(@url2, @content2, @payload2, true, @callstatus2, @response2, 'Authorization', @accessToken)
]%%