Discussions

Ask a Question
Back to All

API call status code "Forbidden" using code as below

            string apiKey = "MY_API_KEY";

            // Create a RestClient
            var client = new RestClient("https://csgoempire.com");

            // Create a RestRequest for the endpoint
            var request = new RestRequest("/api/v2/user", Method.Get);

            // Add the authorization header
            request.AddHeader("Authorization", $"Bearer {apiKey}");

            // Execute the request
            var response = client.Execute(request);

            // Check if the request was successful
            if (response.IsSuccessful)
            {
                // Parse the response content
                var content = response.Content;
                dynamic data = Newtonsoft.Json.JsonConvert.DeserializeObject(content);
                Console.WriteLine($"Your account balance is: {data.balance}");
            }
            else
            {
                Console.WriteLine($"Failed to retrieve account balance. Status code: {response.StatusCode}");
            }