AddDelegation : The remote server returned an error: (400) Bad Request.

Answered

Comments

2 comments

  • Avatar
    Aviksha Ramya Koneri

    Hi Prakash,

    You may need to modify your code as shown below snippet to make it work. We should use Unix Timestamp for StartDate and End Date input.

    public static WFDelegation AddDelegation(WFDelegation delegation)
    {
        string url = $"{WebConfig.AppSettings[$"{WFConst.constAdminSettings}:{WFConst.constAdminUrl}"]}AddDelegation";

        DateTime dtStart = DateTime.Parse(delegation.StartDate.ToString());

        long milliStart = (long)(dtStart.ToUniversalTime() - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds;

        string formattedStartDate = $"/Date({milliStart}+0000)/";

        DateTime dtEnd = DateTime.Parse(delegation.EndDate.ToString());

        long milliEnd = (long)(dtEnd.ToUniversalTime() - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds;

        string formattedEndDate = $"/Date({milliEnd}+0000)/";

        #region Json Object

        dynamic jsonRequestData = new JObject();

        jsonRequestData.FromUser = delegation.FromUser;
        jsonRequestData.ToUser = delegation.ToUser;
        jsonRequestData.StartDate = formattedStartDate;
        jsonRequestData.EndDate = formattedEndDate;
        jsonRequestData.Description = delegation.Description;
        jsonRequestData.Status = delegation.Status;

        #endregion

        string _jsonString = JsonConvert.SerializeObject(jsonRequestData);

        AgilePointServiceUtil ops = new AgilePointServiceUtil();

        string respose = ops.POSTJson(url, _jsonString);

        WFDelegation _delegations = null;

        #region Json Parse

        if (!string.IsNullOrWhiteSpace(respose))
        {
            JObject resObject = JObject.Parse(respose);

            string result = resObject?.ToString();

            _delegations = JsonConvert.DeserializeObject<WFDelegation>(result);
        }

        #endregion

        return _delegations;
    }

    Modification: The parameters StartDate and EndDate should be in the format of  “/Date(1499884200000+0000)/”, but in your code those parameters are sent as string.

    Document Link: https://documentation.agilepoint.com/11/developer/restmethodAddDelegation.html

     

    Thanks,

    Aviksha

    2
    Comment actions Permalink
  • Avatar
    Prakashkumar Nambi

    Hi Aviksha,

    The fix what you gave works fine.

    Thanks.

     

     

     

    0
    Comment actions Permalink

Please sign in to leave a comment.