GitHub GraphQL API v4 vs REST API v3 - api

Is it possible to list all github's organizations with GitHub GraphQL API v4 like we did with REST API v3 ?
Follow a limited sample call :
$ curl https://api.github.com/organizations?since=32358551
[
{
"login": "NxtReader",
"id": 32358576,
"url": "https://api.github.com/orgs/NxtReader",
"repos_url": "https://api.github.com/orgs/NxtReader/repos",
"events_url": "https://api.github.com/orgs/NxtReader/events",
"hooks_url": "https://api.github.com/orgs/NxtReader/hooks",
"issues_url": "https://api.github.com/orgs/NxtReader/issues",
"members_url": "https://api.github.com/orgs/NxtReader/members{/member}",
"public_members_url": "https://api.github.com/orgs/NxtReader/public_members{/member}",
"avatar_url": "https://avatars3.githubusercontent.com/u/32358576?v=4",
"description": null
},
{
"login": "fokkmandag",
"id": 32358602,
"url": "https://api.github.com/orgs/fokkmandag",
"repos_url": "https://api.github.com/orgs/fokkmandag/repos",
"events_url": "https://api.github.com/orgs/fokkmandag/events",
"hooks_url": "https://api.github.com/orgs/fokkmandag/hooks",
"issues_url": "https://api.github.com/orgs/fokkmandag/issues",
"members_url": "https://api.github.com/orgs/fokkmandag/members{/member}",
"public_members_url": "https://api.github.com/orgs/fokkmandag/public_members{/member}",
"avatar_url": "https://avatars2.githubusercontent.com/u/32358602?v=4",
"description": null
}
]

You can use a search query with type:org as SearchResultItem can hold an Organization object :
{
search(first: 100, type: USER, query: "type:org") {
userCount
pageInfo {
hasNextPage
endCursor
}
edges {
node {
... on Organization {
login
name
description
}
}
}
}
}
For the pagination, you can get the next request with after param as the last endCursor value if hasNextPage is true, like :
search(after: "Y3Vyc29yOjEwMA==", first: 100, type: USER, query: "type:org")

Related

PowerBI Create Dataset from a Postgresql datasource using REST API

I created a datasource behind gateway for using rest API. Datasource got created. However, now I want to add a table(create a dataset) from the created datasource to use it in a report. However, I am getting the below error from API.
{
"error": {
"code": "FailedToDeserializeDatasetError",
"pbi.error": {
"code": "FailedToDeserializeDatasetError",
"parameters": {},
"details": [],
"exceptionCulprit": 1
}
}
}
API request body:
{
"datasources": [
{
"gatewayId":"gateway_id",
"datasourceId": "datasource_id",
"datasourceType": "PostgreSql",
"connectionDetails": "{\"server\":\"server_address\",\"database\":\"database_name\"}",
"credentialType": "Basic",
"credentialDetails": {
"privacyLevel": "None",
"useEndUserOAuth2Credentials": false
}
}
],
"defaultMode": "Push",
"name": "API DS 1",
"tables": [
{
"name":"currency_rates",
"description": "DS Table 1 Demo API",
"columns":[
{
"name":"id",
"dataType":"Int64"
},
{
"name":"traded_on",
"dataType":"DateTime"
},
{
"name":"currency_code",
"dataType": "string"
},
{
"name":"close",
"dataType": "Double"
}
]
}
]
}
Not sure what is wrong here.
API Reference: https://learn.microsoft.com/en-us/rest/api/power-bi/push-datasets/datasets-post-dataset-in-group

SQL Server stored procedure in .NET Core 6 Web API to produce JSON data used in Angular app

