Question

How to index into an array of integers in a placeholder expression

  • 3 November 2022
  • 1 reply
  • 64 views

Badge

I feel like such a noob asking this question… but…

I’m building an automator.

I’ve done an API GET agent details

I’ve parsed that in a parser node: P5.

I’m seeking to pull out the agent groups that the agent is a member of, specifically just the first one.  I can do this by configuring the json parser to return a scalar integer for member_of instead of returning an array of integers - but this feels brittle to me.  The moment that someone regenerates that parser node, it will break.

I want to access the first element of the array of integers in a placeholder expression, but for the life of me, I can’t figure out the right syntax, and half an hour of googling has brought me no closer to a resolution.

This place holder:

{{P5.root.agent.member_of.member_of_number}}

...returns an array of integers which is the agent groups for the agent I'm GETting.  I’ve tried the following placeholder variations, and they all return nulls:

{{P5.root.agent.member_of[0]}}

{{P5.root.agent.member_of.member_of_number[0]}}

 

For the love of god, what am I doing wrong??  How do I index into this array?

 

(PS, for those of you laughing at my API/Freshservice noobness, I’m a killer TSQL developer… so a bit out of my comfort zone!)

 

 


1 reply

Userlevel 7
Badge +11

Hello, 

I normally use JSON expression in the parser node but you are right it will be overwritten if you accidentally auto generate the parser node it’s gone. You could add something in the node name saying not to do it or the specific change you did. 

But you could use the expression node or split – Liquid template language (shopify.github.io)

first – Liquid template language (shopify.github.io) and remove – Liquid template language (shopify.github.io) to remove any unwanted characters. 

 


 

Reply