0

I would like to authenticate me on spreadshirt but I get an internal server error as result.

Im new to Rest API..

So here is the documentation: https://developer.spreadshirt.net/display/API/Security+Resources

and my Code:

        var client = new RestClient("https://api.spreadshirt.net/api/v1");

        var request = new RestRequest("sessions", Method.POST);
        request.AddParameter("username", "foo");
        request.AddParameter("password", "bar");
        var test = client.Execute(request);

EDIT:

Got it

My Login Class

[SerializeAs(Name ="login")]
public class Login
{
    private string user;
    private string pw;


    [SerializeAs(Name ="username")]
    public string username
    {
        get
        {
            return "foo";
        }
        set
        {
            this.user = value;
        }
    }
    [SerializeAs(Name ="password")]
    public string password
    {
        get { return "bar"; }
        set { this.pw = value; }
    }
}

On Button Click

var login = new Login();
        var request = new RestRequest("sessions/", Method.POST);

        var client = new RestClient("https://api.spreadshirt.net/api/v1/");

        request.XmlSerializer = new RestSharp.Serializers.XmlSerializer();
        request.RequestFormat = DataFormat.Xml;

        request.AddXmlBody(login, "http://api.spreadshirt.net");

        var response = client.Execute(request);
        MessageBox.Show(response.StatusCode.ToString());
BR75
  • 633
  • 7
  • 25
  • 2
    It's a REST API but requests must be in XML. See https://stackoverflow.com/questions/34527935/building-xml-request-with-restsharp – Dan Wilson May 01 '18 at 15:18
  • thanks, could you tell me whats wrong with it now? – BR75 May 01 '18 at 21:01
  • I would just try it and see if it works. If not, then post a specific error here. I can't say either way just by looking at the code. – Dan Wilson May 01 '18 at 21:07
  • it throws me the same internal server error. Im not sure if im doing it right with my Login class or if I miss something to pass – BR75 May 01 '18 at 21:14
  • Can you do the debug and share the request value?. Some of the request also cause an internal server error problem – Subburaj May 29 '18 at 04:28
  • Im already solved that problem, see my edit :) – BR75 May 29 '18 at 17:59

0 Answers0