I am simply looking to pull the Auth token then use it to inject a record into an active Event Entry Journey. I think the issue is with the HTTPPost2 section.

Other information:

  • The DE linked to the journey has all the fields in the @journeyBody variable, only the Contact_Key is NOT NULLABLE while the rest are.
  • Date fields are date data type, Mobile is phone data type while the rest are Text.
  • I am attempting to run this AMPscript in a Cloudpage.
  • When I comment out the HTTPPost2 section I am able to view the token and the journeyBody variable.

Here is my code:

        SET @body = '{"client_id": "zzzzzzzzzzzzzzzzzzzzzzzzy","client_secret": "yyyyyyyyyyyyyyyyyyyyyyyyyyy", "grant_type": "client_credentials"}'
        SET @accessToken = HTTPPost2("https://QQQQQQQQQQQQQQQQQ.auth.marketingcloudapis.com/v2/token", "application/json", @body, True, @callstatus, @response)
        SET @PullaccessToken = REGEXMATCH(@callstatus,'^(?:.*"access_token":")(.*?)(?:".*)$',1)
    SET @journeyBody = '{
            "ContactKey": "003QQQQQQQQQQQQ",
            "EventDefinitionKey": "APIEvent-SSSSSSSSSSSSSSSSSSSSSSSSSSS",
            "EstablishContactKey": true,
            "Data": { "Contact_Key":"003QQQQQQQQQQQQ", 
                      "MessageText":"[SFMC] Hi there friend, here is your booking information: 2PM 23 Nov 2022. I hope you can attend.", 
        SET @bearerAccess_token = CONCAT('Bearer ', @PullaccessToken)
         set @postrequest = HTTPPost2("https://QQQQQQQQQQQQQQQQQ.rest.marketingcloudapis.com/interaction/v1/events", 'application/json', @journeyBody, True, @PullaccessToken)
        access_token: %%=v(@PullaccessToken)=%% 
        BODY: %%=v(@journeyBody)=%% 
  • 1
    Why are you using AMPscript for that? It’s much easier done in SSJS: sfmarketing.cloud/2020/04/07/…
    – zuzannamj
    Commented Apr 20, 2022 at 9:00
  • You didnt add the header name 'Authorization' as a parameter in the second HttpPost2, according to the documentation in developer.salesforce.com/docs/marketing/marketing-cloud/guide/…
    – SebOB
    Commented Apr 20, 2022 at 12:36
  • Hi guys Thanks for showing interest in my post! zuzannamj, I am planning on testing this ampscript in an SMS message. From my understanding, SSJS wont work in an SMS message? @SebOB, thanks! I took your advice and it now works :D
    – Weenus23
    Commented Apr 21, 2022 at 2:00

1 Answer 1


Changing the HTTPPost2 to this has it working:

 set @postrequest = HTTPPost2("https://QQQQQQQQQQQQQQQQQ.rest.marketingcloudapis.com/interaction/v1/events", 'application/json', @journeyBody, True, @output,@respheader, "Authorization", @bearerAccess_token)

You must log in to answer this question.

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