David T
David T

Reputation: 25

Sending named variables to SOAP via New-WebServiceProxy in Powershell

Please forgive any errors in terminology, I am self taught :)

I am using New-WebServiceProxy to interact with a SOAP API.

Everything works when variables are at a single level, as long as they are entered in the correct order they are parsed correctly. However I can't work out how to enter 2nd level variables.

For example once the web service proxy has been set up as $Forms via the WSDL the following SOAP call

<x:Body>
    <pri:AddForm>
        <pri:apiToken>12345</pri:apiToken>
        <pri:FormTemplateID>xyz</pri:FormTemplateID>
        <pri:OrganisationID>A1</pri:OrganisationID>
    </pri:AddForm>
</x:Body>

Will work as $Forms.AddForm(1234, xyz, A1)

However if some of the variables are within a subheading such as

<x:Body>
    <pri:AddForm>
        <pri:apiToken>12345</pri:apiToken>
        <pri:formRequest>
            <pri:FormTemplateID>xyz</pri:FormTemplateID>
            <pri:OrganisationID>A1</pri:OrganisationID>
        </pri:formRequest>
        </pri:AddForm>
</x:Body>

The same command won't work and presents an error "Cannot find an overload for "AddForm" and the argument count: "3".

Is there a way to structure the command so it will recognise the arguments within the subheading?

Upvotes: 1

Views: 341

Answers (1)

David T
David T

Reputation: 25

After a lot of trial and error I've found the following works

$formRequest = [PSCustomObject] @{
    FormTemplateID = "xyz"
    OrganisationID = "A1"
}

$FVForms.AddForm($apiToken, $FormRequest)

Upvotes: 0

Related Questions