REST API

Documentation for https://www.jdoodle.com/compiler-api/

Endpoints for REST API

https://api.jdoodle.com/v1/execute - can be used to run or compile programs.

https://api.jdoodle.com/v1/credit-spent - used to check the credit spent.

(only POST method supported with Content-Type: application/json)

Input Parameters for the execute API call

Output Parameters for the execute API call when the execution is successful

Output Parameters for the execute API call when the execution failed

Input Parameters for the "credit-spent" API call

Output Parameters for the "credit-spent" API call when the execution is successful

Output Parameters for the "credit-spent" API call when the execution failed

Language Codes and Version Index

Please refer - Language Codes and Versions

Java Example for the Execute API Call

The below is a quick and dirty Java example, but please use your favourite rest API client and JSON Java libraries for clean code for production use.

package com.jdoodle;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

public class APITest {
    public static void main(String args[]) {

        String clientId = "YourClientID"; //Replace with your client ID
        String clientSecret = "YourClientSecret"; //Replace with your client Secret
        String script = "";
        String language = "php";
        String versionIndex = "0";

        try {
            URL url = new URL("https://api.jdoodle.com/v1/execute");
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setDoOutput(true);
            connection.setRequestMethod("POST");
            connection.setRequestProperty("Content-Type", "application/json");

            String input = "{\"clientId\": \"" + clientId + "\",\"clientSecret\":\"" + clientSecret + "\",\"script\":\"" + script +
            "\",\"language\":\"" + language + "\",\"versionIndex\":\"" + versionIndex + "\"} ";

            System.out.println(input);

            OutputStream outputStream = connection.getOutputStream();
            outputStream.write(input.getBytes());
            outputStream.flush();

            if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) {
                throw new RuntimeException("Please check your inputs : HTTP error code : "+ connection.getResponseCode());
            }

            BufferedReader bufferedReader;
            bufferedReader = new BufferedReader(new InputStreamReader(
            (connection.getInputStream())));

            String output;
            System.out.println("Output from JDoodle .... \n");
            while ((output = bufferedReader.readLine()) != null) {
                System.out.println(output);
            }

            connection.disconnect();

        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

NodeJs Example for the Execute API Call

var request = require('request');

var program = {
    script : "",
    language: "php",
    versionIndex: "0",
    clientId: "YourClientID",
    clientSecret:"YourClientSecret"
};
request({
    url: 'https://api.jdoodle.com/v1/execute',
    method: "POST",
    json: program
},
function (error, response, body) {
    console.log('error:', error);
    console.log('statusCode:', response && response.statusCode);
    console.log('body:', body);
})

Curl Example for the execute API Call

The below is a curl example (note: may need slight syntax change in windows)

curl -H "Content-Type: application/json; charset=UTF-8" -X POST -d '{"clientId": "YourClientId","clientSecret":"YourClientSecret","script":"","language":"php","versionIndex":"0"}' https://api.jdoodle.com/v1/execute

Curl Example for the "credit-spent" API Call

The below is a curl example (note: may need slight syntax change in windows)

curl -H "Content-Type: application/json; charset=UTF-8" -X POST -d '{"clientId": "YourClientId","clientSecret":"YourClientSecret"}' https:

Postman Examples

Right-click the below JSON file and save it in your system, then import the file to your postman and change the clientId and clientSecret for a quick start.

Do you have any client libraries for these APIs?

We don't provide API client libraries, but you can generate client libraries in so many different languages using http://editor.swagger.io/ and the below JSON API Description. Simply go to http://editor.swagger.io/, copy paste the below JSON into the editor, click on Generate Client and select the language.

    {
        "swagger": "2.0",
        "info": {
            "description": "JDoodle Compiler API",
                "version": "1.0.0",
                "title": "JDoodle Compiler API",
                "termsOfService": "https://www.jdoodle.com/terms",
                "contact": {
                "email": "jdoodle@nutpan.com"
            }
        },
        "host": "api.jdoodle.com",
        "basePath": "/v1",
        "consumes": [
            "application/json"
        ],
        "produces": [
            "application/json"
        ],
        "paths": {
        "/execute": {
            "post": {
                "summary": "Execute Program",
                    "description": "Endpoint to execute code",
                    "tags": [
                        "execute"
                    ],
                    "parameters": [
                    {
                        "name": "execute",
                        "in": "body",
                        "description": "the body",
                        "required": true,
                        "schema": {
                            "properties": {
                                "clientId": {
                                    "type": "string"
                                },
                                "clientSecret": {
                                    "type": "string"
                                },
                                "script": {
                                    "type": "string"
                                },
                                "stdin": {
                                  "type": "string"
                                },
                                "language": {
                                    "type": "string"
                                },
                                "versionIndex": {
                                    "type": "string"
                                }
                            }
                        }
                    }
                ],
                    "responses": {
                    "200": {
                        "description": "Execution success",
                        "schema": {
                          "type": "object",
                          "properties": {
                            "output": {
                              "type": "string",
                              "description": "Output"
                            },
                            "statusCode": {
                              "type": "integer",
                              "description": "Status Code"
                            },
                            "memory": {
                              "type": "number",
                              "description": "Memory used"
                            },
                            "cpuTime": {
                              "type": "number",
                              "description": "CPU Time used"
                            }
                          }
                    },
                    "401": {
                        "description": "Unauthorized"
                    },
                    "429": {
                        "description": "Daily limit reached"
                    }
                }
            }
        },
        "/credit-spent": {
            "post": {
                "summary": "Credit Spent",
                    "description": "Endpoint to execute code",
                    "tags": [
                    "credit-spent"
                ],
                    "parameters": [
                    {
                        "name": "credit",
                        "in": "body",
                        "description": "the body",
                        "required": true,
                        "schema": {
                            "properties": {
                                "clientId": {
                                    "type": "string"
                                },
                                "clientSecret": {
                                    "type": "string"
                                }
                            }
                        }
                    }
                ],
                    "responses": {
                    "200": {
                        "description": "Execution success",
                        "schema": {
                          "type": "object",
                          "properties": {
                            "used": {
                              "type": "integer",
                              "description": "No of credits used today"
                            }
                          }
                        }
                    },
                    "401": {
                        "description": "Unauthorized"
                    }
                }
            }
        }
    },
        "externalDocs": {
        "description": "Find out more about JDoodle Compiler API",
            "url": "https://www.jdoodle.com/compiler-api"
    }
}

Where can I find help and support?

For any help, doubts, suggestions, etc. Please get in touch with us at hello@jdoodle.com

Last updated