Skip to end of banner
Go to start of banner

REST API

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

Get snippets of current user

GET http://{host}:{port}/{context}/rest/snippets/1.0/snippets
curl -u username:password -H "Content-Type:application/json" http://bitbucket.example.com/rest/snippets/1.0/snippets
 Sample response
{
  "size": 1,
  "limit": 25,
  "isLastPage": true,
  "values": [{
    "guid": "87dec410f4404d4ca43dc4772a8bd0f0",
    "name": "Example Snippet",
    "description": "Example description...",
    "categories": [{
      "guid": "2f7c939e273f4d29b60f08f9a508298a",
      "name": "Example Category"
    }],
    "isVisible": true,
    "isPublic": false,
    "userId": 1,
    "createdAt": 1379175213548,
    "updatedAt": 1379175745710,
    "files": [{
      "guid": "bda2ce737fce4cc19ba00cafc5c9f33d",
      "name": "example.sql",
      "content": "SELECT * FROM examples"
    }],
    "comments": [{
        "guid": "6b90147977bb42f782610f0211a94cfc",
        "text": "This is a comment...",
        "userId": 1,
        "createdAt": 1431174442000,
        "updatedAt": 1431174442000
    }]
  }],
  "start": 0
}

Get starred snippets of current user

GET http://{host}:{port}/{context}/rest/snippets/1.0/snippets/starred
curl -u username:password -H "Content-Type:application/json" http://bitbucket.example.com/rest/snippets/1.0/snippets/starred


 Sample response
{
  "size": 1,
  "limit": 25,
  "isLastPage": true,
  "values": [{
    "snippet": {
      "guid": "87dec410f4404d4ca43dc4772a8bd0f0",
      "name": "Example Snippet",
      "description": "Example description...",
      "categories": [{
        "guid": "2f7c939e273f4d29b60f08f9a508298a",
        "name": "Example Category"
      }],
      "isVisible": true,
      "isPublic": false,
      "userId": 1,
      "createdAt": 1379175213548,
      "updatedAt": 1379175745710,
      "files": [{
        "guid": "bda2ce737fce4cc19ba00cafc5c9f33d",
        "name": "example.sql",
        "content": "SELECT * FROM examples"
      }],
      "comments": [{
          "guid": "6b90147977bb42f782610f0211a94cfc",
          "text": "This is a comment...",
          "userId": 1,
          "createdAt": 1431174442000,
          "updatedAt": 1431174442000
      }]
    },
    "userId": 1,
    "starredAt": 1379177521715
  }],
  "start": 0
}

Browse snippets

GET http://{host}:{port}/{context}/rest/snippets/1.0/snippets/browse
curl -u username:password -H "Content-Type:application/json" http://bitbucket.example.com/rest/snippets/1.0/snippets/browse
 Sample response
{
  "size": 1,
  "limit": 25,
  "isLastPage": true,
  "values": [{
    "guid": "87dec410f4404d4ca43dc4772a8bd0f0",
    "name": "Example Snippet",
    "description": "Example description...",
    "categories": [{
      "guid": "2f7c939e273f4d29b60f08f9a508298a",
      "name": "Example Category"
    }],
    "isVisible": true,
    "isPublic": false,
    "userId": 1,
    "createdAt": 1379175213548,
    "updatedAt": 1379175745710,
    "files":[{
      "guid": "bda2ce737fce4cc19ba00cafc5c9f33d",
      "name": "example.sql",
      "content": "SELECT * FROM examples"
    }],
    "comments": [{
        "guid": "6b90147977bb42f782610f0211a94cfc",
        "text": "This is a comment...",
        "userId": 1,
        "createdAt": 1431174442000,
        "updatedAt": 1431174442000
    }]
  }],
  "start": 0
}


Browse snippets of user

