web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

converting API request from javascript to C#

(0) ShareShare
ReportReport
Posted on by

Hi...

Can anyone suggest me how to convert the following API call  in javascript to C# code (WebClient only):

function GetData() {

formType = Xrm.Page.ui.getFormType();
$.ajax({
beforeSend: function (xhrObj) {
xhrObj.setRequestHeader("Authorization", "Bearer " + token);
},
type: "Get",
crossDomain: true,
cache: false,
url: "some url here", //Search API
data: { qry: search, from: 1, to: 100, format: 'json', ctrycode: 1 },
dataType: "json",
success: function (data) {
if (formType == 1) {
debugger;
getSearchData(data);
}
else if (formType == 2) {
getUpdateData(data);
}
},
error: function (error, readyState, textStatus, statusCode) {
getErrorDetails(error, readyState, textStatus, statusCode);
}
});

}

I tried the following code but it is giving error: {"Cannot send a content-body with this verb-type."}. This error says that you can not use content body with method GET. But my requirement is to use GET only.

GetDatafromAPI getData = new GetDatafromAPI();
getData.qry = "search";
getData.from = "1";
getData.to = "100";
getData.format = "json";
getData.ctrycode = "1";

string url1 = "intouch-api.linkmobility.com/.../search";

DataContractJsonSerializer objSerialization1 = new DataContractJsonSerializer(typeof(GetDatafromAPI));
MemoryStream objStream1 = new MemoryStream();
objSerialization1.WriteObject(objStream1, getData);
string data1 = Encoding.UTF8.GetString(objStream1.ToArray(), 0, (int)objStream1.Length);
WebClient webClient1 = new WebClient();

webClient.Headers["Authorization"] = "Bearer " + token;
webClient.Encoding = Encoding.UTF8;

var response1 = webClient.UploadString(url1, "GET", data1);

I want to retrieve data in WebClientResponse so that i can pass it to another function in C# code.

Please help

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Nithya Gopinath Profile Picture
    17,078 on at

    Hi Needhi,

    Refer the link below.

    msdn.microsoft.com/.../mt742424.aspx

    It shows the web API sample using c#.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans