Zendesk - How to get users based on roles? - c#

I am using Elizabeth's wrapper from https://github.com/mozts2005/ZendeskApi_v2
I want to pull a list of agents. I don't see any built in Function that will allow that.
I have tried using the endpoint of /api/v2/users.json?role=agent with the GetAllUsers() function but it still returns all of them.
Right now, I am going to add a custom field to be able to search for them, but that should not be the case, especially since Zendesk's API does have an option for returning users based on their role: /api/v2/users.json?role[]=admin&role[]=end-user
Can anyone help me out?

You can give a try to the Zendesk Search API:
from urllib.parse import urlencode
import requests
results = [] # Empty list to collect pagination results
credentials = 'your_zendesk_email', 'your_zendesk_password'
session = requests.Session()
session.auth = credentials
params = {
'query': 'type:user role:agent'
}
url = 'https://your_subdomain.zendesk.com/api/v2/search.json?' + urlencode(params)
while url:
response = session.get(url)
data = response.json()
results += data['results']
url = data['next_page'] # should return false according to the doc when the last page is reached
Useful resources:
zendesk api python tutorial
zendesk api pagination
Search endpoint seems to be supported also in the c# library you are using.

Related

Making a POST REST API call in Power Bi Query Functions to generate a token, and used that JWT based token to make another GET API Call

