401 Unauthorized when trying to make call to API

When I attempt to make a call to this Rest API, it will return "Unauthorized". I have tried various ways of authenticating with it, but none have worked. I have already confirmed that the credentials and URL are correct. Is there another way that I should be passing the credentials?

Sample code given in PHP:

// Get Order with specific ID

$username = "foo@foodomain.com";

$password = "qaz@PASSword.net";

$base_url = "https://my.freestylecommerce.com/webapi/V1/";

$url = $base_url . "Orders/1049";

print("<br/><br/>***** Getting URL ". $url . "<br/>");

$out = get_request ( $url, $username, $password);



* Curl GET request


function get_request ( $url, $username, $password)


    $CURL = curl_init();

    curl_setopt($CURL, CURLOPT_URL, $url); // set url to post to


    curl_setopt($CURL, CURLOPT_HTTPHEADER, array('Accept: application/json'));

    curl_setopt($CURL, CURLOPT_USERPWD, $username . ":" . $password);

    curl_setopt($CURL, CURLOPT_RETURNTRANSFER, true);

    curl_setopt($CURL, CURLOPT_SSL_VERIFYPEER, 0);

    curl_setopt($CURL, CURLOPT_SSL_VERIFYHOST, 0);

    //curl_setopt($CURL, CURLOPT_HEADER, 1);

    $Response = curl_exec($CURL);

    if($Response === false)





    return $Response;



Open in new window

Code in C# (initial attempt):

logger.Log("Calling URL: " + geturl);
List<string> orderlist = new List<string>();

var request = WebRequest.Create(geturl);

request.ContentType = "application/json; charset=utf-8";
request.Credentials = new NetworkCredential(supplierid, token);
var response = (HttpWebResponse)request.GetResponse();

Open in new window

Now I am attempting it in a different way (still to no avail), using a HTTPWebRequest, setting auth header, and accept header:

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(geturl);
request.Accept = "application/json";
SetBasicAuthHeader(request, supplierid, token);
logger.Log("Username is: " + supplierid + " and password is: " + token);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream resStream = response.GetResponseStream();

public static void SetBasicAuthHeader(WebRequest request, String userName, String userPassword)
            string authInfo = userName + ":" + userPassword;
            authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(authInfo));
            request.Headers["Authorization"] = "Basic " + authInfo;

Open in new window

Jordan JohnsonAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

käµfm³d 👽Commented:
What does the API's documentation state? That is the source of truth for how the API requires you to log in. Anything we suggest would simply be guessing.
käµfm³d 👽Commented:

And by my last comment I am not referring to code, but rather what authentication mechanism does the documentation mention? Does it say basic authentication? Is it OAuth? Is it token based? etc.
Jordan JohnsonAuthor Commented:
It appears to just use basic authentication. It doesn't actually state this within the documentation, but just gives the PHP code example and so I was really just trying to go from the code example alone.
Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

käµfm³d 👽Commented:
Based on what I see here:


...your assumption is correct. Your last code snippet should be what you need. Just to be sure, you've done what is described here:


...to set up an account, correct?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jordan JohnsonAuthor Commented:
Thanks, I am glad to hear that the code looks correct at least. It may be an issue on their side in that case. I was given test credentials, but perhaps I was locked out or something along those lines. I tried browsing directly to the url used for the call to the API and input my credentials, and it continued to prompt for credentials, so there looks to be some other issue at play.
Jordan JohnsonAuthor Commented:
This was all I needed to know. Now that it was fixed on their end, the calls are having no further issues. Thanks!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.