How to do a source import with GitHub APIv3 - github

background:
I am trying to build an application that will copy a public repository to the logged in account.
Now i am trying to do a source import in PostMan and i am using the following settings:
i make a PUT request to this link:
https://api.github.com/repos/{myusername}/{empty github repository}/import
with the following header:
Accept:application/vnd.github.barred-rock-preview
With this body:
{
"vcs": "git",
"vcs_url": "https://github.com/{owner of repo i want to copy}/{repo i want to copy}",
"vcs_username": "{myusername}",
"vcs_password": "{mypassword}"
}
I have read the github API for importing repositories. But i am getting the following response from the server:
{
"message": "Not Found",
"documentation_url":
"https://developer.github.com/v3/migrations/source_imports/#start-an-import"
}
Why does the server return a Not Found? How do i get this to work

It need Authentication else will get 404 Not Found
using username and password for authentication
Put URL:
https://{myusername}:{mypassword}#api.github.com/repos/{myusername}/{myreponame}/import
Request Body
{
"vcs": "git",
"vcs_url": "https://github.com/{ownerRepo}/{ownerRepoName}"
}
vcs_username and vcs_password used for remote repo not yours.

Related

GitHub - URL could not be accessed: HTTP/1.1 400 Bad Request

I am using a private repository in my project ( for example https://github.com/org/repo), and recently I am getting the below error message when I trying to run composer install.
[Composer\Downloader\TransportException]
The 'https://api.github.com/repos/org/myrepo' URL could not be accessed: HTTP/1.1 400 Bad Request
You have to update your auth.json file. Please go to Settings > Developer settings > Personal access tokens (Direct URL: https://github.com/settings/tokens) page and generate a new token and copy the token string then enable sso and authorise with your private organisation. Update your auth.json like below format.
{
"http-basic": {
"github.com": {
"username": "<YOUR-USERNAME>",
"password": "<NEW_TOKEN>"
}
}
}

"Preflight response is not successful" in Apollo Server running on GitHub Codespaces

I followed the Apollo Getting Started example in a Github Codespace.
Upon starting the server, I see the error:
{
"error": "Preflight response is not successful"
}
Sample repo to reproduce is here: https://github.com/anishkny/codespaces-test
I tried various options for cors but it did not work:
...
new ApolloServer({ typeDefs, resolvers
cors: {
"origin": "*",
"methods": "GET,HEAD,PUT,PATCH,POST,DELETE",
"preflightContinue": false,
"optionsSuccessStatus": 204
}
});
...
I had this same issue. It turns out that Playground is not forwarding your Github credentials. Notice that if you visit the preview URL in an incognito window, you are redirected to the Github login screen. The solution is to change Playground settings so that your credentials are sent in GraphQL requests.
Click the top right corner, click the gear icon (settings)
Change the following
- "request.credentials": "omit",
+ "request.credentials": "same-origin",

How to use github api from postman

i want to create a file on my github account using github api through postman.
github api to create a file on github account:
PUT /repos/:owner/:repo/contents/:path
can anyone tel me how to use this api in postman.
i have my public github account : https://github.com/ritzygithub/myfirstRepo
and in postman header i set
Authorization type to OAuth 2
Authorization : token <token>
PUT request with url: https://api.github.com/repos/ritzygithub/myfirstRepo/
Can you please help me out in this
i just figured it out.. posting my answer here so that if anyone is facing same issue then this can help them.
In postman, set as PUT request with below URL
https://api.github.com/repos/YourUsername/YourRepo/contents/file.txt
Add Body:
{
"message": "my commit message",
"committer": {
"name": "My name",
"email": "my email"
},
"content": "base64encoded"
}
Header:
Content-Type : application/json
Authorization : token
Refer below Screenshot:
Hope this helps.
Thanks

HTTP 401 error message when I try with private enterprise Github account

I am working with python + the requests library + github access to get a hook URL.
When I try to access a hook from my personal public git repo, I get the response smoothly:
import json
import requests
token = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
response = requests.get("https://api.github.com/repos/josenrihernand/github-personal-repo/hooks", auth=("josenrihernand", token)).json()
print("RESPONSE: ", response) ---> IT WORKS (I get the hook url)
However, if I try with a enterprise / private github account, I get an HTTP 401 error message:
import json
import requests
token = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
response = requests.get("https://MY_DOMAIN/repos/ENTERPRISE_USER/REPO_PATH/hooks", auth=("ENTERPRISE_USER", token)).json()
print("RESPONSE: ", response) ---> I got a 401 error message.
I am sure that the token is ok.
What could be the root cause of that error ?
Is the get address properly formed ?
thanks a lot!
Github entreprise base URL for v3 API is :
http(s)://hostname/api/v3/
check Rest v3 API doc
I guess in your case it would be :
https://your.domain/api/v3/repos/USER/REPO/hooks

How to share file with room in HipChat via Postman or Jersey client?

Please provide the solution for this (I am new to jersey and postman). I tried with below link but unable to share the file: https://www.hipchat.com/docs/apiv2/method/share_file_with_room
I attached screen shots, which I tried from postman.
Note: I used API access token with send message scope.
I am getting below error as response:
{
"error": {
"code": 400,
"message": "No file was found in the request. See https://www.hipchat.com/docs/apiv2/method/share_file_with_room for an example",
"type": "Bad Request"
}
}