Skip to content

Instantly share code, notes, and snippets.

@cpacia
Last active September 11, 2016 19:10
Show Gist options
  • Save cpacia/3b7ae731c907863906f101911055cbd9 to your computer and use it in GitHub Desktop.
Save cpacia/3b7ae731c907863906f101911055cbd9 to your computer and use it in GitHub Desktop.
swagger: '2.0'
schemes:
- http
- https
host: localhost:8080
basePath: /
info:
description: |
# Introduction
The OpenBazaar networking daemon combines a Kademlia DHT, IPFS node, Bitcoin wallet, and a peer-to-peer contracting system. This JSON API is the primary mechanism for controlling the node. It offers a RESTful api for building user interfaces as well as a number of RPC calls. In documentation you'll find a full list of API calls and example usages.
# Authentication
When running on localhost (the default), the API is unauthenticated. You can enable authentication by setting the config file as follows:
```
{
"JSON-API": {
"Authenticated": true
}
}
```
Note that on mainnet the server enables authentication automatically if the gateway url is bound to anything other than localhost (implying open internet access) even if the config file is set to false.
On each startup, OpenBazaar generates a new cookie file and saves it in the datafolder. The cookie is deleted on shutdown. To authenticate an API connection you need to include that cookie in each request header. Example:
```
cookie: OpenBazaar_Auth_Cookie=2Yc7VZtG/pVKrH5Lp0mKRSEPC4xlm1dGpkbUXLehTUI
```
# SSL
**NEVER** open the JSON API to the internet without also encrypting the connection with SSL. Without SSL enabled the cookie will be sent to the server in the clear allowing anyone who views your packets to access your server and potentially steal your bitcoins. For instructions on how to enable SSL, see [here]().
# Cross-Origin Resource Sharing
CORS is turned off by default, meaning that you will not be able to make API calls from a browser to a running server on localhost. You can turn CORS on by setting the config file as follows:
```
{
"JSON-API": {
"CORS": true
}
}
```
Keep in mind that running the server with CORS enabled is a potential secrity risk as it will allow any website you visit to make calls to your server. Authentication should be enabled along side CORS.
version: 1.0.0
title: OpenBazaar JSON API
termsOfService: There are no TOS at this moment, use at your own risk we take no responsibility.
contact:
email: project@openbazaar.org
url: https://openbazaar.org
x-logo:
url: 'https://openbazaar.org/assets/img/icon-large.png'
license:
name: MIT
url: 'http://opensource.org/licenses/MIT'
tags:
- name: Profile
description: API calls for setting and viewing profile data
- name: Settings
description: API calls for setting mostly UI specific setting variables.
- name: Following
description: All API calls related to following and getting lists of following/followed peers.
- name: Wallet
description: Bitcoin wallet RPC calls
securityDefinitions:
api_key:
type: apiKey
name: autoCookie
in: header
paths:
/ob/follow:
post:
tags:
- Following
summary: Follow a peer
description: RPC call to follow another peer on the network.
operationId: Follow
consumes:
- application/json
produces:
- application/json
parameters:
- in: body
name: body
description: Follow object containing a peer ID.
required: true
schema:
$ref: '#/definitions/Follow'
responses:
'200':
description: OK
schema:
$ref: '#/definitions/DefaultResponse'
'400':
description: Bad Request
schema:
$ref: '#/definitions/ErrorResponse'
'500':
description: Internal Server Error
schema:
$ref: '#/definitions/ErrorResponse'
/ob/unfollow:
post:
tags:
- Following
summary: Unfollow a peer
description: RPC call to unfollow another peer on the network.
operationId: Unfollow
consumes:
- application/json
produces:
- application/json
parameters:
- in: body
name: body
description: Unfollow object containing a peer ID.
required: true
schema:
$ref: '#/definitions/Follow'
responses:
'200':
description: OK
schema:
$ref: '#/definitions/DefaultResponse'
'400':
description: Bad Request
schema:
$ref: '#/definitions/ErrorResponse'
'500':
description: Internal Server Error
schema:
$ref: '#/definitions/ErrorResponse'
/ob/followers:
get:
tags:
- Following
summary: Get a list of your followers
description: Returns a list of peers IDs that follow you
operationId: GetFollowers
consumes:
- application/json
produces:
- application/json
parameters:
- in: query
name: offsetId
description: Return all peer IDs after this ID
required: false
type: string
- in: query
name: limit
description: Number of peer IDs to return
required: false
type: string
responses:
'200':
description: OK
schema:
$ref: '#/definitions/FollowResponse'
'500':
description: Internal Server Error
schema:
$ref: '#/definitions/ErrorResponse'
/ob/following:
get:
tags:
- Following
summary: Get a list of peers you are following.
description: Returns a list of peer IDs you are following
operationId: GetFollowing
consumes:
- application/json
produces:
- application/json
parameters:
- in: query
name: offsetId
description: Return all peer IDs after this ID
required: false
type: string
- in: query
name: limit
description: Number of peer IDs to return
required: false
type: string
responses:
'200':
description: OK
schema:
$ref: '#/definitions/FollowResponse'
'500':
description: Internal Server Error
schema:
$ref: '#/definitions/ErrorResponse'
/ob/followsme/{peerId}:
get:
tags:
- Following
summary: Does <peer> follow me?
description: Returns true if the given peer follows you
operationId: FollowsMe
consumes:
- application/json
produces:
- application/json
parameters:
- name: peerId
in: path
description: The base58 encoded peer ID
required: true
type: string
responses:
'200':
description: OK
schema:
$ref: '#/definitions/FollowsMeResponse'
/ob/isfollowing/{peerId}:
get:
tags:
- Following
summary: An I following <peer>?
description: Returns true if you're following the given peer
operationId: IsFollowing
consumes:
- application/json
produces:
- application/json
parameters:
- name: peerId
in: path
description: The base58 encoded peer ID
required: true
type: string
responses:
'200':
description: OK
schema:
$ref: '#/definitions/IsFollowingResponse'
/ob/profile:
post:
tags:
- Profile
summary: Set the profile
description: Set the profile for this node
operationId: PostProfile
consumes:
- application/json
produces:
- application/json
parameters:
- in: body
name: body
description: Profile object
required: true
schema:
$ref: '#/definitions/Profile'
responses:
'200':
description: OK
schema:
$ref: '#/definitions/Profile'
'400':
description: Bad Request
schema:
$ref: '#/definitions/ErrorResponse'
'409':
description: Conflict
schema:
$ref: '#/definitions/ErrorResponse'
'500':
description: Internal Server Error
schema:
$ref: '#/definitions/ErrorResponse'
put:
tags:
- Profile
summary: Update the profile
description: Update the profile for this node
operationId: PutProfile
consumes:
- application/json
produces:
- application/json
parameters:
- in: body
name: body
description: Profile object
required: true
schema:
$ref: '#/definitions/Profile'
responses:
'200':
description: OK
schema:
$ref: '#/definitions/Profile'
'400':
description: Bad Request
schema:
$ref: '#/definitions/ErrorResponse'
'404':
description: Not Found
schema:
$ref: '#/definitions/ErrorResponse'
'500':
description: Internal Server Error
schema:
$ref: '#/definitions/ErrorResponse'
/ipns/{peerId}/profile:
get:
tags:
- Profile
summary: Get a profile
description: Get a profile for a node given the peer ID.
operationId: GetProfile
consumes:
- application/json
produces:
- application/json
parameters:
- name: peerId
in: path
description: The base58 encoded peer ID. Use own peer ID to get own profile.
required: true
type: string
responses:
'200':
description: OK
schema:
$ref: '#/definitions/Profile'
'400':
description: Bad Request
schema:
$ref: '#/definitions/IPFSResponse'
'500':
description: Internal Server Error
schema:
$ref: '#/definitions/IPFSResponse'
/ob/settings:
post:
tags:
- Settings
summary: Set settings
description: Set the settings object in the database
operationId: PostSettings
consumes:
- application/json
produces:
- application/json
parameters:
- in: body
name: body
description: Settings object
required: true
schema:
$ref: '#/definitions/Settings'
responses:
'200':
description: OK
schema:
$ref: '#/definitions/DefaultResponse'
'400':
description: Bad Request
schema:
$ref: '#/definitions/ErrorResponse'
'409':
description: Conflict
schema:
$ref: '#/definitions/ErrorResponse'
'500':
description: Internal Server Error
schema:
$ref: '#/definitions/ErrorResponse'
put:
tags:
- Settings
summary: Update settings
description: Update the settings object in the database. Overwrites all fields.
operationId: PutSettings
consumes:
- application/json
produces:
- application/json
parameters:
- in: body
name: body
description: Settings object
required: true
schema:
$ref: '#/definitions/Settings'
responses:
'200':
description: OK
schema:
$ref: '#/definitions/DefaultResponse'
'400':
description: Bad Request
schema:
$ref: '#/definitions/ErrorResponse'
'404':
description: Not Found
schema:
$ref: '#/definitions/ErrorResponse'
'500':
description: Internal Server Error
schema:
$ref: '#/definitions/ErrorResponse'
patch:
tags:
- Settings
summary: Patch settings
description: Update individual settings without overwriting the rest.
operationId: PatchSettings
consumes:
- application/json
produces:
- application/json
parameters:
- in: body
name: body
description: Settings object with only those fields set which should be updated.
required: true
schema:
$ref: '#/definitions/Settings'
responses:
'200':
description: OK
schema:
$ref: '#/definitions/DefaultResponse'
'400':
description: Bad Request
schema:
$ref: '#/definitions/ErrorResponse'
'404':
description: Not Found
schema:
$ref: '#/definitions/ErrorResponse'
'500':
description: Internal Server Error
schema:
$ref: '#/definitions/ErrorResponse'
get:
tags:
- Settings
summary: Get the settings
description: Fetch the settings from the database
operationId: GetSettings
consumes:
- application/json
produces:
- application/json
responses:
'200':
description: OK
schema:
$ref: '#/definitions/Settings'
'404':
description: Not Found
schema:
$ref: '#/definitions/ErrorResponse'
'500':
description: Internal Server Error
schema:
$ref: '#/definitions/ErrorResponse'
/wallet/address:
get:
tags:
- Wallet
summary: Get a bitcoin address
description: Returns an unused bitcoin address. Note the same address is returned until the address is used.
operationId: GetBitcoinAddress
consumes:
- application/json
produces:
- application/json
responses:
'200':
description: OK
schema:
$ref: '#/definitions/Address'
/wallet/mnemonic:
get:
tags:
- Wallet
summary: Get the mnemonic seed
description: Returns the mnemonic seed used to derive all the bitcoin keys. Note this seed should never be disclosed as it will allow someone to drain your wallet and steal your OpenBazaar identity.
operationId: GetMnemonic
consumes:
- application/json
produces:
- application/json
responses:
'200':
description: OK
schema:
$ref: '#/definitions/Mnemonic'
'500':
description: Internal Server Error
schema:
$ref: '#/definitions/ErrorResponse'
/wallet/balance:
get:
tags:
- Wallet
summary: Get the wallet's balance
description: Returns the unconfirmed and confirmed balances of the wallet in satoshi (1/100000000 of a full bitcoin).
operationId: GetBalance
consumes:
- application/json
produces:
- application/json
responses:
'200':
description: OK
schema:
$ref: '#/definitions/Balance'
/wallet/spend:
post:
tags:
- Wallet
summary: Send bitcoins
description: Send bitcoins to someone. Note the feelLevel parameter controls how much of a fee to use. By default the wallet will query a fee api to get the appropriate fee-per-byte for the given level. There is a max fee value in the config file. If the api returns more than the max, then a default fee will be used. The default values, max values, and api can be configured in the config file. If you do not wish to use a fee api, and just want to use the default value, set the fee api to "".
operationId: SpendBitcoins
consumes:
- application/json
produces:
- application/json
parameters:
- in: body
name: body
description: Spend object
required: true
schema:
$ref: '#/definitions/Spend'
responses:
'200':
description: OK
schema:
$ref: '#/definitions/DefaultResponse'
'400':
description: Bad Request
schema:
$ref: '#/definitions/ErrorResponse'
'500':
description: Internal Server Error
schema:
$ref: '#/definitions/ErrorResponse'
/wallet/resyncblockchain:
post:
tags:
- Wallet
summary: Re-sync blockchain
description: RPC call to re-download the blocks in the blockchain. It is theoretically possible that the wallet could fail to hear of a transaction intended for itself if its peers fail to relay a transaction. In such cases the resource is to re-download the historical blocks from a new peer to discover the missing transaction(s).
operationId: ResyncBlockchain
consumes:
- application/json
produces:
- application/json
responses:
'200':
description: OK
schema:
$ref: '#/definitions/DefaultResponse'
definitions:
DefaultResponse:
type: object
ErrorResponse:
type: object
properties:
success:
type: boolean
example: false
reason:
type: string
example: "Error unmarshalling json"
IPFSResponse:
type: string
Follow:
description: A json object containing a peer ID
type: object
required: ["id"]
properties:
id:
description: Base58 encoded multihash
type: string
example: "QmamudHQGtztShX7Nc9HcczehdpGGWpFBWu2JvKWcpELxr"
FollowResponse:
description: A json list of Peer IDs
type: array
example: [
"QmecpJrN9RJ7smyYByQdZUy5mF6aapgCfKLKRmDtycv9aG",
"QmamudHQGtztShX7Nc9HcczehdpGGWpFBWu2JvKWcpELxr",
"QmPDLS7TV9Q3gtxRXQVqrm2RpEtz1Mq6u2YGeuEJWCqu6B"
]
items:
type: string
FollowsMeResponse:
type: object
properties:
followsMe:
type: boolean
example: false
IsFollowingResponse:
type: object
properties:
isFollowing:
type: boolean
example: false
Address:
type: object
properties:
address:
description: "An unused bitcoin address"
type: string
example: "1HYhu8e2wv19LZ2umXoo1pMiwzy2rL32UQ"
Mnemonic:
type: object
properties:
mnemonic:
description: "A twelve-word mnemonic seed"
type: string
example: "spot piano symbol news risk zero maze exchange repeat matrix whisper learn"
Balance:
type: object
properties:
confirmed:
description: "The confirmed balance in satoshi"
type: integer
example: 25000000
unconfirmed:
description: "The unconfirmed balance in satoshi"
type: integer
example: 1700000
Spend:
type: object
properties:
address:
description: "A bitcoin address to send coins to"
type: string
example: "1HYhu8e2wv19LZ2umXoo1pMiwzy2rL32UQ"
amount:
description: "The amount to send in satoshi"
type: integer
example: 1700000
feeLevel:
description: "The fee level to use"
enum: [ "PRIORITY", "NORMAL", "ECONOMIC" ]
type: string
example: "NORMAL"
Profile:
type: object
required: ["name"]
properties:
handle:
description: "Optional blockchainID. Profile will be rejected if the handle doesn't validate to this node's peer ID."
type: string
example: "@UrbanArt"
name:
description: "User's name"
type: string
example: "Urban Art"
location:
description: "Optional location data for this user"
type: string
example: "Chicago, Illinois"
about:
description: "About section text"
type: string
example: "We love spray painting and street art and this is the best way to not get arrested or get any tickets but still be able to paint graffiti. We hope you like it."
shortDescription:
description: "Short text description used in various parts of the app where the about is otherwise too long"
type: string
example: "Spray paint artwork on canvas; everything is individually painted and handmade."
website:
description: "Option website url"
type: string
example: "http://urbanart.com"
email:
description: "Optional email address"
type: string
example: "dave@urbanart.com"
phoneNumber:
description: "Optional phone number"
type: string
example: "555-8790"
social:
description: "Optional social media accounts"
type: array
example: [
{
"type": "TWITTER",
"username": "@UrbanArtStore",
"proof": "https://twitter.com/UrbanArtStore/status/774773006132391936"
},
{
"type": "FACEBOOK",
"username": "urbanart"
}
]
items:
type: object
required: ["type", "username"]
properties:
type:
description: "The type of social account"
type: string
example: "TWITTER"
username:
description: "Account username"
type: string
example: "@UrbanArtStore"
proof:
description: "A url link proving ownership of this account. For example, a tweet saying 'My OpenBazaar handle is ...'"
type: string
example: "https://twitter.com/UrbanArtStore/status/774773006132391936"
nsfw:
description: "Is this user's page not safe for work?"
type: boolean
vendor:
description: "Is this user a vendor?"
type: boolean
moderator:
description: "Is this user a moderator?"
type: boolean
primaryColor:
description: "Primary RGB profile color in hexadecimal format"
type: string
example: "#AF854C"
secondaryColor:
description: "Secondary RGB profile color in hexadecimal format"
type: string
example: "#E3E3E3"
textColor:
description: "Text RGB profile color in hexadecimal format"
type: string
example: "#FFFFFF"
avatarHash:
description: "The IPFS hash for this node's avatar. This field is added automatically by the server."
type: string
example: "QmecpJrN9RJ7smyYByQdZUy5mF6aapgCfKLKRmDtycv9aG"
headerHash:
description: "The IPFS hash for this node's header. This field is added automatically by the server."
type: string
example: "QmPDLS7TV9Q3gtxRXQVqrm2RpEtz1Mq6u2YGeuEJWCqu6B"
followerCount:
description: "The number of peers following this node. This field is added automatically by the server."
type: integer
example: 25
followingCount:
description: "The number of peers this node is following. This field is added automatically by the server."
type: integer
example: 82
listingCount:
description: "The number of listings this node has for sale. This field is added automatically by the server."
type: integer
example: 11
lastModified:
description: "The time this profile was last modified. This field is added automatically by the server."
type: string
example: "2016-12-31T15:59:60-08:00"
Settings:
type: object
properties:
paymentDataInQR:
description: "Add order metadata into payment QR code. Most wallets typically save the metadata so this is an optional privacy feature."
type: boolean
showNotifications:
description: "Show notifications which come over the websocket"
type: boolean
showNsfw:
description: "Show not safe for work content"
type: boolean
shippingAddresses:
description: "List of shipping addresses saved for this user"
type: array
example: [
{
"name": "Seymour Butts",
"company": "Globex Corporation",
"addressLineOne": "31 Spooner Street",
"addressLineTwo": "Apt. 124",
"city": "Quahog",
"state": "RI",
"country": "UNITED_STATES",
"addressNotes": "Leave package at back door"
}
]
items:
description: "A shipping address object"
type: object
properties:
name:
description: "Name of person to ship to"
type: string
example: "Seymour Butts"
company:
description: "Optional company name"
type: string
example: "Globex Corporation"
addressLineOne:
description: "Shipping street address"
type: string
example: "31 Spooner Street"
addressLineTwo:
description: "Second address line. Sometimes used for apartment numbers."
type: string
example: "Apt. 124"
city:
description: "City to ship to"
type: string
example: "Quahog"
state:
description: "State or region ship to"
type: string
example: "RI"
country:
description: "Country to ship to. Must be one of the countires listed in [countriescodes.proto](https://github.com/OpenBazaar/openbazaar-go/blob/master/pb/protos/countrycodes.proto)."
type: string
example: "UNITED_STATES"
postalCode:
description: "Postal code ship to"
type: string
example: "00093"
addressNotes:
description: "Additional information about the address"
type: string
example: "Leave package at back door"
localCurrency:
description: "The currency to display prices in"
type: string
example: "USD"
country:
description: "The location of the user. Used for checking if products ships to them. Must be one of the countires listed in [countriescodes.proto](https://github.com/OpenBazaar/openbazaar-go/blob/master/pb/protos/countrycodes.proto)."
type: string
example: "UNITED_STATES"
language:
description: "The languange preference of the user. Used to select the language in the UI."
type: string
example: "English"
termsAndConditions:
description: "The saved terms and conditions. Becomes the default text for each listing that is created."
type: string
example: "By purchasing this item you agree to the following..."
refundPolicy:
description: "The saved refund policy. Becomes the default text for each listing that is created."
type: string
example: "All sales are final."
blockedNodes:
description: "Ids of peers we the user wishes to block"
type: array
example: [
"QmecpJrN9RJ7smyYByQdZUy5mF6aapgCfKLKRmDtycv9aG",
"QmamudHQGtztShX7Nc9HcczehdpGGWpFBWu2JvKWcpELxr",
"QmPDLS7TV9Q3gtxRXQVqrm2RpEtz1Mq6u2YGeuEJWCqu6B"
]
items:
type: string
description: "The peer ID to block"
moderators:
description: "Saved list of moderator IDs that will be added to each new listing."
type: array
example: [
"QmNedYJ6WmLhacAL2ozxb4k33Gxd9wmKB7HyoxZCwXid1e",
"QmQdi7EaJUmuRUtSaCPkijw5cptFfNcX2EPvMyQwR117Y2"
]
items:
type: string
description: "The moderator peer ID"
smtpSettings:
description: "Settings for email notifications"
type: object
example: {
"notifications": true,
"serverAddress": "smtp.urbanart.com:465",
"username": "urbanart",
"password": "letmein",
"senderEmail": "notifications@urbanart.com",
"recipientEmail": "Dave@gmail.com"
}
properties:
notifications:
description: "Turn email notifications on and off"
type: boolean
serverAddress:
description: "The outgoing mail server IP address or hostname and port"
type: string
example: "smtp.urbanart.com:465"
username:
description: "SMTP username"
type: string
example: "urbanart"
password:
description: "SMTP password"
type: string
example: "letmein"
senderEmail:
description: "The outgoing email address"
type: string
example: "notifications@urbanart.com"
recipientEmail:
description: "The email to send the notifications to"
type: string
example: "Dave@gmail.com"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment