최근 검색


최근 검색 없음

Formatting of " " when using Liquid markup on Api request



2024년 1월 25일에 게시됨

Having an issue when trying to format Liquid on a request.

When creating or updating a ticket via Api request i am using this format:

{
"ticket":{
"requester_id" : "{{ticket.requester.id}}", 
"collaborator_ids": ["{% if ticket.cc_names != empty %}{% capture ccedusers %}{% for cc in ticket.ccs %}{% unless forloop.last %}{{ cc.id | append: ', ' }}{% else %}{{ cc.id }}{% endunless %}{% endfor %}{% endcapture %}{{ ccedusers | strip_newlines }}{% else %}{% endif %}"]
}

When recovering requester_id the " " would not affect the syntax but for collaborator_ids need to be inside [ ]. When using liquid, the values are recovered properly but they require to be inside  " " for the request to be correct.

Depending on where " " are placed the request would be successful but the " " will always interfere on the format and not recover the cc values.

they can be recovered as:

 "collaborator_ids": "[12345678910, 12345678911]"

or as:

 "collaborator_ids": ["12345678910, 12345678911"]

but none seem to work to add the users... ideally, the first sample would ignore the " "  just as requester_id does, but cannot make it work.

Any suggestion would be greatly appreciated. 

Thank you! 


0

1

댓글 1개

      It seems like you're trying to format the collaborator_ids as an array of integers in your JSON payload, but you're running into issues with the quotation marks and the way Liquid is outputting the values. I would recommend to try with the JSON format for an array of integers like this:

      "collaborator_ids": [12345678910, 12345678911]

      However, Liquid is templating the values as a string, which is why you're getting the entire list within quotes. To ensure that the collaborator_ids are sent as an array of integers, you need to modify your Liquid code to output the IDs without enclosing them in a string.

      Here's a Liquid template that should output the correct format (to the best of my limited knowledge)

      {
        "ticket": {
          "requester_id": "{{ ticket.requester.id }}",
          "collaborator_ids": [
            {% if ticket.cc_names != empty %}
              {% for cc in ticket.ccs %}
                {{ cc.id }}{% unless forloop.last %},{% endunless %}
              {% endfor %}
            {% endif %}
          ]
        }
      }


      This template will output the collaborator_ids as an array of integers without quotes around them. The {% unless forloop.last %},{% endunless %} part ensures that a comma is added between the IDs but not after the last one.

      0


      댓글을 남기려면 로그인하세요.

      원하는 정보를 못 찾으셨나요?

      새 게시물