0

I've been successfully using PHP and SoapClient to pass requests to a third party API using array. By dumping out the request from SoapClient what the XML data that is being passed to the API.

Now I've come across a required XML structure for <extendedData> that I'm having trouble passing as an array;

<TypeID>int</TypeID>
<FooID>int</FooID>
<BarID>int</BarID>
<extendedData>
    <Service_CreateFields>
        <FieldName>my string 1</FieldName>
        <FieldValue>my string 2</FieldValue>
        <Comments>my string 3</Comments>
    </Service_CreateFields>
    <Service_CreateFields>
        <FieldName>my string 4</FieldName>
        <FieldValue>my string 5</FieldValue>
        <Comments>my string 6</Comments>
    </Service_CreateFields>
</extendedData>

I've tried the following array but it fails to generate an XML request with two or more <Service_CreateFields>

$data = array(
    "TypeID" => "11",
    "FooID" => "22",
    "BarID" => "33",
    "extendedData" => array(
        "Service_CreateFields" => array(
                "FieldName" => "my string 1",
                "FieldValue" => "my string 2",
                "Comments" => "my string 3",
            ),
            "Service_CreateFields" => array(
                "FieldName" => "my string 4",
                "FieldValue" => "my string 5",
                "Comments" => "my string 6",
            ),
    ),
);

Has anyone had experience with this?

1
  • use foreach loop for extendedData which will have xml tags as Service_CreateFields it would generate the xml with child for you Commented Jan 11, 2017 at 11:45

1 Answer 1

2

Try wrapping each child in it's own array:

$data = array(
    "TypeID" => "11",
    "FooID" => "22",
    "BarID" => "33",
    "extendedData" => array(
        "Service_CreateFields" => array(
            array(
                "FieldName" => "my string 1",
                "FieldValue" => "my string 2",
                "Comments" => "my string 3",
            ),
            array(
                "FieldName" => "my string 4",
                "FieldValue" => "my string 5",
                "Comments" => "my string 6",
            )
        )
    )
);
Sign up to request clarification or add additional context in comments.

1 Comment

Yes, this array structure worked just fine! Many thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.