YourMembership API-Session.Create =未知错误响应

时间:2019-03-01 20:33:47

标签: javascript ajax xml api response

我正在尝试创建对YourMembership的API的调用,特别是Session.Create方法。

function create_session(){
    var xml_create_session = '<?xml version="1.0" encoding="utf-8" ?>' +
    '<YourMembership>' +
    '<Version>' + ym_api_version + '</Version>' +
    '<ApiKey>' + ym_api_key + '</ApiKey>' +
    '<CallID>001</CallID>' +
    '<Call Method="Session.Create"></Call>' +
    '</YourMembership>';
    var xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function() {
        if (this.readyState == 4 && this.status == 200) {
            var session_id = xhttp.responseText.SessionID;
            authorize_token(session_id);
        }
    };
    xhttp.open("POST", api_url,true);
    xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xhttp.send(xml_create_session);  
}

当我将此请求提交给API时,我得到以下响应,其中包含API发送的错误以及提交给API的原始请求(注意:我已编辑了API密钥,这是正确的在响应中):

<?xml version="1.0" encoding="utf-8" ?>
<YourMembership_Response>
<ErrCode>999</ErrCode>
<ExtendedErrorInfo></ExtendedErrorInfo>
<ErrDesc>An unknown error has occured.</ErrDesc>
<XmlRequest>
<YourMembership>
<Version>2.02</Version>
<ApiKey>REDACTED</ApiKey>
<CallID>001</CallID>
<Call Method="Session.Create"></Call>
</YourMembership>
</XmlRequest>
</YourMembership_Response>

YourMembership在其文档中指出,API请求必须通过POST以XML文件的形式提交,并提供以下示例来调用其网站(https://api.yourmembership.com/reference/2_02/Session_Create.htm)上的Session.Create:

<?xml version="1.0" encoding="utf-8" ?>

<YourMembership>
    <Version>2.02</Version>
    <ApiKey>3D638C5F-CCE2-4638-A2C1-355FA7BBC917</ApiKey>
    <CallID>001</CallID>
    <Call Method="Session.Create"></Call>
</YourMembership>

这似乎是平台特有的问题,但是我的JS或理解如何构造XML文件发送到API的可能性也很大,因此任何指导都是非常感激!非常感谢!

0 个答案:

没有答案