I have a SQL Server stored procedure that has an ID parameter and returns a string in JSON format that is needed in the Angular app.
Here is a sample of the JSON needed:
[
{
"type": "date",
"name": "asofdate",
"ui":
{
"label": "As Of Date",
"placeholder": "Enter a date"
},
"validators": { "required": "true" }
},
{
"type": "select",
"name": "scope",
"ui": { "label": "Scope", "placeholder": "Select a scope" },
"validators": { "required": "true" },
"source": [
{ "value": 1, "text": "ABC" },
{ "value": 2, "text": "CDE" },
{ "value": 3, "text": "FGI" }
]
}
]
Here is a what the result of running the stored procedure looks like:
When I run the Web API passing the ID parameter to the stored procedure, I would like to capture the response as a JSON object to be used in the Angular app.
But the Web API is returning this:
[
{
"jsonResponse": "[
{
\"type\":\"date\",
\"name\":\"asofdate\",
\"ui\":{\"label\":\"As Of Date\",\"placeholder\":\"Enter a date\"},
\"validators\":{\"required\":\"true\"}
}
,
{
\"type\":\"select\",
\"name\":\"scope\",
\"ui\":{\"label\":\"Scope\",\"placeholder\":\"Select a scope\"},
\"validators\":{\"required\":\"true\"},
\"source\":[{\"value\":1,\"text\":\"ABC\"},{\"value\":2,\"text\":\"DEF\"},{\"value\":3,\"text\":\"GHI\"}]}
}
]
Is there a way to get the JSON response from the Web API without all the "\" and without:
{
"jsonResponse": "
so that it matches the sample above?
Here is the code from the Web API:
[HttpGet("{ReportID}")]
public async Task<ActionResult<IEnumerable<usp_ReportParameterResult>>> GetReportParameters(int ReportID)
{
if (_context.usp_ReportParameterAsync == null)
{
return NotFound();
}
var op = new OutputParameter<int>();
var JSONresponse = await _context.usp_ReportParameterAsync(ReportID, op);
if (JSONresponse == null)
{
return NotFound();
}
return JSONresponse;
}
The stored procedure uses JSON_QUERY and JSON PATH to create the needed nested arrays.
So, in the angular code I have the following hard-coded:
TESTDATA:any[] = [
{
type:'text',
name:'firstName',
validators:{
required:true
},
ui:{label:'First Name',placeholder:'Enter Your First Name'}
}
,
{
"type":"date",
"name":"asofdate",
"ui":{"label":"****As Of Date","placeholder":"Enter a date","class":["date-picker-wrapper"]},
"validators":{"required":"true"}
}
]
What I need is instead of this data being hrad-coded it is being dynamically generated from a Web API.
The hard-coded data looks like the following from browser debug:
[![enter image description here][2]][2]
From the web api data looks like the following:
It is not an array like the TESTDATA. Is the a way to get response from web api into an array format as required?
Actually, easiest solution was to remove the backlashes in the Angular app by simply doing the following:
for (let item of this.formattedJSON) {
item.ui = JSON.parse(item.ui);
item.validators = JSON.parse(item.validators);
}

GraphQL query - Query by ID

I have installed the strapi-starter-blog locally and I'm trying to understand how I can query article by ID (or slug). When I open the GraphQL Playground, I can get all the article using:
query Articles {
articles {
id
title
content
image {
url
}
category {
name
}
}
}
The response is:
{
"data": {
"articles": [
{
"id": "1",
"title": "Thanks for giving this Starter a try!",
"content": "\n# Thanks\n\nWe hope that this starter will make you want to discover Strapi in more details.\n\n## Features\n\n- 2 Content types: Article, Category\n- Permissions set to 'true' for article and category\n- 2 Created Articles\n- 3 Created categories\n- Responsive design using UIkit\n\n## Pages\n\n- \"/\" display every articles\n- \"/article/:id\" display one article\n- \"/category/:id\" display articles depending on the category",
"image": {
"url": "/uploads/blog_header_network_7858ad4701.jpg"
},
"category": {
"name": "news"
}
},
{
"id": "2",
"title": "Enjoy!",
"content": "Have fun!",
"image": {
"url": "/uploads/blog_header_balloon_32675098cf.jpg"
},
"category": {
"name": "trends"
}
}
]
}
}
But when I try to get the article using the ID with variable, like here github code in the GraphQL Playground with the following
Query:
query Articles($id: ID!) {
articles(id: $id) {
id
title
content
image {
url
}
category {
name
}
}
}
Variables:
{
"id": 1
}
I get an error:
...
"message": "Unknown argument \"id\" on field \"articles\" of type \"Query\"."
...
What is the difference and why can't I get the data like in the example of the Github repo.
Thanks for your help.
It's the difference between articles and article as the query. If you use the singular one you can use the ID as argument

How to change the example values for api requests in Swagger UI?

I'm making an API for a site and I'm using Swagger UI, I currently have a route for adding a favorite for a user the route is "/users/{id}/favorites/", and the params in the spec are:
"parameters":[
{
"in":"path",
"name":"id",
"description":"User's Id",
"required":true,
"schema":{
"$ref":"#/definitions/User"
}
},
{
"in":"body",
"name":"body",
"description":"Enter user's id and video id for favorite",
"required":true,
"schema":{
"$ref":"#/definitions/Favorite"
}
}
],
The definition for the favorites model in the spec looks like this:
"Favorite":{
"type":"object",
"properties":{
"id":{
"type":"integer",
"format": "int64"
},
"userId":{
"$ref":"#/definitions/User/properties/id"
},
"videoId":{
"$ref":"#/definitions/Video/properties/id"
}
},
"xml":{
"name":"Flag"
}
}
But currently when I go the /api route the example value being shown for the body param is
{
"id": 0
}
on the docs it displays an almost correct request sample correctly and shows:
{
"id": 0,
"userId": 0,
"videoId": 0
}
How do I change the example value for the /api route to show
{
"userId": 0,
"videoId": 0
}
as an example and how do I remove the id param from the example on the doc
Found a way to do it, not sure if this is the best way but I just changed the definition and made userId an int instead of a $ref and the same for videoId.

Facebook API (javascript) getting latest school education info

I'm very new to the facebook api for my website, and I am using the javascript sdk. I want to get the users latest school information, including school name, course and year of study. This is what I have so far but it breaks the login script and returns 'response.education.school is undefined'. I'm guessing I'll need some kind of for loop to go through the education array as most users have more than one school listed?
function login() {
FB.login(function(response) {
if(response.authResponse) {
// connected
FB.api('/me', function(response) {
fbLogin(response.id, response.name, response.firstname, response.email,
response.education.school.name, response.education.concentration.name, response.education.year.name);
});
} else {
// cancelled
}
}, {scope: 'email, user_education_history, user_hometown'});
}
response.education.school is undefined
This is because responce.education is an array of objects. This would be an example for me (actual information removed)
"education": [
{
"school": {
"id": "",
"name": ""
},
"year": {
"id": "",
"name": ""
},
"concentration": [
{
"id": "",
"name": ""
}
],
"type": ""
},
...
]
You need to iterate over it and process each educaional step e.g.
for(ed in response.education) {
var school = response.education[ed].school;
var schoolName = school.name;
...
}
And so on; you are currently passing an aobject structure to your fbLogIn that can't handle it. If you want the latest school education, you simply pick the one that has the most recent year.name value.