Client API Usage

Greetings, all.

Most of my customers use a WebApp to access their data, but some are more sophisticated and would like to use the client REST API. A customer may have multiple devices assigned to him or her.

That in mind:

  1. How would a customer obtain the DEVICE_PUBLIC_KEYs for each of his/her devices?
  2. If a customer needs to call mdash.net/api/v2/customer, how would he/she obtain his/her CUSTOMER_KEY?

To clarify, as the owner/admin I know how to get this info from the mDash dashboard, but not clear how a customer would obtain this information on their own.

Thanks!
-AD

A customer gets its key after self-registration.
Similar to admins get their own credentials.

This is a web app login snippet: https://github.com/cesanta/mdash-smart-light/blob/master/mobile-app/js/app.js#L135-L151

There, a customer enters email + password, clicks on login button, and JS code sends a /customer GET request with the basic authorisation header. A response is a customer JSON object with token and list of customer’s devices (their PUBLIC_KEYs).

Hope that helps.

Thanks for these details - it’s clear how one obtains the device PUBLIC_KEYs now.

I am confused, however, regarding the usage of /customer GET endpoint. In the Client API doc it states:

Every request must have a ?access_token=CUSTOMER_KEY query string attached, or a Authorization: Bearer CUSTOMER_KEY header specified.

…but you mention above that username/password authorization should be used with this GET call instead of the CUSTOMER_KEY token approach in the docs. Do both methods apply?

-AD

Yes, both methods. If you know the CUSTOMER_KEY, you can use it.
If you don’t know it, you must know email/pass - then, use Basic auth.

Understood on the Basic auth method. Is there a way for a customer to programmatically determine his/her CUSTOMER_KEY?

-AD

A customer must know its email + pass.
Make a Basic auth request using email + pass, and get a customer JSON object back. A JSON object contains CUSTOMER_KEY.

1 Like

Sorry to revisit this, but struggling to get this to work.

Attempting the following:
curl --request GET --user 'user@example.com:passwd' --url https://mdash.net/api/v2/customer

…returns:
{"message":"Not Found"}

Am I missing something here?

Thanks,
-AD

Any further thoughts on this one? We have a customer attempting to make use of this API endpoint and are stuck at the moment.

Thanks!

I’ve given an exact snippet from the working .js file.

The URL is https://mdash.net/customer

Thanks for the corrected URL. I was using the other URL from the API doc.

The following curl command worked for me:

curl -u user@example.com:passwd https://mdash.net/customer

-AD

1 Like