How to get contents of a sub directory in a Gitlab repository using Gitlab API (with PHP curl) -


i trying list of repository contents using gitlab api repository subdirectory.

because top level access working fine, i'm assuming issue not authorization or general approach, url , parameters being passed subdirectory. or perhaps documented unimplemented feature of gitlab api.

for example, using php , curl get, following url works top level list of files , folders:

the api doc says:

get /projects/:id/repository/tree 

and url works ok curl function:

https://gitlab.com/api/v3/projects/username%2fprojectname/repository/tree 

(the username%2fprojectname %2f found in gitlab thread. appears docs mean id)

for clarifcation, snipppet of working code top level list of contents is:

$url = "https://gitlab.com/api/v3/projects/username%2fprojectname/repository/tree"; $ch = curl_init($url); 

so sub directory access, api docs list paramters:

id (required) - id of project
path (optional) - path inside repository. used contend of subdirectories
ref_name (optional) - name of repository branch or tag or if not given default branch

so based on this, tried each of following url curl_init command above:

$url = "https://gitlab.com/api/v3/projects/username%2fprojectname/repository/tree?path=subdirectory"; 

this returns empty string. in case missing something, tried each of following:

$params = array( 'path' => subdirectory);  $url = "https://gitlab.com/api/v3/projects/username%2fprojectname/repository/tree . "?" . http_build_query($params);  $url = "https://gitlab.com/api/v3/projects/username%2fprojectname/repository/tree . "?" . urlencode(http_build_query($params));  $url = "https://gitlab.com/api/v3/projects/username%2fprojectname/repository/tree . "%3f" . urlencode(http_build_query($params)); 

but of these return empty string gitlab api. not error, empty string.


for reference, existing issues did not help:

how subfolders , files using gitlab api

how access source code files , list directories using gitlab api?

neither answer more available in current docs or give concrete examples of working solution.

ok, problem solved doing 1 or both of following (i'm not sure 1 solved it):

  • added ssh key

  • used project id rather namespace/projectname in url.

then ?path=subdirectory&ref_name=master on url (as in question), worked.


Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -