I have a project where I need to retrieve all the issues from a repo. I've been practicing with the atom repository and I am using the GitHub API.
I use axios get function and the request I'm making is the following.
axios.get('https://api.github.com/repos/atom/atom/issues',
{
headers: { 'Accept': 'application/vnd.github.VERSION.raw+json' },
params: {'state': 'all'}
})
.then((response) => {
console.log(response);
})
.catch((error) =>{
console.log(error);
});
But there are 772 issues and it is only retrieving 30 issues.
How can I retrive them all? am I missing something in the header or the params.
Ive also tried without params and the header. And also adding filter: all to the params and I still get 30 issues.
Thanks in advance.
Related
I'm trying to fetch an image resource that's part of a conversation message.
I've tried both FETCH as well as using AXIOS but I'm getting the same error message.
Here's an example of my FETCH request
const token = `${accountSid}:${authToken}`;
const encodedToken = Buffer.from(token).toString('base64');
let response = await fetch('https://mcs.us1.twilio.com/v1/Services/<SERVICE_SID>/Media/<MEDIA_SID>',
{
method:'GET',
headers: {
'Authorization': `Basic ${encodedToken}`,
}
});
let data = await response.json();
console.log(data);
And here's what Axios looked like
let config = {
method: 'get',
crossdomain: true,
url: 'https://mcs.us1.twilio.com/v1/Services/<SERVICE_SID>/Media/<MEDIA_SID>',
headers: {
'Authorization': `Basic ${encodedToken}`,
},
};
try {
const media = await axios(config);
console.dir(media);
} catch(err) {
console.error(err);
}
Both ways are NOT working.
After looking into it more, I found out that Chrome makes a pre-flight request and as part of that requests the allowed headers from the server.
The response that came back was this
as you can see, in the "Response Headers" I don't see the Access-Control-Allow-Headers which should have been set to Authorization
What am I missing here?
I have made sure that my id/password as well as the URL i'm using are fine. In fact, I've ran this request through POSTMAN on my local machine and that returned the results just fine. The issue is ONLY happening when I do it in my code and run it in the browser.
I figured it out.
I don't have to make an http call to get the URL. It can be retrieved by simply
media.getContentTemporaryUrl();
I am currently working on a simple GitHub GraphQL client in NodeJS.
Given that GitHub GraphQL API is accessible only with an access token, I set up an OAuth2 request to grab the access token and then tried to fire a simple GraphQL query.
OAuth2 flow gives me the token, but when I send the query, I get HTTP 422.
Here below simplified snippets from my own code:
Prepare the URL to display on UI side, to let user click it and perform login with GitHub
getGitHubAuthenticationURL(): string {
const searchParams = new URLSearchParams({
client_id,
state,
login,
scope,
});
return `https://github.com/login/oauth/authorize?${searchParams}`;
}
My ExpressJs server listening to GitHub OAuth2 responses
httpServer.get("/from-github/oauth-callback", async (req, res) => {
const {
query: { code, state },
} = req;
const accessToken = await requestGitHubAccessToken(code as string);
[...]
});
Requesting access token
async requestToken(code: string): Promise<string> {
const { data } = await axios.post(
"https://github.com/login/oauth/access_token",
{
client_id,
client_secret,
code
},
{
headers: {
"Content-Type": "application/json",
Accept: "application/json",
},
}
);
return data.access_token;
}
Firing simple graphql query
const data = await axios.post(
"https://graphql.github.com/graphql/proxy",
{ query: "{ viewer { login } }"},
{
headers: {
Authorization: `Bearer ${accessToken}`,
"Content-Type": "application/json",
},
}
);
Do you guys have any clue?
Perhaps I am doing something wrong with the OAuth2 flow? As in most of the examples I found on the web, a personal token is used for this purpose, generated on GitHub, but I would like to use OAuth2 instead.
Thanks in advance for any help, I really appreciate it!
EDIT
I changed the query from { query: "query { viewer { login } }"} to { query: "{ viewer { login } }"}, nonetheless, the issue is still present.
I finally found the solution:
Change the URL from https://graphql.github.com/graphql/proxy to https://api.github.com/graphql, see here
Add the following HTTP headers
"Content-Type": "application/json"
"Content-Length"
"User-Agent"
Hope this will help others out there.
I am creating a spreadsheet to help me quickly shorten UTM parameters for ad campaigns. I want to be able to dynamically add tags to the query string so that they are easier to organize once they are created in Bitly. Here is what I have tried in Google Sheets.
=importData(concatenate("https://api-ssl.bitly.com/v3/shorten?tags[]=test&tags[]=new&longUrl=",ENCODEURL(J10),"&access_token=",$C$5,"&format=txt"))
It kicks back a URL and works perfectly, except it does not add the tags. Just not sure what I am missing.
Link to copy, just add bitly API key:
https://docs.google.com/spreadsheets/d/1OB4CaA-P-dXpRsDXjdTzLkNKHWGPjkzWOxo3n-Iv6ao/edit?usp=sharing
To further explain my end result... you will notice my "tags" parameter in the URL. I want that to be pushed into the Bitly API and create/add those tags to the newly created URL. This will give me the ability to better filter them for use.
Even though the docs says you can, it seems like it is not possible to create the link with tags. Even the Bitly UI does not support it.
It is possible to do an update and add the tags.
I created the bitlink and then right after I did another request to updated it with the tags.
Update API: PATCH:https://api-ssl.bitly.com/v4/bitlinks/{bitlink.id}
This is what I did:
fetch("https://api-ssl.bitly.com/v4/shorten", {
method: "POST",
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ***'
},
body: JSON.stringify(data)
}).then(response => response.json())
.then(data => {
let updateData = {
"tags": [
"tag1",
"tag2"
]
};
fetch("https://api-ssl.bitly.com/v4/bitlinks/" + encodeURIComponent(data.id), {
method: "PATCH",
headers: {
'Content-Type': 'application/json',
'Authorization': '***'
},
body: JSON.stringify(updateData)
})
});
}
try this:
=IMPORTDATA("https://api-ssl.bitly.com/v3/shorten?tags[]=test&tags[]=new&longUrl="&ENCODEURL(J10)&"&access_token="&$C$5&"&format=txt")
I'm working on a web app with React on Express with a Postgresql database, and am working on trying to allow users the ability to delete/update their profiles. I've updated the controller, model, and routes for these changes, but I'm having an issue figuring out where to send the fetch request from the React component. Anytime I try to run a delete or an update I get the following on my terminal:
PUT /api/auth/1 400 3.468 ms - 24
--- undefined /robots.txt
I checked other threads on here and wasn't able to find how I can determine what URL I should point to for these functions. I think once I get that it should work as intended. Below are my auth routes and the functions I have set up, if anybody could suggest how I'd determine what URL to point this to I'd really appreciate it.
// handle profile update/delete
authRouter.route('/dashboard')
.get(usersController.show)
.put(usersController.update)
.delete(usersController.delete)
User Update/Delete functions:
handleUpdateSubmit(e, data, id) {
e.preventDefault()
console.log('clicked')
fetch(`/api/auth/${id}`, {
method: 'PUT',
credentials: 'include',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(data),
}).then(res => res.json())
.then(res => {
this.setState({
fireRedirect: true,
redirectPath: '/dashboard'
})
}).catch(err => console.log(err))
}
userDelete(id) {
fetch(`/api/auth/${id}`, {
method: 'DELETE',
}).then(res => res.json())
.then(res => {
this.setState({
fireRedirect: true,
redirectPath: '/'
})
}).catch(err => console.log(err))
}
Please let me know if there's any information that'd be useful for figuring this out and I'll provide it immediately, thanks!
Forgot to follow up on this, the issue was with how my functions were ordered. I moved my authrouter.Route code beneath the login/logout/register functions and it's working as expected.
I am trying to call Yammer REST API for getting authenticated user's information using the following code:
$(document).ready(function() {
$.ajax({
method: "GET",
url: "https://www.yammer.com/api/v1/users/current.json",
contentType: "application/json; charset=utf-8",
dataType: 'json',
success: function(data) {
if (data.Success) {
alert(data);
}
},
error: function(xhr2, status2) {
alert(xhr2.status);
}
});
});
However, it is always going to error method. Can anyone guide me to proceed on this piece?
You're not sending the API any authentication information, so how does it know what user it's supposed to be pulling down? You should take a look at the Javascript SDK.
I had the same problem. Change url from "https://www.yammer.com/api/v1/users/current.json" to "users/current.json" solves the issue (it will be going to success method)