public static JToken CallBCToken(BCCust theBCCust, string theBCURI, JToken theBCToken, Method theMethod, string theBCVersion) { //JToken theBCToken; // We will send data, and expect to get data back, as JSON const string contentType = "application/json"; const string acceptType = "application/json"; // BigCommerce site API credentials string api_token = theBCCust.Api_token; string api_client_id = theBCCust.Api_client_id; string api_secret = theBCCust.Api_secret; string api_site_id = theBCCust.Api_site_id; // Setup a REST client RestClient client = new RestClient("https://api.bigcommerce.com/stores/" + api_site_id + "/" + theBCVersion); // Setup a REST request, based on credentials retrieved above, and URI fragment. RestRequest request = new RestRequest(theBCURI, theMethod); request.AddHeader("x-auth-client", api_client_id); request.AddHeader("x-auth-token", api_token); request.AddHeader("content-type", contentType); request.AddHeader("accept", acceptType); if (theMethod != Method.GET && theBCToken != null) { // Insert JSON token into request request.AddParameter("application/json", theBCToken, ParameterType.RequestBody); } // Ask the REST service; capture response IRestResponse response = client.Execute(request); if (response.IsSuccessful) { // Extract the response as a string. string the_response = response.Content; // Translate the string into a JSON token theBCToken = JToken.Parse(the_response); } else { theBCToken = null; } return(theBCToken); }
public static JToken PostBCToken(BCCust theBCCust, string theBCURI, JToken theBCToken) => CallBCToken(theBCCust, theBCURI, theBCToken, Method.POST, "v2");
public static JToken PutBCToken3(BCCust theBCCust, string theBCURI, JToken theBCToken) => CallBCToken(theBCCust, theBCURI, theBCToken, Method.PUT, "v3");
public static JToken GetBCToken3(BCCust theBCCust, string theBCURI) => CallBCToken(theBCCust, theBCURI, null, Method.GET, "v3");