Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
jayhawk
Advocate I
Advocate I

Connect to API. Bearer Token

Hi

I am having a hard time connecting to data via API.  I am attempting pull out data from Samsara, https://www.samsara.com/api#. (the website is public info).  They use something called Bearer Token.  I have my token.  I have no issues making a call, and getting data via Terminal.  

Could someone please tell me the steps in connecting to an API in PowerBI, having to use the company issued Bearer Token they provide to you.  

 

The steps in PowerBI I took are....Get Data>Web.  Have been unsuccessful.  Please see pictures of the different things I have tried.  

2020-01-10 14_00_44-Untitled - Power BI Desktop.png2020-01-10 14_02_03-Untitled - Power BI Desktop.png2020-01-10 14_03_30-Untitled - Power BI Desktop.png2020-01-10 14_03_42-Untitled - Power BI Desktop.png

Thank you

25 REPLIES 25
jusTodd
Advocate III
Advocate III

FYI:   Apparently, Samsara is working on a PowerBI Connector to be released sometime towards the end of 2023.

Mdauria6087
New Member

You will need an API key for Samsara to use the BI web API access.

  • hi, have created a api token from samasara and provided all read acces with anyone in organization. I am giving they key but getting beloow image.jpg

    image.jpg

Double check ... have you tried replacing <API Token> with the actual token?

 

should look like

Bearer samsara_api_VariousNumbersLetters

jusTodd
Advocate III
Advocate III

The solution that continues to be missed, offered up by @jayhawk and again by @Mdauria6087 

 

Replace "3U2" with your token and you are on your way!

 

SamsaraAPIConnect.png

PierlootRens
New Member

This solved it for me

KHC0587
Frequent Visitor

Did anyone figure out how to set up automatic refreshes on this data source? I have been able to pull the data from Samsara (thank you all for the above support), but when I publish online, I can't set up refreshes due to missing web credentials?

 

KHC0587_0-1671820634694.png

This is my M-Script call:

Json.Document(Web.Contents("https://api.samsara.com/fleet/vehicles", [Headers=[Authorization="Bearer myapiKey"]]))

 

and off of the vehicle id columns i call:

#"Added Custom" = Table.AddColumn(#"Changed Type1", "Custom", each Json.Document(Web.Contents("https://api.samsara.com/",[RelativePath = "v1/fleet/trips" & "?startMs=" & Text.From(Duration.TotalSeconds(startMs - #datetime(1970, 1, 1, 0, 0, 0))) & "000" & "&endMs=" & Text.From(Duration.TotalSeconds(Date.From(DateTimeZone.LocalNow())-#date(1970, 1, 1))) & "000" & "&vehicleId=" & [data.id], Headers = [Authorization = "Bearer " & "myapiKey"]]))),

 

Did you resolve this? I'm stuck with the same issue

Unfortunately, no I never solved it, ended up just abandoning the project as leadership lost interest in it.

Mdauria6087
New Member

Mdauria6087_0-1668185817457.png

Give this a shot.

Mdauria6087
New Member

Does anyone know how to get a full YTD dataset from the Samsara API. The endCursor is limiting me to 3 rows only.

 

Mdauria6087_0-1668184854674.png

Here is my call:

GET /fleet/hos/daily-logs?startDate=2022-01-01&endDate=2022-11-01&driverActivationStatus=active&expand=vehicle HTTP/1.1
Accept: application/json
Authorization: Bearer samsara_api_?????????????????????????
Host: api.samsara.com

tariqpervez
Regular Visitor

I have a similar situation where I am trying to extract distance data of fleets through Fleet company's web API service. I am done with API authentication from where I got a ClientID, UserID & Token. Now using this information, I am trying to make  API calls from power bi. Below are the snapshots of steps which I followed; 

tariqpervez_0-1647387222245.png

when the API call completes it shows null in data and an error

tariqpervez_1-1647387269345.png

I have further expanded the error below. It says that "TotalDistance" property in "Distance" report cannot be set to a System.Decimal value it should be set to a non-null value of type System.Double

tariqpervez_2-1647387330638.png

apart from this, I have tried making calls from their web API service portal and it runs fines and gives responses in JSON. Below is the snapshot of that 

 

tariqpervez_3-1647387582595.png

 

tariqpervez_4-1647387592853.png

 

Please provide your valuable feedback on this problem.

Anonymous
Not applicable

Hi, 

 

Your solution worked for me too (put "Authorization" as header parameter and then "Bearer [Bearer_key]" as value.

 

But how can i setup a daily update when i publish my report ? Where do i put the bearer token ?

Icey
Community Support
Community Support

Hi @jayhawk ,

 

Sorry, I don't know much about API. Hope these documents can help you:

Connecting Power BI with API;

Integration with Power BI.

 

 

Best Regards,

Icey

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

I am also struggling to connect to the same API using Power BI

 

I’ve followed the Samsara API Call documentation from here: https://developers.samsara.com/docs and attempted the following ‘First API Call’ Curl instructions but using Microsoft Power BI Desktop.

 

curl --request GET \

  --url https://api.samsara.com/fleet/drivers \

  --header 'Accept: application/json' \

  --header 'Authorization: Bearer {access_token}'

API_1.png

 

The next menu asks for the Key and here I have used the API token again.

I get the message 'An API key value wasn't specified'

API_2.png

Please can anyone help me with this? Samsara have been unable to assist with the Power BI side of things.

@Anonymous Here ya go.  You should be good to go bud.  

1.png

Right click on the work List. 2.png

Right click on the work List again. 

3.png4.png5.png

Thanks!  This worked out perfectly!  I am not sure why nobody has marked this as a solution.

 

That first screenshot is the solution as of this date!

Anonymous
Not applicable

Hey, thank you for helping so quick and also including how to drill down in to the table.

 

I've tried following your screenshots but I'm lost again as it asks me to authenticate again.

API1_Jay.png

Clicking OK brings up this, I've gone for 'Web API' but this may not be right.

API2_Jay.png

I've also tried various iterations of the API Token, taking out the 'samsara_api_' part et., but no luck. I must be doing something else wrong!

API3_Jay.png

@Anonymous ....looks like that's all correct.  Have you tried making a call in Postman yet?  Let me know.  

 

Anonymous
Not applicable

Hi! I'm in! Samsara support just got back to me. The link for us on this side of the pond must be https://api.eu.samsara.com

Thanks Again for your help.

 

So, just for the record:

Working Samsara API Connection.png

Then select Anonymous in the next section. 

API Anonymous.png

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.