I have requirement to make a POST REST API call using Power Bi Query Functions to get the JWT access token. Then use the same token obtained make a GET API call to obtain data that has to be displayed in a Power Bi Dashboard.
Now the issue is, I am not able to get the first part right, to get the access token. I need to be pass the client id, client secret and resource uri as a body of the POST API to get the token.
Can anyone help me with this?
Here is a sample to get the token:
let
url = "XXXXXXXXXXXX/api/",
body =
"{""client_id"":""XXX"",""client_secret"":""XXX"",""resource_uri"":""XXXXXX""}",
Source =
Json.Document(
Web.Contents(
url,
[
Headers = [#"Content-Type"="application/json"],
Content=Text.ToBinary(body)
]
)
)
in
Source
After getting the token with the above query, you can use it in another query to make the 2nd call and get the actual data.
This is how it ultimately worked for me:
let
GetJson = Web.Contents("https://login.microsoftonline.com/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx/oauth2/token",
[
Headers = [# "Accept" = "application/json",
# "Content-Type" = "application/x-www-form-urlencoded;charset=UTF-8"
],
Content = Text.ToBinary("client_id=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx&client_secret=xx***xx:/xxx?***&resource=api://xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx&grant_type=client_credentials")
]
),
FormatAsJson = Json.Document(GetJson),
# "Converted to Table" = Record.ToTable(FormatAsJson),
# "Expanded Value" = Table.Last(# "Converted to Table"),
access_token = List.Last(Record.FieldValues(# "Expanded Value")),
source = Json.Document(Web.Contents("https://my-web-api.azurewebsites.net/api/get_my_data?Num=100", [Headers = [ContentType = "application/json"]])),
Result = Json.Document(source)
in
# "Result"
Please update the required credentials/secrets/id or any relevant field to get this working. But I would request Microsoft or any Microsoft affiliated Power Bi Developer to create a more comprehensive article or document on these topics.

Returning Google My Business Information in a console application

I have tried making a console app to add a random company name onto the end of a search and then return the HTML to extract the data. I would like to get this working on a true random basis but filtering by a random company name / postcode would be a start.
When adding on the name and postcode to the search call such as "https://www.google.co.uk/search?q=argos+LS15+9JB&ie=utf-8&oe=utf-8&client=firefox-b-ab&gfe_rd=cr&ei=OKu-V_3PE5CCaN74iMAG" the html returns no confirmation if the company has a google my business account. If I inspect element I can see the google my business information but if i return the html using the below call it doesn't return the right html I am looking for, can anyone help with this?
**using(WebClient client = new WebClient()) {
string s = client.DownloadString(url);
}**
I am new to C#/ API so apologies in advance.
google uses a lot of javascript to render the search result page. instead of trying to parse the result page, check Google My Business API

Google PageSpeed API dotnet .net

I have set up a basic C# application to run a PageSpeed test on a website that I specify using the Google.Apis.Pagespeedonline.v2 nuget package.
The set up is simple enough and I have a variable that I can specify the url which is then past in to the Service
// Create the service.
var service = new PagespeedonlineService(new BaseClientService.Initializer
{
ApplicationName = "PageSpeed Sample",
ApiKey = "[API_KEY_HERE]"
});
var url = "URL_TO_TEST";
// Run the request.
var result = await service.Pagespeedapi.Runpagespeed(url).ExecuteAsync();
The problem being the .Runpagespeed method ONLY accepts URL. I need to be able to specify, at minimum, the 'Mobile' strategy so I can obtain scores for both Desktop and Mobile. I know this is possible in other libraries but seems to be missing in .NET. Is anybody aware of a way to do this using the .NET library? In the reference documentation it implies that the method accepts further optional parameters but it does not in the code.
Pagespeedapi: runpagespeed has an optional value called strategy
strategy string The analysis strategy to use
Acceptable values are: "desktop": Fetch and analyze the URL for
desktop browsers "mobile": Fetch and analyze the URL for mobile
devices
Example:
var request = service.Pagespeedapi.Runpagespeed(url);
request.Strategy = Google.Apis.Pagespeedonline.v2.PagespeedapiResource.RunpagespeedRequest.StrategyEnum.Mobile;
var results = request.Execute();

Facebook page /feed missing images

I was using the Facebook Public API Feed for the longest time and since they deprecated it I've been trying to find a replacement method in C#.
I am able to get my page posts but any post that contains images I only get the message and no images. After spending the past weekend trying to find a way I am desperate to know if anyone has had any success in getting full page post content from the Facebook C# SDK library.
Here is what I have and it works for getting the posts but they do not contain any images.
var fb = new FacebookClient
{
AppId = ConfigurationManager.AppSettings.Get("FacebookAppID"),
AppSecret = ConfigurationManager.AppSettings.Get("FacebookAppSecret"),
AccessToken = ConfigurationManager.AppSettings.Get("FacebookAccessToken")
};
var pageFeed = string.Format("/v2.4/{0}/feed", _facebookPageId);
dynamic response = fb.Get(pageFeed);
Since the upgrade in Graph API v2.4. Only a limited set of data is sent via FB unless specifically requested. You should pass the fields parameter with the keyword of data which you would like to retrieve.
A list of keyword is available here
In your case, the request statement would be:
var pageFeed = string.Format("/v2.4/{0}/feed?fields=id,message,picture", _facebookPageId);
To get all pictures from a post: replace picture with attachments, as picture will return the very first picture linked to the post.
var pageFeed = string.Format("/v2.4/{0}/feed?fields=id,message,attachments", _facebookPageId);

Get facebook feed for particular users C#

I am developing a server application that should be able to react to the amount of likes for some of the posts in the user's feed.
I need to get post from users wall.
I'm using Facebook library version 6.4.2
I use the following code to get the posts:
var apiKey = ConfigurationManager.AppSettings["apiKey"];
var secret = ConfigurationManager.AppSettings["secret"];
var client = PostHandler.CreateFacebookClient(apiKey, secret);
var get = client.Get(string.Format("/{0}/feed", pageId));
and/or (both return the same info)
var token =ConfigurationManager.AppSettings["token"];
var get = client.Get(string.Format("/{0}/feed?access_token={1}", pageId, token));
The problem is that using the same set of permissions the json returned from the request above is different from the json returned from json returned from Graph API Explorer methog GET 100000481752436/feed
In my opinion the json returned from my request is missing some posts and the one from the Geaph API all contains the posts from my feed.
Could you please advice, what could I have missed ?
If you are missing some posts in the feed it is most likely that you'll have to check the permissions set again.
Based on the type of posts you are missing you maybe have to add the user_status, user_activities, user_friends, user_checkins or user_games_activity permissions. Please make sure that you're using the correct set of the permissions for your particular task.
If you'll specify the type of the posts you are missing you may get much more helpful answers.

Categories

Resources