mastodon-cpp  0.30.1
mastodon-cpp Documentation

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 ABI will be unstable in versions < 1.0.0

Beginning with 0.30.0, all IDs are const string instead of uint_fast64_t as required by the Mastodon API. Sorry for the inconvenience.

Breaking API changes

I'm going to rewrite key parts of this library. The new API will be incompatible with the old one. The new code will start with the version number 0.100.0. The old code is archived in the branch "pre-0.100.0" and will get bugfixes for a while.


The HTML reference can be generated with, if doxygen is installed. It is also available at There are examples in examples/.

Most basic example

#include <iostream>
#include <string>
#include <mastodon-cpp/mastodon-cpp.hpp>
int main()
Mastodon::API masto("", "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)
16 Timeout
100 - 999 HTTP status codes
65535 Unknown error

If you use a debug build, you get more verbose error messages.

Useful links



Every release includes packages for the package managers of Debian and Red Hat. Gentoo packages are available in an overlay.


Add my repository and install it from there.

eselect repository enable tastytea
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 sid.

From source


Get sourcecode


Download the current release at

Development version

git clone


mkdir build
cd build/
cmake ..

cmake options:

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



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.6.1

Glitch-Soc support


Copyright © 2018 tastytea <>.
License GPLv3: GNU GPL version 3 <>.
This program comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to redistribute it under certain conditions.