Document creation of services via REST API (BB-5351)

Issue #4574 closed
Chris Reid
created an issue

Allow creation of repository services via the REST API.

Comments (15)

  1. Marcus Bertrand staff

    Can you specify whether you want to enable services or create them? If you meant create, can you give me a bit more information about the how and what you'd like to see?

  2. Chris Reid reporter

    Well it would be nice to do both. Really I just need a simple way to automate creating a POST service for each of my repositories. This way I can automate the creation of a repo, as well as any other services that it may be connected to.

    I figured the REST API would be the best place for that.

  3. Chris Reid reporter

    Hey Brad,

    The specific example I have the code working with is a bit convoluted, but below is an example of some code that should get you going in the right direction:

    // some basic variables
    $user = "myuser";
    $pass = "mypass";
    $project_FullName = "My Dynamically Created Repository";
    $project_description = '';
    $project_DomainName = "";
    $owner = 'myuser';
    // project "fields"
    $fields = array(
        'name' => $project_FullName,
        'description' => $project_description,
        'language' => 'php',
        'website' => 'http://'.$project_DomainName,
        'scm' => 'hg',
        'owner' => $owner,
        'is_private' => '1',
    // url to POST to
    $url = "";
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_USERPWD, "$user:$pass");
    //curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    // these two lines are really the ticket ;)
    curl_setopt($ch, CURLOPT_POST, TRUE);
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($fields));
    $result = curl_exec($ch);
    $http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    if ($result === FALSE || $http_status != '200')
        // Uho!
        log_error($result, "There was an error creating the repository on bitbucket!");
    // process the returned json
    $json = json_decode($result);
    log($json, "Sucess!");
    // proceed with the rest of the tasks
  4. suwat bodin

    Since it is not documented, can we assume this services api will be supported officially (at the minimum similar to other documented apis)? Otherwise, is it like that it will be removed or changed?

  5. Log in to comment