C++ wrapper for the Mastodon API .
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tastytea b9603587c5
Added proxy to get_stream()
1 year ago
examples Added proxy support 1 year ago
packages/gentoo added ~amd64-KEYWORD to ebuild 1 year ago
src Added proxy to get_stream() 1 year ago
tests Moved entites into src/easy/entities/ 1 year ago
.gitignore moved examples and tests to root directory 1 year ago
.travis.yml fixed travis script 1 year ago
CMakeLists.txt Added proxy to get_stream() 1 year ago
CONTRIBUTING.md added contributiung guidelines 1 year ago
Doxyfile fixed doxygen recipe 1 year ago
ISSUE_TEMPLATE.md created issue template 1 year ago
LICENSE initial commit 1 year ago
README.md Added support for push subscriptions 1 year ago
build.sh fixed build script 1 year ago
build_doc.sh Parameter support, added documentation. 1 year ago


mastodon-cpp is a C++ wrapper for the Mastodon API. The library takes care of the network stuff. You submit a query and get the raw JSON. You can then put that JSON into easy to use classes.



The HTML reference can be generated with build_doc.sh, if doxygen is installed. It is also available at tastytea.github.io/mastodon-cpp/. There are examples in examples/.

Upgrading from below 0.13.0

  • You have to recompile all applications linking against this library.
  • We use a mutex now to guard the string that is being written to. You can get a reference to it with Mastodon::API::http::get_mutex() (see examples 9 and 13 for more info). This is only relevant for streams.

Upgrading from below 0.10.0

Mastodon::API::get, ::get_stream, ::post, ::put and ::del don’t take std::string as parameter to API-calls anymore, only parametermaps. The old behaviour is still supported but is deprecated and will be removed in version 1.0.0.

Upgrading from below 0.7.0

Your projects will break, sorry. Here are the important changes:

  • The header location has changed. They are now in mastodon-cpp/.
  • Specific network error messages have been replaced by 15, “Network error”. You can get the exceptions from curlpp with Mastodon::API::exceptions(true).

Most basic example

#include <iostream>
#include <string>
#include <mastodon-cpp/mastodon-cpp.hpp>

int main()
    Mastodon::API masto("social.example.com", "auth_token");
    std::string answer;
    masto.get(Mastodon::API::v1::accounts_verify_credentials, answer);
    std::cout << answer << '\n';

Another simple example

Using the Easy-class.

#include <iostream>
#include <string>
#include <vector>
#include <mastodon-cpp/mastodon-cpp.hpp>
#include <mastodon-cpp/easy/all.hpp>

using Mastodon::Easy;

int main()
    Easy masto("social.example", "");
    std::string answer;
    masto.get(Mastodon::API::v1::timelines_public, answer);

    for (const std::string &str : Easy::json_array_to_vector(answer))
        Easy::Status status(str);
        std::cout << "  " << status.account().acct() << " wrote:\n";
        std::cout << status.content() << '\n';

Compiling your project

A project consisting of one file can be compiled as follows:

g++ -std=c++14 -lmastodon-cpp example.cpp

Error codes

mastodon-cpp will never use error codes below 11, except 0.

Code Explanation
0 No error
11 Invalid call
12 Not implemented
13 URL changed (HTTP 301 or 308)
14 Aborted by user
15 Network error (curlpp exception)
20 Failed to connect
21 Couldn’t resolve host
22 Network is unreachable
23 Transfer interrupted
24 SSL error
25 Timeout
100 - 999 HTTP status codes
65535 Unknown error

If you use a debug build, you get more verbose error messages. Errors 20-25 are no longer in use (since 0.8.9).

Useful links



Every release includes packages for the package managers of Gentoo, Debian and Red Hat.


Put the ebuild into your local overlay and run ebuild <ebuild path> manifest. Install with emerge mastodon-cpp.

Or add my repository and install it from there.

eselect repository add tastytea git https://git.tastytea.de/repos/overlay-tastytea.git
echo 'dev-cpp/mastodon-cpp ~amd64' >> /etc/portage/package.keywords/mastodon-cpp
emaint sync -r tastytea
emerge -a dev-cpp/mastodon-cpp


Prebuilt DEB and RPM packages for x86_64(amd64) are provided with each release. These packages are automatically built and not tested. Install with dpkg -i or rpm -i, respectively.

To use the DEB package on stretch, you will need libcurlpp0 from buster or jessie.

