UpdateDelegation : The remote server returned an error: (400) Bad Request.
AnsweredHi Team,
I am getting "The remote server returned an error: (400) Bad Request." while adding "AddDelegation" using the below code.
public static WFDelegation UpdateDelegation(WFDelegation delegation)
{
string url = $"{WebConfig.AppSettings[$"{WFConst.constAdminSettings}:{WFConst.constAdminUrl}"]}UpdateDelegation";
#region Json Object
dynamic jsonRequestData = new JObject();
#region Date Formats
long milliStart = (long)(delegation.StartDate.ToUniversalTime() - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds;
string formattedStartDate = $"/Date({milliStart}+0000)/";
long milliEnd = (long)(delegation.EndDate.ToUniversalTime() - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds;
string formattedEndDate = $"/Date({milliEnd}+0000)/";
#endregion
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;
}
jsonRequestData :-
{
"FromUser":"NAMBP4123",
"ToUser":"SVIJA2987",
"StartDate":"/Date(1714674600000+0000)/",
"EndDate":"/Date(1715106600000+0000)/",
"Description":"testing ewwrwer",
"Status":"Active"
}
-
Prakashkumar, the values of 'FromUser' and 'ToUser' should be an actual AgilePoint user such as domainname\username or username@company.com.
For better understanding capture and log the WebException response data. It might include information like Invalid user 'NAMBP4123'.
You can also copy paste the payload to postman which will always read response data from WebException. Call the same API from postman to easily identify the reason for the (400) Bad Request.
-
Hi Prakashkumar,
1) To Update delegation, DelegationID is mandatory. Try passing the DelegationID along with other properties in payload.
2) The payload you are making use of will let you create a Delegation. if you are actually trying to AddDelegation, then you will have to change the endpoint.
Hope you find this answer helpful.
-
Hi Prakash,
You may need to modify your jsonRequestData to make your code work. We should mention domain name in the values of FromUser and ToUser, and Delegation ID is required for update delegation.
You can refer below payload
{
“DelegationID”:”DELEGATIONID”,
"FromUser":"DOMAINNAME\\NAMBP4123",
"ToUser":" DOMAINNAME\\SVIJA2987",
"StartDate":"/Date(1714674600000+0000)/",
"EndDate":"/Date(1715106600000+0000)/",
"Description":"testing ewwrwer",
"Status":"Active"
}Modification: Replace DELEGATIONID with your delegation ID and DOMAINNAME to your Domain name.
Document Link: https://documentation.agilepoint.com/11/developer/restmethodUpdateDelegation.html
Please sign in to leave a comment.
Comments
4 comments