Stig Schmidt Nielsson
Stig Schmidt Nielsson

Reputation: 1687

How to access shopify api with .NEts new HttpClient class

I am trying to call the shopify like this:

HttpClient.GetAsync(https://---apikey---:[email protected]/admin/orders.xml)

But I keep getting Unauthorized 401 results. When I test the uri in chrome it works fine, so I think the HttpClient somehow is unable to handle authentication data embedded in the url which shopify requires.

Does anyboy body know how to do this with the new .NEt 4.5 HttpClient ?

Upvotes: 1

Views: 1270

Answers (2)

Edward Ocampo-Gooding
Edward Ocampo-Gooding

Reputation: 2862

Chris’ answer is dead on.

In case you’re also curious about an even more slick way of working with the Shopify API with .NET, check out the official .NET adapter for Shopify: https://github.com/cmcdonaldca/shopify.net

Upvotes: 1

Kinexus
Kinexus

Reputation: 12904

You could try creating an instance of HttpClientHandler and create a Credentials instance and use this in your HttpClient, something like this;

            var clientHandler = new HttpClientHandler
                                    {
                                        Credentials = new NetworkCredential("Username", "Password"),
                                        PreAuthenticate = true
                                    };

            var httpClient = new HttpClient(clientHandler);

            var responseMessage = httpClient.GetAsync("http://url").Result;

In this case, you would not need to pass the username@password in the URI.

Upvotes: 3

Related Questions