Discussions

Ask a Question
Back to All

I am getting forbidden error when calling Order/New API in C#

public void WebAPICallingforSearchOrders()
{
string x_auth_token = "e6a3105b-af20-3fb3-88fe-e69d46bcde2e";
string x_seller_authz_token = "f2c22bbc-577f-4eb2-a64d-ac54df9a4310";

        string json = "";
        var client = new RestClient("http://staging-apigateway.snapdeal.com/seller-api/orders/new");

        var request = new RestRequest(Method.GET);
        request.AddHeader("Accept", "application/json");
        request.AddHeader("Content-Type", "application/json");
        request.AddHeader("X-Auth-Token", x_auth_token);
        request.AddHeader("X-Seller-AuthZ-Token", x_seller_authz_token);

        request.AddQueryParameter("application/json", "VENDOR_SELF");

        //client.ExecuteAsync(request, response =>
        //{
        //    json = response.Content;
        //});

        var response = client.Execute(request);
        json = response.Content;

        if (!json.Contains("errors") && !json.Contains("error"))
        {
            json = json.Replace("[{", "{");
            json = json.Replace("}]", "}");

            var result = JObject.Parse(json);
        }
        else
        {
            json = json.Replace("[{", "{");
            json = json.Replace("}]", "}");
            var result = JObject.Parse(JObject.Parse(json)["errors"].ToString());
            string code = result["code"].ToString();
            string message = result["message"].ToString();
        }
    }