Third Light Developer Exchange

Code and templating community forum for developers and software integrators

You are not logged in.

Announcement

If you wish to join the Developer Exchange, please contact your account manager - this is to avoid unnecessary spam in the forums. Many thanks for your understanding.

#1 2014-11-18 14:14:55

satishd
Member
Registered: 2014-11-18
Posts: 40

Unbable to get session id

Hi There,

I'm newer to thridlight IMS API software, As a first step I want to login into IMS through the API key, but always comes up the following error when I try to get session id through the url

https://myIMSServer/api.json.tlx?json=%7binParams:{apikey:P2bd9zs1zslWvoZGBOZNxiXbPhMbeb4a},action:Core.LoginWithKey,apiVersion:1.0}


The error I get is as shown below

{"result":{"api":"BAD_INPUT","action":"API_ERROR","debug":"No input provided."}}


I have used following URL

https://mywebsite/api.json.tlx?json={inParams:{apikey:fC+d/VnMT+8ZQmdWWXWgB2yy7bAKASHt},action:Core.LoginWithKey,apiVersion:1.0}

and the configuration >site options is as follows.

Key Name             API Key   
hubapp             fC+d/VnMT+8ZQmdWWXWgB2yy7bAKASHt   

Unchecked "Enable API access from other sites"
Unchecked "Enable JSONP API Requests"


>> Do I have to check "Enable API access from other sites" in that case, what address should I mention, I am using development machine where as server is located within same domain.

Please advise me

Thanks for your help.
Satish

Offline

#2 2014-11-18 14:33:34

dominic
Third Light Staff
Registered: 2013-06-06
Posts: 119

Re: Unbable to get session id

Hi Satish,

The problem is that the JSON provided is not valid; if you change it to

{"inParams":{"apikey":"fC+d/VnMT+8ZQmdWWXWgB2yy7bAKASHt"},"action":"Core.LoginWithKey","apiVersion":"1.0"}

(note the use of quotes), then you should not see this error.

It is also worth noting that this ought to be URL-encoded before being passed as a GET parameter - if you are testing from a browser you may well find that this is taken care of for you, but you should take care to do it explicitly in an application (or, better, use the POST method, as GET parameters are logged).

If the above is a real API key, you should delete it and create a new one, as it is a sensitive security token.

The "Enable API access from other sites" is required for applications that will make requests from an end user's browser, as CORS applies to these. JSONP is an alternative mechanism for this.

Kind regards,

Dominic

Offline

#3 2014-11-18 14:56:10

satishd
Member
Registered: 2014-11-18
Posts: 40

Re: Unbable to get session id

Thanks Dominic,

I have tried with new changes and with new API key- still get the same error.


http://myserver.thirdlight.com/api.json.tlx?json={"inParams":{"apikey":"GOkrMgtGiwRKWnDHapcqn2WRNS8F3mxi"},"action":"Core.LoginWithKey","apiVersion":"1.0"}




{"result":{"api":"BAD_INPUT","action":"API_ERROR","debug":"No input provided."}}



Thanks
Satish

Offline

#4 2014-11-18 15:14:08

satishd
Member
Registered: 2014-11-18
Posts: 40

Re: Unbable to get session id

Hi Dominic,

I even tried logging through asp.net (post) method, i get the same error message

protected void Page_Load(object sender, EventArgs e)
        {
            var url = "http://myserver/api.json.tlx";
            var username = "myname";
            var password = "mypassword";
            var httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
            httpWebRequest.ContentType = "application/json";
            httpWebRequest.Method = "POST";

            using (var streamWriter = new System.IO.StreamWriter(httpWebRequest.GetRequestStream()))
            {
                string json = "{\"action\":\"Core.Login\"," +
                              "\"apiVersion\":\"1.0\"," +
                              "\"inParams\":{\"username\":\"" + username + "\", \"password\":\"" + password + "\"}}";

                streamWriter.Write(json);
            }
            var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
            using (var streamReader = new System.IO.StreamReader(httpResponse.GetResponseStream()))
            {
                var result = streamReader.ReadToEnd();
                Response.Write(result);
            }

             

        }


Thanks
Satish

Offline

#5 2014-11-18 16:16:51

ben
Third Light Staff
From: Third Light
Registered: 2013-06-06
Posts: 79

Re: Unbable to get session id

Hi Satish,
The "No input provided." debug message only comes from one point in the code and that's caused by either there being no incoming JSON or failing to decode what does arrive.

Regarding the GET method - I can't see anything wrong with the URL there. I'd be interested in how you are issuing the request - are you using a browser, or from a command line. I expect some sort of encoding problem as Dom mentioned. You do need to make sure the GET parameter is url encoded.

Similarly I can't see anything wrong with your POST implementation but I'm not that familiar with asp.net.


This does seem to be a bit odd. If you still have problems can you provide more of the script or application that you're running?

Ben

Offline

#6 2014-11-18 16:39:33

satishd
Member
Registered: 2014-11-18
Posts: 40

Re: Unbable to get session id

Thanks Ben,

Yes it is looking odd- I think remote logins are not alllowed? any settings I must be aware ?, from last two days I am trying to establish a connection either through API Key or through Login

Try1: Through Browser URL

here is the URL i am pasting in browser to see what results I get
http://myserver.thirdlight.com/api.json.tlx?json={"inParams":{"apikey":"GOkrMgtGiwRKWnDHapcqn2WRNS8F3mxi"},"action":"Core.LoginWithKey","apiVersion":"1.0"}


Try2: Through .Net application where I construct JSon object and submitting to server
Same error is occurring in both the cases- The asp.net code i m using is as follows.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication1
{
    public partial class _Default : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            var url = "http://myserver.thirdlight.com/api.json.tlx";
            var username = "myuserid";
            var password = "my password";
            var httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
            httpWebRequest.ContentType = "application/json";
            httpWebRequest.Method = "POST";

            using (var streamWriter = new System.IO.StreamWriter(httpWebRequest.GetRequestStream()))
            {
                string json = "{\"action\":\"authenticate.tlx\"," +
                              "\"apiVersion\":\"1.0\"," +
                              "\"inParams\":{\"username\":\"" + username + "\", \"password\":\"" + password + "\"}}";

                streamWriter.Write(json);
            }
            var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
            using (var streamReader = new System.IO.StreamReader(httpResponse.GetResponseStream()))
            {
                var result = streamReader.ReadToEnd();
                Response.Write(result);
            }

             

        }
    }
}

Regards
Satish

Offline

#7 2014-11-18 18:07:03

ben
Third Light Staff
From: Third Light
Registered: 2013-06-06
Posts: 79

Re: Unbable to get session id

Hi Ratish, just so we're definitely on the same page, please could you screenshot your browser and post it here - so I can see the exact URL (or as much as possible) and the exact response?

Many thanks,
Ben

Offline

#8 2014-11-18 18:07:26

ben
Third Light Staff
From: Third Light
Registered: 2013-06-06
Posts: 79

Re: Unbable to get session id

Sorry Satish, not Ratish!

Offline

#9 2014-11-18 18:09:40

satishd
Member
Registered: 2014-11-18
Posts: 40

Re: Unbable to get session id

Hi Ben,

I cant attache the screenshot, can you let me know your email id so that i can send the screenshots.

Thanks
Satish

Offline

#10 2014-11-19 12:14:16

dominic
Third Light Staff
Registered: 2013-06-06
Posts: 119

Re: Unbable to get session id

Hi Satish,

As mentioned previously, you should really URL encode before sending the GET request - this would transform it to

http://myserver.thirdlight.com/api.json.tlx?json=%7B%22inParams%22%3A%7B%22apikey%22%3A%22GOkrMgtGiwRKWnDHapcqn2WRNS8F3mxi%22%7D%2C%22action%22%3A%22Core.LoginWithKey%22%2C%22apiVersion%22%3A%221.0%22%7D

From Firefox this happens transparently, but this isn't the case for all browsers.

As to your POST attempt, I do note that you are setting action to authenticate.tlx - which is not a valid method. I think you want Core.Login instead. This should raise a different error, though, along the lines of:

{"result":{"api":"NO_SUCH_MODULE","action":"API_ERROR"}}

Again, it really is not a good idea to post valid credentials like API keys on the internet - you should change it again and then redact from any future post.

Kind regards,

Dominic

Offline

#11 2014-11-19 12:34:31

satishd
Member
Registered: 2014-11-18
Posts: 40

Re: Unbable to get session id

Thanks Dominic, This seems to have worked now.

Offline

Board footer