Search code examples
javascriptjquerymagentomagento-soap-api

Access Magento SOAP API via JavaScript: What am i doing wrong?


i'm currently trying to access the SOAP API of a my magento store with no success. i have created a soap user and role in backend and tested them via xmlrpc login. Same-Origin-Policy is not an issue. i get the wsdl via the url myshop.com/api/?wsdl

i have tried jquery soap client:

$.soap({
    url: 'http://my-shop.de/api/',
    method: 'login',
    data: {
        username:'soap_username',
        apiKey:'soap_userpass'
    },

    success: function (soapResponse) {
        alert("yes!!");
    },
    error: function (SOAPResponse) {
        alert(SOAPResponse.toString());

    }

})

returning a 404 and i can't figure out why.

in addition i have tried javascript soap client:

var url = 'http://myshop.de/api/';
var pl = new SOAPClientParameters();
pl.add("username", 'soap_username');
pl.add("apiKey", 'soap_userpass');

SOAPClient.invoke(url, "login", pl, true, HelloTo_callBack);

function HelloTo_callBack(r) {
    alert(r.toString());
};

returning a 500 internal server error. again, i have no clue what is going wrong here. can anyone give me a hint about what i am missing?

any help or hint appreciated, thanks!


Solution

  • Ok found the problem! it was the maintenance mode. Even my ip was whitelisted and i could browse the store and backend normally, somehow the soap api calls got messed up. So working code for me is:

    $.soap({
        url: 'http://my-shop.de/api/?wsdl',
        method: 'login',
        data: {
            username:'soap_username',
            apiKey:'soap_userpass'
        },
    
        success: function (soapResponse) {
            alert("yes!!");
        },
        error: function (SOAPResponse) {
            alert(SOAPResponse.toString());
    
        }
    
    })
    

    (note changed URL)