POST /v1/tasks returns HTTP Status: 422 – Reason: Unprocessable Entity

380 views
Skip to first unread message

Nick Chubinidze

unread,
Mar 21, 2016, 10:53:11 AM3/21/16
to Assembla API Development
i am using c# HttpClient.

                 AssemblaTask at = new AssemblaTask()
                    {
                        description = "test",
                        user_id = userId,
                        space_id = spaceId,
                        ticket_id = ticketId,
                        url = someUrl,
                        hours = 6.3F,
                        begin_at = Convert.ToDateTime("2012-12-17T08:52:20Z"),
                        end_at = Convert.ToDateTime("2012-12-17T08:52:20Z"),
                        updated_at = Convert.ToDateTime("2012-12-17T08:52:20Z"),
                        created_at = Convert.ToDateTime("2012-12-17T08:52:20Z"),
                         job_agreement_id="ggggggggggg",
                         id=532 
                    };

                    var a = new Uri($"http://api.assembla.com/v1/tasks.json");
                    
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                    client.DefaultRequestHeaders.Host = a.Host;
                    client.DefaultRequestHeaders.Add("X-Api-Key", ApiKey);
                    client.DefaultRequestHeaders.Add("X-Api-Secret", ApiSecret);


                    
85 {"errors":{"space_id":["can't be blank"],"description":["can't be blank"],"begin_at":["can't be blank"],"end_at":["can't be blank"]}} 0 


Untitled.jpg

Stanislav Kolotinskiy

unread,
Mar 21, 2016, 11:12:09 AM3/21/16
to assembla...@googlegroups.com
Hi Nick,

I can see from your snippet that `at` variable isn't used at all. Is that on purpose?

Regards,
Stanislav
--
You received this message because you are subscribed to the Google Groups "Assembla API Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to assembla-api-d...@googlegroups.com.
To post to this group, send email to assembla...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Nick Chubinidze

unread,
Mar 21, 2016, 12:07:49 PM3/21/16
to Assembla API Development
here it is

DataContractJsonSerializer jsonSer = new DataContractJsonSerializer(typeof(AssemblaTask));

                    MemoryStream ms = new MemoryStream();
                    jsonSer.WriteObject(ms, at);
                    ms.Position = 0;

                    StreamReader sr = new StreamReader(ms);

                    StringContent theContent = new StringContent(sr.ReadToEnd(), System.Text.Encoding.ASCII, "application/json"); 

                    HttpResponseMessage response = await client.PostAsync(a, theContent);

понедельник, 21 марта 2016 г., 19:12:09 UTC+4 пользователь Stanislav Kolotinskiy написал:
Message has been deleted
Message has been deleted

Nick Chubinidze

unread,
Mar 22, 2016, 4:09:10 AM3/22/16
to Assembla API Development
in documentation there is note on tasks section. i don't have idea what's that and how to attach, maybe you can give some hint ) 

Note: Be sure to have Time tool attached to your project before using this API.

and one more thing i'm curious about.  on Task object fields page there is validations section where's written that we need presence validator on some fields and i don't clearly understand it. 

понедельник, 21 марта 2016 г., 18:53:11 UTC+4 пользователь Nick Chubinidze написал:

Stanislav Kolotinskiy

unread,
Mar 22, 2016, 4:44:13 AM3/22/16
to assembla...@googlegroups.com
Hi Nick,

so before using tasks API, you need to have Time tool in your space. You could add it from Admin section in your space. Also, I can't really help you about your code, since I'm not a C# expert, but here are some hints:
* please make sure that application/json Content-Type header is set correctly
* please make sure that the object is serialized correctly into JSON?
* please make sure that your object is wrapped into "task" namespace. So request data should look like: {"task": {"description": "My description", space_id: "my_space_id", ...}}

Please let me know if that helps.

Regards,
Stanislav


On 22/03/16 10:08, Nick Chubinidze wrote:

in documentation there is note on tasks section. i don't have idea what's that and how to attach, maybe you can give some hint ) 

Note: Be sure to have Time tool attached to your project before using this API.

and one more thing i curious about.  on Task object fields page there is validations section where's written that we need presence validator on some fields and i don't clearly understand it. 

понедельник, 21 марта 2016 г., 18:53:11 UTC+4 пользователь Nick Chubinidze написал:
i am using c# HttpClient.
Reply all
Reply to author
Forward
0 new messages