mastodon-cpp  0.104.0
mastodon-cpp Documentation

mastodon-cpp is a C++ wrapper for the Mastodon API. You submit an API call and get the raw JSON or easy to use abstractions.

The ABI will be unstable in versions < 1.0.0

Subscribe to mastodon-cpp releases.


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 <mastodon-cpp/mastodon-cpp.hpp>
int main()
Mastodon::API masto("", "auth_token");
std::cout << masto.get(Mastodon::API::v1::accounts_verify_credentials);
std::cout << std::endl;

Another simple example

Using the Easy interface.

#include <iostream>
#include <string>
#include <mastodon-cpp/mastodon-cpp.hpp>
#include <mastodon-cpp/easy/all.hpp>
using Mastodon;
int main()
Easy::API masto("social.example", "");
return_call ret = masto.get(API::v1::timelines_public);
for (const std::string &str : Easy::json_array_to_vector(ret.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

List of types

Learn more at and

Return types

Other types

Error codes

Code Explanation
0 No error
22 Invalid argument
78 URL changed (HTTP 301 or 308)
110 Connection timed out
111 Connection refused (check http_error_code)
113 No route to host / Could not resolve host
192 curlpp runtime error
193 curlpp logic error
255 Unknown error

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

Useful links


Upgrading from versions below 0.100.0

Starting with version 0.100.0, large parts of the library have been rewritten. Upgrading from previous versions will require extensive code changes. You can keep using the old version, it is archived in the branch pre-0.100.0. It will receive bug-fixes for a while but no new features.


Every release includes packages for Debian and Centos. Gentoo packages are available in my overlay.


Add my repository and install it from there.

eselect repository enable tastytea
echo 'dev-cpp/mastodon-cpp ~amd64' >> /etc/portage/package.accept_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. .deb packages are built on Debian stretch and .rpm packages are built on CentOS 7. These packages are automatically built and not tested.

To use the DEB<tt>.deb package on Debian stretch, you will need libcurlpp0 from sid.

To use the .rpm package on CentOS 7, you will need libcurlpp from EPEL 6.

From source


Get sourcecode


Download the current release at

Development version

git clone


mkdir build
cd build/
cmake ..
cmake --build . -- -j$(nproc --ignore=1)

cmake options:

Install with make install.


You can run the tests with ctest inside the build directory. You need to set the environment variable MASTODON_CPP_ACCESS_TOKEN to an access token with the scopes read, write and follow for some tests. You can select the instance to use with MASTODON_CPP_INSTANCE, the default is You can select the user ID with MASTODON_CPP_USER_ID, the default is 9hnrrVPriLiLVAhfVo. You can select the status ID with MASTODON_CPP_STATUS_ID, the default is 9hwnuJMq3eTdO4s1PU. You can select the filter ID with MASTODON_CPP_FILTER_ID.

Requirements for the test-user:



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, 2019 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.