GET http://{host}:{port}/{context}/rest/snippets/1.0/snippets/browse?username={username}
curl -u username:password -H "Content-Type:application/json" http://bitbucket.example.com/rest/snippets/1.0/snippets/browse?username=johndoe
 Sample response
{
  "size": 1,
  "limit": 25,
  "isLastPage": true,
  "values": [{
    "guid": "87dec410f4404d4ca43dc4772a8bd0f0",
    "name": "Example Snippet",
    "description": "Example description...",
    "categories": [{
      "guid": "2f7c939e273f4d29b60f08f9a508298a",
      "name": "Example Category"
    }],
    "isVisible": true,
    "isPublic": false,
    "userId": 1,
    "createdAt": 1379175213548,
    "updatedAt": 1379175745710,
    "files":[{
      "guid": "bda2ce737fce4cc19ba00cafc5c9f33d",
      "name": "example.sql",
      "content": "SELECT * FROM examples"
    }],
    "comments": [{
        "guid": "6b90147977bb42f782610f0211a94cfc",
        "text": "This is a comment...",
        "userId": 1,
        "createdAt": 1431174442000,
        "updatedAt": 1431174442000
    }]
  }],
  "start": 0
}

Get snippets of category

GET http://{host}:{port}/{context}/rest/snippets/1.0/snippets/categories/{guid}

curl -u username:password -H "Content-Type:application/json" http://bitbucket.example.com/rest/snippets/1.0/snippets/categories/2f7c939e273f4d29b60f08f9a508298a
 Sample response
{
  "size": 1,
  "limit": 25,
  "isLastPage": true,
  "values": [{
    "snippet": {
      "guid": "87dec410f4404d4ca43dc4772a8bd0f0",
      "name": "Example Snippet",
      "description": "Example description...",
      "categories": [{
        "guid": "2f7c939e273f4d29b60f08f9a508298a",
        "name": "Example Category"
      }],
      "isVisible": true,
      "isPublic": false,
      "userId": 1,
      "createdAt": 1379175213548,
      "updatedAt": 1379175745710,
      "files": [{
        "guid": "bda2ce737fce4cc19ba00cafc5c9f33d",
        "name": "example.sql",
        "content": "SELECT * FROM examples"
      }],
      "comments": [{
          "guid": "6b90147977bb42f782610f0211a94cfc",
          "text": "This is a comment...",
          "userId": 1,
          "createdAt": 1431174442000,
          "updatedAt": 1431174442000
      }]
    },
    "userId": 1,
    "starredAt": 1379177521715
  }],
  "start": 0
}

Get snippet by GUID

GET http://{host}:{port}/{context}/rest/snippets/1.0/snippets/{guid}
curl -u username:password -H "Content-Type:application/json" http://bitbucket.example.com/rest/snippets/1.0/snippets/87dec410f4404d4ca43dc4772a8bd0f0
 Sample response
{
  "guid": "87dec410f4404d4ca43dc4772a8bd0f0",
  "name": "Example Snippet",
  "description": "Example description...",
  "categories": [{
    "guid": "2f7c939e273f4d29b60f08f9a508298a",
    "name": "Example Category"
  }],
  "isVisible": true,
  "isPublic": false,
  "userId": 1,
  "createdAt": 1379175213548,
  "updatedAt": 1379175745710,
  "files": [{
    "guid": "bda2ce737fce4cc19ba00cafc5c9f33d",
    "name": "example.sql",
    "content": "SELECT * FROM examples"
  }],
  "comments": [{
      "guid": "6b90147977bb42f782610f0211a94cfc",
      "text": "This is a comment...",
      "userId": 1,
      "createdAt": 1431174442000,
      "updatedAt": 1431174442000
  }]
}


Get comment by GUID

GET http://{host}:{port}/{context}/rest/snippets/1.0/snippets/{snippetGuid}/comments/{commentGuid}
curl -u username:password -H "Content-Type:application/json" http://bitbucket.example.com/rest/snippets/1.0/snippets/87dec410f4404d4ca43dc4772a8bd0f0/comments/6b90147977bb42f782610f0211a94cfc
 Sample response
{
  "guid": "6b90147977bb42f782610f0211a94cfc",
  "text": "This is a comment...",
  "userId": 1,
  "createdAt": 1431174442000,
  "updatedAt": 1431174442000
}

