private void CallTheApi() { if (!string.IsNullOrWhiteSpace(txtUrl.Text) && !txtUrl.Text.EndsWith("/")) { txtUrl.Text = txtUrl.Text + "/"; } if (!string.IsNullOrWhiteSpace(cboPath.Text) && !cboPath.Text.StartsWith("/")) { cboPath.Text = "/" + cboPath.Text; } var context = new WebApiRequestContext { PublicKey = txtPublicKey.Text, SecretKey = txtSecretKey.Text, Url = txtUrl.Text + (radioOdata.Checked ? "odata/" : "api/") + txtVersion.Text + cboPath.Text, HttpMethod = cboMethod.Text, HttpAcceptType = (radioJson.Checked ? ApiConsumer.JsonAcceptType : ApiConsumer.XmlAcceptType) }; if (!string.IsNullOrWhiteSpace(cboQuery.Text)) { context.Url = string.Format("{0}?{1}", context.Url, cboQuery.Text); } if (!context.IsValid) { "Please enter Public-Key, Secret-Key, URL and method.".Box(MessageBoxButtons.OK, MessageBoxIcon.Exclamation); Debug.WriteLine(context.ToString()); return; } var apiConsumer = new ApiConsumer(); var response = new WebApiConsumerResponse(); var sb = new StringBuilder(); StringBuilder requestContent = null; Dictionary <string, object> multiPartData = null; lblRequest.Text = "Request: " + context.HttpMethod + " " + context.Url; lblRequest.Refresh(); if (radioApi.Checked && !string.IsNullOrEmpty(txtFile.Text) && cboPath.Text.StartsWith("/Upload")) { multiPartData = apiConsumer.CreateProductImageMultipartData(txtFile.Text, txtProductId.Text.ToInt(), txtProductSku.Text); } var webRequest = apiConsumer.StartRequest(context, cboContent.Text, multiPartData, out requestContent); txtRequest.Text = requestContent.ToString(); bool result = apiConsumer.ProcessResponse(webRequest, response); lblResponse.Text = "Response: " + response.Status; sb.Append(response.Headers); if (result && radioJson.Checked && radioOdata.Checked) { var customers = response.TryParseCustomers(); if (customers != null) { sb.AppendLine(string.Format("Parsed {0} customer(s):", customers.Count)); foreach (var customer in customers) { sb.AppendLine(customer.ToString()); } sb.Append("\r\n"); } } sb.Append(response.Content); txtResponse.Text = sb.ToString(); cboPath.InsertRolled(cboPath.Text, 64); cboQuery.InsertRolled(cboQuery.Text, 64); cboContent.InsertRolled(cboContent.Text, 64); }