API connection error [solved]

Plugins, funzionalità sviluppate dagli utenti, patch, fix...
Post Reply
martin.duran
Newbie
Posts: 2
Joined: Wed Aug 14, 2013 8:25 pm

API connection error [solved]

Post by martin.duran »

Hi, i'm trying to make a call to the REST API from C#, but i always receive this message:

Code: Select all

{"success":false,"error":104,"message":"Authorization header value doesn't match"}
The X-Authorization hash is well generated (Y2x6RVIwYTRCWkdBZnBKRiFCX2VobFRTOjhkZmVjODcxOWYwZjQ1ZjY4ZGVjNGNmMDA2ODI4MzI2OTQ4ZmQ2MmU=). This is the code i use to make the call:

Code: Select all

string url = String.Format("http://{0}/api/{1}", urlBase, method); 
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); 
request.Method = "POST"; 
request.Host = urlBase; 
request.Headers.Add("X-Authorization", "Docebo " + code); 
request.ContentType = "text/json"; 

StreamWriter requestStream = new StreamWriter(request.GetRequestStream()); 
requestStream.Write(json); 
requestStream.Close();

With: 
urlBase = gmigliarino.docebosaas.com 
method = user/checkUsername 
json = {"userid": "user.test"}
Anyone has any idea why i'm receiving this message? Or any C# example.

Thanks in advance!
Last edited by martin.duran on Fri Aug 16, 2013 3:14 pm, edited 1 time in total.
User avatar
max
FormaLms Guru
Posts: 2735
Joined: Thu Mar 01, 2012 10:41 am
Version: forma.lms 2.4
Contact:

Re: API connection error

Post by max »

Hi Martin
Welcome on board!
Sorry, but our Tech Guys are all on holiday, I am not able to support you on this issue.
Hope someone else on the forum is available.
---------------------
Massimiliano Ferrari
Elearnit - Elearning e Knowledge Management
https://www.elearnit.net
https://www.linkedin.com/in/massimilianoferrari
m.ferrari[at]elearnit.net
Skype: m_ferrari_it
martin.duran
Newbie
Posts: 2
Joined: Wed Aug 14, 2013 8:25 pm

Re: API connection error

Post by martin.duran »

Hi, i finally got it worked! Just set the ContentType to "application/x-www-form-urlencoded" and the content that is written to the stream like GET format: param1=value1&param2=value2...

Thanks!!
User avatar
max
FormaLms Guru
Posts: 2735
Joined: Thu Mar 01, 2012 10:41 am
Version: forma.lms 2.4
Contact:

Re: API connection error [solved]

Post by max »

Hi,
thanks to you, Martin, you did everything by yourself... :-)

Thanks for posting the solution, too!
---------------------
Massimiliano Ferrari
Elearnit - Elearning e Knowledge Management
https://www.elearnit.net
https://www.linkedin.com/in/massimilianoferrari
m.ferrari[at]elearnit.net
Skype: m_ferrari_it
Post Reply