Skip to content
Visit Railgun on GitHub
Set theme to dark (⇧+D)

Using cURL with the API

Here is how to create, activate, assign, and enable a Railgun using cURL and the Optimized Partner API.

  1. Look up the user_key for the domain to add a Railgun to. This can be done using the user_lookup Host API method and the user’s email address or unique ID:
$ curl -s ''
{    "msg": null,    "request": {        "act": "user_lookup",        "cloudflare_email": ""    },    "response": {        "cloudflare_email": "",        "hosted_zones": [            ""        ],        "unique_id": "UNIQUE_ID (CAN BE USED IN PLACE OF USER'S EMAIL)",        "user_api_key": "USER_API_KEY (NOT USED FOR RAILGUN)",        "user_authed": true,        "user_exists": true,        "user_key": "UNIQUE_USER_KEY_OF_32_CHARACTERS"    },    "result": "success"}
  1. Next, call the init API method to create a new Railgun using the host_key and user_key:
$ curl ''
{    "msg": null,    "response": {        "act": "railgun_init",        "railgun_id": "1",        "railgun_name": "GENERATED_OR_SPECIFIED_RG_NAME",        "railgun_status": "INI",        "rtkn": "30_CHARACTER_RTKN"    },    "result": "success"}
  1. The Railgun daemon should then be started so that it may complete the activation process, which should be logged via syslog after startup:
$  tail -f /var/log/messagesOct 27 22:29:41 www railgun[Activation]: Activation POST completed.Oct 27 22:29:41 www railgun[Activation]: Assigned Railgun ID: 1Oct 27 22:29:41 www railgun[Activation]: Acquired cert from server
  1. Next, the suggestion_set method is called with auto_enabled set to 0 in order to expose the Railgun to the domain. Setting auto_enabled to 0 will not enable Railgun for the domain, it will only expose the Railgun instance to the domain within Cloudflare Settings. To expose, associate, and enable Railgun in a single API call, set auto_enabled to 1.
$ curl ''
{    "msg": null,    "response": {        "act": "railgun_suggest",        "railgun_id": "1",    },    "result": "success"}
  1. The user should now be able to see the Railgun configuration dropdown menu within their Cloudflare Settings panel. The user can now test and enable Railgun themselves. If auto_enabled had been set to 1, the following conn_set call is not necessary and would’ve been performed automatically.

  2. Finally, the conn_set method is called to associate the Railgun with the domain and create the necessary DNS records and SSL certificate. It is possible to test Railgun without enabling it using a special HTTP header. More details on testing with the hostname (railgun_rec_name) in the installation documentation.

$ curl ''
{    "msg": null,    "response": {        "act": "railgun_conn_set",        "railgun_conn_id": "2",        "railgun_rec_name": ""    },    "result": "success"}