1

We have exposed our sql server db behind slashdb(slashdb.com). Within their site we were able to create queries and get the data from their generated URLs. But not from outside like from a C# application.

Now we would to use those URLs in your c# application and display the data in our web pages. I know how to make rest based call in c#. But I'm stuck in sending the authentication information with the slashdb rest api call from my c#. It is throwing 403 http error.

Please let me know how can i make call to a slash db rest call from a c# application.

Thanks.

Phil Cooper
  • 5,747
  • 1
  • 25
  • 41
APeter
  • 21
  • 1
  • 4

1 Answers1

1

HTTP 403 indeed indicates missing or incorrect credentials or a fact that the user is not authorized to table or query resource.

First of all, make sure that the username you will be using to send requests to SlashDB has been assigned Execute permission to the query. To do that, go to Configuration->Queries, and open the query definition. In the Execute field type in the username. You can assign multiple user names by separating them with commas. As a side note user public does not require credentials, so if your resource can be publicly available, simply add public the Execute field.

For non-public users you need to provide those credentials with your HTTP request.

SlashDB allows for two ways to send your credentials:

  1. Username/Password using BasicAuthentication
  2. API keys

Ad.1 Construct your HTTP request with the Authorization header and a binhexed value for username:password. See this Stackoverflow recipe how to do that: Calling a rest api with username and password - how to

Ad.2 To use API keys, first assign the SlashDB user a key (alphanumerical string) then provide it with your request.

To do that, go to Configuration->Users, and open the user's configuration dialog. Scroll down to the bottom to the API Authentication section and paste your key in the field provided. For inspiration see CodeIngniter or WEP256 keys on http://randomkeygen.com/. Do not use strings containing ":" because it is used for splitting the key to app-key and api-key. For now just go with a single key.

Send your key with your request either as a header or in the URL query string. By default the parameter is called "apikey":

Option 1: In headers

(HttpWebRequest)WebRequest.Create(@"https://slashdb.yourdomain.com/db/Northwind/Customers/CustomerID/ALFKI.json");
req.Headers.Add("apikey", "12345678");

Option 2: In URL

(HttpWebRequest)WebRequest.Create(@"https://slashdb.yourdomain.com/db/Northwind/Customers/CustomerID/ALFKI.json?apikey=12345678");
Victor Olex
  • 1,458
  • 1
  • 13
  • 28