Issue in geting URL from array in AJO journey | Community
Skip to main content
mohit_khare
Level 2
March 23, 2026
Solved

Issue in geting URL from array in AJO journey

  • March 23, 2026
  • 1 reply
  • 22 views

Hi All,

I am trying to create a journey where i pull data from an API end poing using AJO custom actions. and there is a filed in the response called as id. the id is stored in an array like this: 


{
    "data": {
        "multiContextList": {
            "items": [
                {
                    "DisplayDate": "dateOnly",
                    "publisheddate": "dateTime",
                    "pageUrl": "string",
                    "_id": "string"

                }
            ]
        }
    }
}

I want to use this ID to create a URL in the AJO journey email  like this: https://domain/_ID.
But when i pull the data suing the action all the fields can  be printed in the email body using the script:

{{#each context.journey.actions.413214ba-8a6c-4564-8a97-88585292066e.data.multiContextList.items as |items|}}{%#if @index = 0%}{{items._id}}{%/if%}{{/each}}

but its not getting populated in the URL part of the email. It shows an error in the journey: Invalid value for the parameter originalUrl found at Position(274,1152) in url helper. (CJMTL - 010030-422).

Also, I am also not able to create a variable in the HTML script using the same code.

{% let authURL = concat("https://my-url/",{{#each context.journey.actions.413214ba-8a6c-4564-8a97-88585292066e.data.multiContextList.items as |items|}}{%#if @index = 0%}{{items._id}}{%/if%}{{/each}}) %} 

It gives an error: Invalid syntax found: '{%/', expected: 'EOF'. Error beginning at position: Line 253, Character 207.

Also if I use the attribute in URL parameter like this: 
https://my-url/{{context.journey.actions.413214ba-8a6c-4564-8a97-88585292066e.data.multiContextList.items.0._id}} or https://my-url/{{context.journey.actions.413214ba-8a6c-4564-8a97-88585292066e.data.multiContextList.items.[0]._id}} it thrown an error: context.journey.actions.413214ba-8a6c-4564-8a97-88585292066e.data.multiContextList.items.0._id not found. Error beginning at position: Line 1, Character 45.

I cant use head function as I not only have to get the 0th value but all the _id values at all locations.

BTW if i use the code: {{#each context.journey.actions.413214ba-8a6c-4564-8a97-88585292066e.data.multiContextList.items as |items|}}{%#if @index = 0%}{{items._id}}{%/if%}{{/each}} or {{#each context.journey.actions.413214ba-8a6c-4564-8a97-88585292066e.data.multiContextList.items as |items|}}{%#if @index = 1%}{{items._id}}{%/if%}{{/each}} and so on, i see the respective values.

Has someone faced this kind of issue. Any help would be appreciated.

 

Thanks,
Mohit

    Best answer by IamCGK

    Hey ​@mohit_khare 

    If you’re looking to use the items’ _id field as a string for the url within the each loop itself, then I’d suggest you to store the value of the _id and then re-use it within the each loop itself and repeat that process for consecutive items.

    For example,

    {{#each context.journey.actions.413214ba-8a6c-4564-8a9788585292066e.data.multiContextList.items as |items|}}

    {% let id = items._id %}
    <a href="https://www.example.com/{{{id}}}">Click Here </a>
    {{!or}}
    {{url originalUrl='https://www.example.com/{{{id}}}' type='TRACKED'}}

    {{/each}}


    Or If you only want to use the first index value then you can refer below

    {{#each context.journey.actions.413214ba-8a6c-4564-8a9788585292066e.data.multiContextList.items as |items|}}

    {%#if @index=0 %}
    {% let id = items._id %}
    <a href="https://www.example.com/{{{id}}}">Click Here </a>
    {%/if%}

    {{/each}}

    In case your use case requires you to define links outside the each loop, then I’d suggest you to store every _id values in separate variables and re-use them outside the loop. This method, albeit redundant, would enable your use-case. 

    And also I’m afraid it’s not possible to store the contextual attribute like you’ve mentioned -- Since it involves storing each loop itself. You can either store contextual attribute via “with” helper function or loop through it.

    {% let authURL = concat("https://my-url/",{{#each context.journey.actions.413214ba-8a6c-4564-8a97-88585292066e.data.multiContextList.items as |items|}}{%#if @index = 0%}{{items._id}}{%/if%}{{/each}}) %} 


    Refer this below thread for more details on url helper function



    I hope this helps!


    Cheers,
    Ganesh Kumar C

    1 reply

    IamCGKAccepted solution
    Level 2
    March 23, 2026

    Hey ​@mohit_khare 

    If you’re looking to use the items’ _id field as a string for the url within the each loop itself, then I’d suggest you to store the value of the _id and then re-use it within the each loop itself and repeat that process for consecutive items.

    For example,

    {{#each context.journey.actions.413214ba-8a6c-4564-8a9788585292066e.data.multiContextList.items as |items|}}

    {% let id = items._id %}
    <a href="https://www.example.com/{{{id}}}">Click Here </a>
    {{!or}}
    {{url originalUrl='https://www.example.com/{{{id}}}' type='TRACKED'}}

    {{/each}}


    Or If you only want to use the first index value then you can refer below

    {{#each context.journey.actions.413214ba-8a6c-4564-8a9788585292066e.data.multiContextList.items as |items|}}

    {%#if @index=0 %}
    {% let id = items._id %}
    <a href="https://www.example.com/{{{id}}}">Click Here </a>
    {%/if%}

    {{/each}}

    In case your use case requires you to define links outside the each loop, then I’d suggest you to store every _id values in separate variables and re-use them outside the loop. This method, albeit redundant, would enable your use-case. 

    And also I’m afraid it’s not possible to store the contextual attribute like you’ve mentioned -- Since it involves storing each loop itself. You can either store contextual attribute via “with” helper function or loop through it.

    {% let authURL = concat("https://my-url/",{{#each context.journey.actions.413214ba-8a6c-4564-8a97-88585292066e.data.multiContextList.items as |items|}}{%#if @index = 0%}{{items._id}}{%/if%}{{/each}}) %} 


    Refer this below thread for more details on url helper function



    I hope this helps!


    Cheers,
    Ganesh Kumar C

    mohit_khare
    Level 2
    March 23, 2026

    Hi ​@IamCGK,

    It really did work. I was able to form the URL using the code not only for the 0th position but any position we need.

    Thanks for your quick help here.

    I will test it with few other payloads and will get back in case of any issues.

    Thanks one again.😀

    Level 2
    March 23, 2026

    Glad to know it helped! You’re welcome!!