From source


  • Tested OS: Linux
  • C++ compiler (tested: gcc 6.4 / 5.4, clang 5.0)
  • cmake (tested: 3.9.6)
  • libcurl (tested: 7.58.0 / 7.35.0)
  • curlpp (tested: 0.8.1 / 0.7.3)
  • Optional
    • Easy interface & Examples: jsoncpp (tested: 1.8.1 / 1.7.2)
    • Documentation: doxygen (tested: 1.8.13)
    • DEB package: dpkg (tested:
    • RPM package: rpm (tested:

Get sourcecode


Download the current release at GitHub.

Development version

Build Status

git clone https://github.com/tastytea/mastodon-cpp.git


mkdir build
cd build/
cmake ..

cmake options:

  • -DCMAKE_BUILD_TYPE=Debug for a debug build
  • -DWITHOUT_EASY=ON to not build the Easy abstractions and to get rid of the jsoncpp-dependency (not recommended)
  • -DWITH_EXAMPLES=ON if you want to compile the examples
  • -DWITH_TESTS=ON if you want to compile the tests
  • -DWITH_DOC=ON if you want to compile the HTML reference
  • -DWITH_DEB=ON if you want to be able to generate a deb-package
  • -DWITH_RPM=ON if you want to be able to generate an rpm-package

You can run the tests with ctest .. inside the build directory. To install, run make install.



Put the ebuild from packages/gentoo into your local overlay and rename it to match the desired version or use the live-ebuild (mastodon-cpp-9999.ebuild) to install the development version.


Compile with -DWITH_DEB=ON or -DWITH_RPM=ON. Run make package from the build directory to generate a DEB/RPM package.


Run make package from the build directory to generate a tar.gz archive.

Status of implementation

Feature complete as of Mastodon 2.4.0

  • GET /api/v1/accounts/:id
  • GET /api/v1/accounts/verify_credentials
  • PATCH /api/v1/accounts/update_credentials
  • GET /api/v1/accounts/:id/followers
  • GET /api/v1/accounts/:id/following
  • GET /api/v1/accounts/:id/statuses
  • POST /api/v1/accounts/:id/follow
  • POST /api/v1/accounts/:id/unfollow
  • POST /api/v1/accounts/:id/block
  • POST /api/v1/accounts/:id/unblock
  • POST /api/v1/accounts/:id/mute
  • POST /api/v1/accounts/:id/unmute
  • GET /api/v1/accounts/relationships
  • GET /api/v1/accounts/search
  • POST /api/v1/apps
  • GET /api/v1/blocks
  • GET /api/v1/domain_blocks
  • POST /api/v1/domain_blocks
  • DELETE /api/v1/domain_blocks
  • GET /api/v1/favourites
  • GET /api/v1/follow_requests
  • POST /api/v1/follow_requests/:id/authorize
  • POST /api/v1/follow_requests/:id/reject
  • POST /api/v1/follows
  • GET /api/v1/instance
  • GET /api/v1/custom_emojis
  • GET /api/v1/lists
  • GET /api/v1/accounts/:id/lists
  • GET /api/v1/lists/:id/accounts
  • GET /api/v1/lists/:id
  • POST /api/v1/lists
  • PUT /api/v1/lists/:id
  • DELETE /api/v1/lists/:id
  • POST /api/v1/lists/:id/accounts
  • DELETE /api/v1/lists/:id/accounts
  • POST /api/v1/media
  • PUT /api/v1/media/:id
  • GET /api/v1/mutes
  • GET /api/v1/notifications
  • GET /api/v1/notifications/:id
  • POST /api/v1/notifications/clear
  • POST /api/v1/notifications/dismiss
  • GET /api/v1/reports
  • POST /api/v1/reports
  • GET /api/v1/search
  • GET /api/v1/statuses/:id
  • GET /api/v1/statuses/:id/context
  • GET /api/v1/statuses/:id/card
  • GET /api/v1/statuses/:id/reblogged_by
  • GET /api/v1/statuses/:id/favourited_by
  • POST /api/v1/statuses
  • DELETE /api/v1/statuses/:id
  • POST /api/v1/statuses/:id/reblog
  • POST /api/v1/statuses/:id/unreblog
  • POST /api/v1/statuses/:id/favourite
  • POST /api/v1/statuses/:id/unfavourite
  • POST /api/v1/statuses/:id/pin
  • POST /api/v1/statuses/:id/unpin
  • POST /api/v1/statuses/:id/mute
  • POST /api/v1/statuses/:id/unmute
  • GET /api/v1/timelines/home
  • GET /api/v1/timelines/public
  • GET /api/v1/timelines/tag/:hashtag
  • GET /api/v1/timelines/list/:list_id
  • GET /api/v1/streaming/user
  • GET /api/v1/streaming/public
  • GET /api/v1/streaming/public/local
  • GET /api/v1/streaming/hashtag
  • GET /api/v1/streaming/list
  • POST /api/v1/push/subscription
  • GET /api/v1/push/subscription
  • PUT /api/v1/push/subscription
  • DELETE /api/v1/push/subscription


Copyright © 2018 tastytea <tastytea@tastytea.de>.
License GPLv3: GNU GPL version 3 <https://www.gnu.org/licenses/gpl-3.0.html>.
This program comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to redistribute it under certain conditions.