1. Bitbucket Website
  2. Public Issue Tracker
  3. master

Issues

Issue #8618 resolved

The owner parameter not working to the repositories endpoint on the POST request.

samuel hints
created an issue

api url : api/2.0/repositories or api/1.0/repositories

method : POST

http request body :

{"owner":"rss_samuel","repo_slug":"The last change","name":"The last change","language":"python","has_wiki":true}

http response header: HTTP/1.1 400 Bad Request.

http response body:

<ul class="errorlist"><li>owner<ul class="errorlist"><li>You can't create repositories under this account.</li></ul></li></ul>

.................................................................

I change owner parameter to accountname parameter and it working...

Comments (25)

  1. samuel hints reporter

    Hi Brodie Rao . Thanks for reply. :)

    The 1.0 repository API doesn't support POSTing JSON data. If you use form encoding, this should work.

    I don't understand your mean.

    Also note that accountname and repo_slug aren't supported field names.

    I don't have problem to accountname parameter, my problem is to owner parameter.

  2. Brodie Rao

    I don't understand your mean.

    It looks like you're uploading JSON to the API endpoint. If you upload the owner, name, etc. encoded as application/x-www-form-urlencoded data, it should work.

    I don't have problem to accountname parameter, my problem is to owner parameter.

    My point was that accountname doesn't do anything (it isn't recognized, it's just ignored).

  3. samuel hints reporter

    Bitbucket have problem to application/x-www-form-urlencoded content type, but I resolve problem to change application/x-www-form-urlencoded to application/x-www-url-form-encoded.

    Now Posting data by form encode work for me. :)

    But now I can't test issue #8618, so later I test it and report result.

  4. samuel hints reporter

    First Test

    API URL : /api/2.0/repositories/{accountname}/{repo_slug}

    Method: POST

    Content-Type: JSON

    Response: HTTP/1.1 200 OK.

    ...........................................................

    Second Test

    API URL : /api/2.0/repositories/{accountname}/{repo_slug}

    Method: POST

    Content-Type: FORM ENCODING

    Response: HTTP/1.1 500 Internal Server Error.

    Response Body:

    'NoneType' object has no attribute 'iteritems'
    File "/opt/python/domains/bitbucket.org/current/bitbucket/local/env/lib/python2.7/site-packages/piston/resource.py", line 198, in __call__ result = checked_meth(request, *args, **kwargs) File "/opt/python/domains/bitbucket.org/current/bitbucket/local/env/lib/python2.7/site-packages/piston/resource.py", line 185, in checked_meth return meth(*args, **kwargs) File "/opt/python/domains/bitbucket.org/current/bitbucket/local/env/lib/python2.7/site-packages/newrelic-2.5.0.94/newrelic/hooks/component_piston.py", line 33, in __call__ return self._nr_wrapped(*args, **kwargs) File "/opt/python/domains/bitbucket.org/2013-07-25/bitbucket/../bitbucket/apps/api/v10/decorators.py", line 384, in _inner return func(self, request, *args, **kwargs) File "/opt/python/domains/bitbucket.org/2013-07-25/bitbucket/../bitbucket/apps/repo2/api/v20/repo.py", line 33, in create data = dict(request.data.iteritems())
    

    ............................................................

    Third Test

    API URL : /api/1.0/repositories/

    Method: POST

    Content-Type: JSON

    Response Header: HTTP/1.1 200 OK.

    .............................................................

    Fourth Test

    API URL : /api/1.0/repositories/

    Method: POST

    Content-Type: FORM ENCODING

    Response Header: HTTP/1.1 500 Internal Server Error.

    Response Body :

    'NoneType' object has no attribute 'copy'
    File "/opt/python/domains/bitbucket.org/current/bitbucket/local/env/lib/python2.7/site-packages/piston/resource.py", line 198, in __call__ result = checked_meth(request, *args, **kwargs) File "/opt/python/domains/bitbucket.org/current/bitbucket/local/env/lib/python2.7/site-packages/piston/resource.py", line 185, in checked_meth return meth(*args, **kwargs) File "/opt/python/domains/bitbucket.org/current/bitbucket/local/env/lib/python2.7/site-packages/newrelic-2.5.0.94/newrelic/hooks/component_piston.py", line 33, in __call__ return self._nr_wrapped(*args, **kwargs) File "/opt/python/domains/bitbucket.org/2013-11-22/bitbucket/../bitbucket/apps/api/v10/decorators.py", line 334, in wrapper return func(*args, **kwargs) File "/opt/python/domains/bitbucket.org/2013-11-22/bitbucket/../bitbucket/apps/api/v10/handlers.py", line 1979, in create data = request.data.copy() 
    

    The 1.0 repository API doesn't support POSTing JSON data. If you use form encoding, this should work.

    Not true, It support JSON and not support FORM ENCODING on the versions 1.0 , 2.0.

  5. samuel hints reporter

    I change the content type application/x-www-url-form-encoded; to

    application/x-www-form-urlencoded; in versions 2.0 , 1.0.

    Summary

    Now in the version 2.0 it working perfect. But version 1.0 have problem yet to content type FORM ENCODING.

    Version : 1.0

    Content Type : application/x-www-url-form-encoded;

    Response Header: HTTP/1.1 500 Internal Server Error.

    Response Body:

    'NoneType' object has no attribute 'copy'
    File "/opt/python/domains/bitbucket.org/current/bitbucket/local/env/lib/python2.7/site-packages/piston/resource.py", line 198, in __call__ result = checked_meth(request, *args, **kwargs) File "/opt/python/domains/bitbucket.org/current/bitbucket/local/env/lib/python2.7/site-packages/piston/resource.py", line 185, in checked_meth return meth(*args, **kwargs) File "/opt/python/domains/bitbucket.org/current/bitbucket/local/env/lib/python2.7/site-packages/newrelic-2.5.0.94/newrelic/hooks/component_piston.py", line 33, in __call__ return self._nr_wrapped(*args, **kwargs) File "/opt/python/domains/bitbucket.org/2013-11-22/bitbucket/../bitbucket/apps/api/v10/decorators.py", line 334, in wrapper return func(*args, **kwargs) File "/opt/python/domains/bitbucket.org/2013-11-22/bitbucket/../bitbucket/apps/api/v10/handlers.py", line 1979, in create data = request.data.copy() 
    

    ..........................................................

    Version : 1.0

    Content Type : application/x-www-form-urlencoded;

    Response Header: HTTP/1.1 401 Unauthorized.

  6. Brodie Rao

    Hi Samuel,

    Sorry for not getting back to you sooner.

    The fact that Bitbucket is crashing shouldn't happen, but it looks like you're still not sending data correctly. Make sure the header you're sending looks like this:

    Content-Type: application/x-www-form-urlencoded
    

    It can't have any stray punctuation at the end. You can also omit the header all together, but the data in your request body still needs to be encoded properly. How you do that will depend on the library/program you're using to issue HTTP requests.

    In curl, you'd do this:

    curl -u username -d owner=username -d name=foo https://bitbucket.org/api/1.0/repositories
    

    Also note that if the owner is the same as the user you're logged in as, you don't need to set it explicitly.

  7. samuel hints reporter

    The fact that Bitbucket is crashing shouldn't happen, but it looks like you're still not sending data correctly. Make sure the header you're sending looks like this:

    The content type application/x-www-form-urlencoded only work to version 2.0. in the version 1.0 that not working.

    Also sometimes the content type application/x-www-url-form-encoded work to version 1.0. for example in the repository issues endpoint when I create milestones or components , that work only to content type application/x-www-url-form-encoded and not to JSON or application/x-www-form-urlencoded.

    .

    Please note that application/x-www-url-form-encoded and

    application/x-www-form-urlencoded are different.

    Clients can send flat request bodies as either as application/json or as application/x-www-url-form-encoded. Read More ...

    This is a problem in bitbucket content type. Please resolve it

    ..............................................................

    How you do that will depend on the library/program you're using to issue HTTP requests.

    I use PHP OAuth library.

    ..............................................................

    My goal is to create a plug-in for Wordpress for develop bitbucket. My plugin is a framwork for bitbucket, and users will can to create her/him plugins for integrate wordpress and bitbucket by my plugin.

    Users will can login to bitbucket by my wordpress plugin and they have access to public/private repositories from own users.

    Please Help me, I've spent a lot of time to report errors in issue tracker. :(

  8. Hadi Khosrojerdi

    I'm the user samuel hints . :)

    And now, my plugin created.

    My plugin can to support all content type's, includes :

    1. JSON application/json.

    Example :

    Version 1 :

    Version 2 :

    <?php 
        global $WP_Bucket;
    
        $owner = "rss_samuel"; // bitbucket username
        $repo_slug = "my_repo"; // a public or private repository
        $repository = $WP_Bucket->api("/2.0/repositories/$owner/$repo_slug", array(
            "body"  =>  json_encode(
                            array(
                                "name"  =>  "repository name",
                                "is_private" => 1, // this is a private repo
                                "language"   => "php",
                            )
                        )
        ));
    ?>
    

    2. Form Encoding application/x-www-url-form-encoded. ( version 1 )

    3. Form Encoding application/x-www-form-urlencoded. ( version 2 )

    • The same code, but this time without json_encode

    .

    <?php 
        global $WP_Bucket;
    
        $owner = "rss_samuel"; // bitbucket username
        $repo_slug = "my_repo"; // a public or private repository
        $repository = $WP_Bucket->api("/2.0/repositories/$owner/$repo_slug", array(
            "body"  =>  array(
                            "name"  =>  "repository name",
                            "is_private" => 1, // this is a private repo
                            "language"   => "php",
                        )
        ));
    ?>
    

    Bitbucket users can to test their own code by my plugin and report their issue's.

    Also there is a test page for browse bitbucket api, just like restbrowser but restbrowser is 2-legged OAuth and my plugin is 3-legged OAuth. ( 2-legged vs 3-legged )

  9. Log in to comment