Gemini Community Support Site

This Gemini community support site can be used to find solutions to product issues. You can log in using Open Id, Google Profile and even Facebook. Feel free to ask a question or browse FAQs and documentation. Product tour videos are also available along with how-to videos demonstrating key Gemini capabilities.




REST API: always getting 404

api

Just playing with REST API and not successfull.

  1. Checked this: http://community.geminiplatform.com/docs/all/page/21/enabling-api-support/?tags=api
  2. Used jQuery to get JSON: http://community.geminiplatform.com/docs/all/page/54/authentication/?tags=api
  3. Checked if Base64 and MD5 is correctly build: http://community.geminiplatform.com/questions/3577/how-to-authenticate-with-gemini-web-services-not-using-net/?tags=api

...and still getting 404. I guess 404 means there is some problem on the server side, but I don't know what to check where to start. Do you have a complete, functional REST example to try it?

stepand76
· 504
stepand76
Replies (9)
helpful
0
not helpful

These are for Gemini 4. Are you on Gemini 5? What exactly are you trying to do? Is it all using jQuery?


Mark Wing
· 9108
Mark Wing
helpful
0
not helpful

Bellow is my code. Off course the password is not correct.

    <html>
<head>
    <script type="text/javascript" src="jquery-1.8.3.min.js"></script>
</head>
<body>
<button id="rest">Rest!</button>
<script type="text/javascript">
    $('#rest').click(function(){
        var geminiUserNameToken = "YWRtaW4"; // Base64("admin")
        var geminiPasswordToken = "ISMvKXpXpadDiUoOSoAfww=="; // Base64(MD5("admin"))
        var geminiApiToken = "YWlna2YzZ250eQ=="; // Base64("aigkf3gnty")
        $.getJSON("http://gemini.reliance.cz/api/projects.ashx/projects?format=json&gemini-username-token=" + geminiUserNameToken + "&gemini-password-token=" + geminiPasswordToken + "&gemini-api-token=" + geminiApiToken,
            function(data) {
                alert(data);
            });
    });
</script>
</body>
</html>

stepand76
· 504
stepand76
helpful
0
not helpful

jsonp is currently not supported, you will need to set headers (basic authentication).


Mark Wing
· 9108
Mark Wing
helpful
0
not helpful

I think it's not JSONP.

See http://api.jquery.com/jQuery.getJSON/

JSONP If the URL includes the string "callback=?" (or similar, as defined by the server-side API), the request is treated as JSONP instead. See the discussion of the jsonp data type in $.ajax() for more details.

However my code is based on sample from your API documentation. Isn't it? So it should work. Do you have a working example of REST API? Thanks.


stepand76
· 504
stepand76
helpful
0
not helpful

Any news?


stepand76
· 504
stepand76
helpful
0
not helpful

We are working on a jQuery sample, which should be there next week. What you need to do is set the headers for the call (authorization)


Saar Cohen
· 5000
Saar Cohen
helpful
0
not helpful

Thank you for info. I will wait for the example you are working on.


stepand76
· 504
stepand76
helpful
0
not helpful
ANSWER

Below you will find a working example. Please make sure this code is run within Gemini.

$(document).ready(function () {
    var geminiUrl = "http://localhost/gemini/api/items/36";
    var geminiUsername = Base64.encode("manager:x3it3c53mm"); // user : apikey

    $.ajax({
        url: geminiUrl,
        type: "GET",
        headers: { "Authorization": "Basic " + geminiUsername },
        success: function () {
            alert('Success!');
        }
    });

});

var Base64 = {

    // private property
    _keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",

    // public method for encoding
    encode: function (input) {
        var output = "";
        var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
        var i = 0;

        input = Base64._utf8_encode(input);

        while (i < input.length) {

            chr1 = input.charCodeAt(i++);
            chr2 = input.charCodeAt(i++);
            chr3 = input.charCodeAt(i++);

            enc1 = chr1 >> 2;
            enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
            enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
            enc4 = chr3 & 63;

            if (isNaN(chr2)) {
                enc3 = enc4 = 64;
            } else if (isNaN(chr3)) {
                enc4 = 64;
            }

            output = output +
            this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
            this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);

        }

        return output;
    },

    // public method for decoding
    decode: function (input) {
        var output = "";
        var chr1, chr2, chr3;
        var enc1, enc2, enc3, enc4;
        var i = 0;

        input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

        while (i < input.length) {

            enc1 = this._keyStr.indexOf(input.charAt(i++));
            enc2 = this._keyStr.indexOf(input.charAt(i++));
            enc3 = this._keyStr.indexOf(input.charAt(i++));
            enc4 = this._keyStr.indexOf(input.charAt(i++));

            chr1 = (enc1 << 2) | (enc2 >> 4);
            chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
            chr3 = ((enc3 & 3) << 6) | enc4;

            output = output + String.fromCharCode(chr1);

            if (enc3 != 64) {
                output = output + String.fromCharCode(chr2);
            }
            if (enc4 != 64) {
                output = output + String.fromCharCode(chr3);
            }

        }

        output = Base64._utf8_decode(output);

        return output;

    },

    // private method for UTF-8 encoding
    _utf8_encode: function (string) {
        string = string.replace(/\r\n/g, "\n");
        var utftext = "";

        for (var n = 0; n < string.length; n++) {

            var c = string.charCodeAt(n);

            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if ((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }

        }

        return utftext;
    },

    // private method for UTF-8 decoding
    _utf8_decode: function (utftext) {
        var string = "";
        var i = 0;
        var c = c1 = c2 = 0;

        while (i < utftext.length) {

            c = utftext.charCodeAt(i);

            if (c < 128) {
                string += String.fromCharCode(c);
                i++;
            }
            else if ((c > 191) && (c < 224)) {
                c2 = utftext.charCodeAt(i + 1);
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            }
            else {
                c2 = utftext.charCodeAt(i + 1);
                c3 = utftext.charCodeAt(i + 2);
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }

        }

        return string;
    }

}

Gurinder
· 350
Gurinder
helpful
0
not helpful

Thanks. It is working!


stepand76
· 504
stepand76