Search code examples
githubpostmangithub-api-v3

How to do a source import with GitHub APIv3


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


Solution

  • 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.