Getting TFS dashboard widget ID with REST API call - javascript

I want to get the id of a widget, because I need to pass it to a web service when the user saves the configuration. I have found out, there is a REST API service for this.
If I enter the following URL in my browser (substituting specific info in the brackets of course):
https://{account}.VisualStudio.com/DefaultCollection/{project}/{teamId}/_apis/dashboard/dashboards/{dashboardId}/widgets/{id}?api-version={version}
it works fine, however I get an HTTP 401 (Unauthorized) error when I try to make an ajax get request from the javascript code of the widget.
Any ideas?

You can try to create a personal access token and use it in your code.
Useful articles:
https://www.visualstudio.com/en-us/docs/setup-admin/team-services/use-personal-access-tokens-to-authenticate
https://www.visualstudio.com/nl-nl/docs/integrate/get-started/rest/basics

401 HTTP status means that you either are not authenticated with the API or are not authorized to perform a particular operation. TFS Rest API from what I can see allows two types of authentication:
Basic
OAuth
The documentation of the API at https://www.visualstudio.com/en-us/docs/integrate/extensions/overview explains it quite well and provides CURL commandline examples. Go and have a look.

Related

Google API get reviews for my business using java script

I am trying to get google reviews for my business but struggling with implementing it. Can someone share how to get the latest/top 5 reviews using google business API using JavaScript/Postman? I was trying to do so:
GET:
https://accounts.google.com/o/oauth2/auth?client_id=MY_CLIENT_ID.apps.googleusercontent.com&client_secret=MY_CLIENT_SECRET&scope=https://www.googleapis.com/auth/business.manage&response_type=token&redirect_uri=https://developers.google.com/oauthplayground
but it doesn't work.
Was trying also testing it on Google oauth playground
filling:OAuth flow: Client-side
Use your own OAuth credentials: my Client ID here
Step 1:
Authorize API: https://www.googleapis.com/auth/plus.business.manage
but here I am getting:
Error 400: redirect_uri_mismatch
The redirect URI in the request, https://developers.google.com/oauthplayground, does not match the ones authorized for the OAuth client. To update the authorized redirect URIs, visit: https://console.developers.google.com/apis/credentials/oauthclient/938304287177-nkvm5mqk3f5uq9lt9j2srqlgd0bjihip.apps.googleusercontent.com?project=938304287177
The redirect uri in your project on Google cloud console must exactly match the redirect uri you are sending from The easiest solution is to go to your project and add it.
https://developers.google.com/oauthplayground
Which is not the same as as you have an extra slash on the end
https://developers.google.com/oauthplayground/
This video will walk you though it. Google OAuth2: How the fix redirect_uri_mismatch error.
Question from Comments
how can I get the reviews using just API key without a need to authorize it using gmail account?
If you check the documentation Method: accounts.locations.reviews.list you will find that it says the following
API keys only allow you to access public data, the data you are trying to access is private user data and therefore requires authorization in order to access it. You can not use an API key to access this data you must be authorized using one of the above scopes. A video which explains api keys. Everything you need to know about Google API Key's, and where to get one.

Is it possible to get a list of users from Directory API using only api key in a string?

I keep getting in to a loop of only seeing google's OAUTH documentation when searching for this but I don't want any user interaction. Maybe it's not possible. I want to do something like the code below in a http GET like you do with the maps API and receive a JSON reply
https://www.googleapis.com/admin/directory/v1/users?domain=MYDOMAIN&maxResults=200&key=MYAPIKEY
When I try something like the above I get 401 login required. I'm using vue-resource to make the request if that is relevant.
If it is possible could someone post an example of a correctly formatted request?
Based on the documentation available at https://developers.google.com/admin-sdk/directory/v1/guides/manage-users you should be able to do this with a simple get request however it MUST be authorized with OAUTH 2.
As stated at https://developers.google.com/admin-sdk/directory/v1/guides/authorizing "Your application must use OAuth 2.0 to authorize requests. No other authorization protocols are supported."
I haven't used vue-resource before however I know that the Chrome plugin Postman has an authorization option to target OAUTH2.0 which should be a good place to start and perform a quick proof of concept.
Once you have the proof of concept working and understand how to interact with OAUTH you can look at implementing it in your app.

Get exchange calendar events in javascript webapp?

I find the documentation provided by microsoft confusing(Link).
How can I for example get an authentication token and where can I download the javascript libraries? I couldn't find any information on this.
Basically I want to know how to get the calendar of an user in my javascript webapp.
I did try sending an request to
"https://outlook.office365.com/api/v1.0/me/calendarview?startDateTime="+begin+"&endDateTime="+end"
This shows me an authentication popup but after submitting the correct username/mail and password, it doesn't do anything. There is no response back.
To get an access token, you need to use the OAuth2 Authorization Code Grant flow. https://dev.outlook.com/RestGettingStarted walks through the process. Basically you need to register your app to get a client ID and secret, then use those to go through the process.

Google OAuth - Authenticate using Javascript Frontend and Server Backend (Authorization Code Flow)

I am implementing Google authentication into my JavaScript web application. I would like to use the authentication code flow as described here.
What I want to do is...
User clicks a button and gets presented with the consent screen
He clicks "allow" and I get back the authorization code
I send the authorization code to my rest backend in order to exchange the authorization code to a access_token
The first 2 parts working perfectly as expected but I cant get 3. to work.
I call https://www.googleapis.com/oauth2/v3/token from my backend posting the code, client_id, client_secret, redirect_uri and grant_type (authorization_code). This works well, I checked it with fiddler (a web debugging tool). However I always get unauthorized_client as a result.
Any ideas?
After a lot of testing and reading i finally got it.
Even if i perform a POST request to get the access token in my backend i need to pass in the parameters (client_id, client_secret, etc...) with the query string NOT the body.
I need to provide the same redirect_uri in both requests (getting the code and getting the access_token)
Now it works great.

Listing analytics for Goo.gl's url shortening API

I've been digging through Google's docs on its url shortener API, but to no avail.
I'm trying to avoid using oAuth and just javascript to list the statistics.
In theory, it should be possible to list statistics for all urls shortened with a specific API key, but I get a status of 401 (Unauthorized)
Can anyone tell me if this is possible — or how I could list all url shortened stats for a specific domain, using just JS and an API key as authorisation?
Sample request:
https://www.googleapis.com/urlshortener/v1/url/history?key=myAPIkey&start-token=10&projection=FULL
Documentation:
https://developers.google.com/url-shortener/v1/url/list
The API documentation says: "This request requires authorization with at least one of the following scopes (read more about authentication and authorization)." When you follow the link to read more, it says:
If the request requires authorization (such as a request for an individual's private data), then the application must provide an OAuth 2.0 token with the request. The application may also provide the API key, but it doesn't have to.
So, you need to provide OAuth tokens to use the url/list resource (but not url/get, so have a look at that).

Categories

Resources