Create snippet

POST http://{host}:{port}/{context}/rest/snippets/1.0/snippets
curl -X POST -u username:password -H "Content-Type:application/json" -d '{ "name" : "Example Snippet", "files" : [{ "name" : "example.sql", "content" : "SELECT * FROM examples" }] }' http://bitbucket.example.com/rest/snippets/1.0/snippets
 Sample response
{
  "guid": "87dec410f4404d4ca43dc4772a8bd0f0",
  "name": "Example Snippet",
  "categories": [],
  "isVisible": true,
  "isPublic": false,
  "userId": 1,
  "createdAt": 1379175213548,
  "updatedAt": 1379175745710,
  "files": [{
    "guid": "bda2ce737fce4cc19ba00cafc5c9f33d",
    "name": "example.sql",
    "content": "SELECT * FROM examples"
  }],
  "comments": []
}

Create comment

POST http://{host}:{port}/{context}/rest/snippets/1.0/snippets/{guid}/comments
curl -X POST -u username:password -H "Content-Type:application/json" -d '{ "text" : "This is a comment..." }' http://bitbucket.example.com/rest/snippets/1.0/snippets/87dec410f4404d4ca43dc4772a8bd0f0/comments
 Sample response
{
  "guid": "6b90147977bb42f782610f0211a94cfc",
  "text": "This is a comment...",
  "userId": 1,
  "createdAt": 1431174442000,
  "updatedAt": 1431174442000
}


Update snippet

PUT http://{host}:{port}/{context}/rest/snippets/1.0/snippets/{guid}
curl -X PUT -u username:password -H "Content-Type:application/json" -d '{ "name" : "Example Snippet", "description" : "Example description...", "categories" : [ "Example Category" ], "files" : [{ "name" : "example.sql", "content" : "SELECT * FROM examples" }] }' http://bitbucket.example.com/rest/snippets/1.0/snippets/87dec410f4404d4ca43dc4772a8bd0f0
 Sample response
{
  "guid": "87dec410f4404d4ca43dc4772a8bd0f0",
  "name": "Example Snippet",
  "description": "Example description...",
  "categories": [{
    "guid": "2f7c939e273f4d29b60f08f9a508298a",
    "name": "Example Category"
  }],
  "isVisible": true,
  "isPublic": false,
  "userId": 1,
  "createdAt": 1379175213548,
  "updatedAt": 1379180600230,
  "files": [{
    "guid": "0c7e081403ba49b4a4c0113d2d9933a5",
    "name": "example.sql",
    "content": "SELECT * FROM examples"
  }],
  "comments": []
}

Update comment

PUT http://{host}:{port}/{context}/rest/snippets/1.0/snippets/{snippetGuid}/comments/{commentGuid}
curl -X PUT -u username:password -H "Content-Type:application/json" -d '{ "text" : "This is another comment..." }' http://bitbucket.example.com/rest/snippets/1.0/snippets/87dec410f4404d4ca43dc4772a8bd0f0/comments/6b90147977bb42f782610f0211a94cfc

 Sample response
{
  "guid": "6b90147977bb42f782610f0211a94cfc",
  "text": "This is a comment...",
  "userId": 1,
  "createdAt": 1431174442000,
  "updatedAt": 1431176876101
}

Delete snippet

DELETE http://{host}:{port}/{context}/rest/snippets/1.0/snippets/{guid}
curl -X DELETE -u username:password -H "Content-Type:application/json" http://bitbucket.example.com/rest/snippets/1.0/snippets/87dec410f4404d4ca43dc4772a8bd0f0

Delete comment

DELETE http://{host}:{port}/{context}/rest/snippets/1.0/snippets/{snippetGuid}/comments/{commentGuid}

curl -X DELETE -u username:password -H "Content-Type:application/json" http://bitbucket.example.com/rest/snippets/1.0/snippets/87dec410f4404d4ca43dc4772a8bd0f0/comments/6b90147977bb42f782610f0211a94cfc



  • No labels