doedje / jquery.soap

This script uses $.ajax to send a SOAP:Envelope. It can take XML DOM, XML string or JSON as input and the response can be returned as either XML DOM, XML string or JSON too.
352 stars 148 forks source link

How to convert the following PHP SOAP call to work in your jquery.soap #137

Closed cj4j closed 11 months ago

cj4j commented 1 year ago

Hi,

I'm new to SOAP (and I have never used PHP), and I'm having trouble working out how I would rewrite the following PHP code to work with your jquery.soap plugin, if possible could you please point me in the right direction?

<?php
$api_key = "myAPIKey"; 
$loc="https://soap.somedomain.co.uk/edi/soapsr.pl";
$uri="https://soap.somedomain.co.uk/StockQuery";
$client = new SoapClient(null, array('location' => $loc,
                                     'uri'      => $uri,
                                     'compression' => "SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP | 5"
                                     ));
$stock_ids=array(1,6,15,16,167,169,170,171,172,173,175,176,5177,5178,5179,5180,5181);
$StkQtys = $client->stock_qty_array($api_key,$stock_ids);
echo var_dump($StkQtys);
unset($client);
exit;
?>

I'm not sure where I should put the '$loc' and '$uri' when using $.soap() Also, how should I structure the data: {} object to include the required information? I've tried the following, but no luck:

<script>
function soap() {
  $.soap({
        loc: 'https://soap.somedomain.co.uk/edi/soapsr.pl',
    url: 'https://soap.somedomain.co.uk/StockQuery',
        compression: 'SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP | 5'
    data: {
        stock_qty_array: { 'myAPIKey', {0:1,1:6,2:15,3:16,4:167,5:169,6:170,7:171,8:172,9:173,10:175,11:176,12:5177,13:5178,14:5179,15:5180,16:5181} }
    },
    success: function (soapResponse) {
                console.dir(soapResponse);
    },
    error: function (SOAPResponse) {
                console.dir(SOAPResponse);
    }
  });
}
</script>

Any advice would be appreciated. Thank you, Chris

doedje commented 1 year ago

It's hard for me to say how you should access your SOAP server without any documents of the API or example of a SOAPRequest that works. If you can pass me a URL to documentation, or you can toy around with SOAPUI to find a request that works, post that here. Than I can take a look.