Azure API Management policy for loop not working on array

In Azure API Management I have a SOAP to REST api with the wsdl imported. I am able to send requests through however the liquid template in the set-body which creates the XML request from JSON is not able to read an array in the JSON.

Liquid Template:

<set-body template="liquid">
            <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://tempuri.org/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
                <soap:Body>
                    <testEndpointName>
                        <request>
                            <Attachments>
                                {% for item in body.testEndpointName.request.attachments %}
                                <testEndpointNameAttachment>
                                    {% if item.fileBytes %}
                                    <FileBytes>{{item.fileBytes}}</FileBytes>
                                    {% else %}
                                    <FileBytes xsi:nil="true" />
                                    {% endif %}
                                    {% if item.fileName %}
                                    <FileName>{{item.fileName}}</FileName>
                                    {% else %}
                                    <FileName xsi:nil="true" />
                                    {% endif %}
                                    {% if item.fileSize %}
                                    <FileSize >{{item.fileSize}}</FileSize>
                                    {% else %}
                                    <FileSize xsi:nil="true" />
                                    {% endif %}
                                </testEndpointNameAttachment>
                                {% endfor %}
                            </Attachments>
                            {% if body.testEndpointName.request.email %}
                            <Email>{{body.testEndpointName.request.email}}</Email>
                            {% else %}
                            <Email xsi:nil="true" />
                            {% endif %}
                            {% if body.testEndpointName.request.emailBody %}
                            <EmailBody">{{body.testEndpointName.request.emailBody}}</EmailBody>
                            {% else %}
                            <EmailBody xsi:nil="true" />
                            {% endif %}
                            {% if body.testEndpointName.request.policyNumber %}
                            <PolicyNumber>{{body.testEndpointName.request.policyNumber}}</PolicyNumber>
                            {% else %}
                            <PolicyNumberxsi:nil="true" />
                            {% endif %}
                            {% if body.testEndpointName.request.subject %}
                            <Subject>{{body.testEndpointName.request.subject}}</Subject>
                            {% else %}
                            <Subject xsi:nil="true" />
                            {% endif %}
                        </request>
                    </testEndpointName>
                </soap:Body>
            </soap:Envelope>
        </set-body>

Example Input:

{
    "testEndpointName": {
        "request": {
            "attachments": [
                {
                    "fileBytes": "fakebytes",
                    "fileName": "fakename.txt",
                    "fileSize": "1234"
                }
            ],
            "email": "[email protected]",
            "emailBody": "test email body",
            "policyNumber": "1234",
            "subject": "test subject"
        }
    }
}

This gets me a request which looks like the following:

<soapenv:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://tempuri.org/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soapenv:Body>
      <testEndpointName>
         <request>
            <Attachments></Attachments>
            <Email>[email protected]</Email>
            <EmailBody>test email body</EmailBody>
            <PolicyNumber>1234</PolicyNumber>
            <Subject>test subject</Subject>
         </request>
      </testEndpointName>
   </soapenv:Body>
</soapenv:Envelope>

The Attachments section is always empty. I have tried replacing for with JSONArrayFor and also made sure that the header Content-Type is always set to application/json. I also tried hard coding values inside the for loop to see if it ever got in there and it did not.

Any help would be appreciated.

4

Before doing the liquid-transformation, it has to be ensured that the Content-Type is set to application/json, like the input data.
This can also be done in the request itself, but to be on the safe side, it can be set in the policy.

The response Content-Type application/xml has to be set after the transformation.

Policy:

<set-header name="Content-Type" exists-action="override">
    <value>application/json</value>
</set-header>
<set-body template="liquid">
    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://tempuri.org/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <soap:Body>
            <testEndpointName>
                <request>
                    <Attachments>
                                {% for item in body.testEndpointName.request.attachments %}
                                <testEndpointNameAttachment>
                                    {% if item.fileBytes %}
                                    <FileBytes>{{item.fileBytes}}</FileBytes>
                                    {% else %}
                                    <FileBytes xsi:nil="true" />
                                    {% endif %}
                                    {% if item.fileName %}
                                    <FileName>{{item.fileName}}</FileName>
                                    {% else %}
                                    <FileName xsi:nil="true" />
                                    {% endif %}
                                    {% if item.fileSize %}
                                    <FileSize>{{item.fileSize}}</FileSize>
                                    {% else %}
                                    <FileSize xsi:nil="true" />
                                    {% endif %}
                                </testEndpointNameAttachment>
                                {% endfor %}
                    </Attachments>
                </request>
            </testEndpointName>
        </soap:Body>
    </soap:Envelope>
</set-body>
<set-header name="Content-Type" exists-action="override">
    <value>application/xml</value>
</set-header>

Test in APIM:

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật