REST API
(only POST method supported with Content-Type: application/json)
clientId | Your Client ID |
clientSecret | Your Client Secret |
script | program to compile and/or execute |
stdin | StdIn |
language | language of the script (refer the supported language list below) |
versionIndex | the version index of the language to be used (refer to the supported languages and versions in the list below) |
compileOnly | true/false - default false. If true, the program will be only compiled, not executed. |
Parameter | Description |
output | Output of the program |
statusCode | Status Code of the result |
memory | Memory used by the program |
cpuTime | CPU Time used by the program |
compilationStatus | Only when the "compileOnly" option in the request is true. 1 - error. 0 - success. |
Parameter | Description |
error | error message |
statusCode | Status Code of the result |
Parameter | Description |
clientId | Client ID for your subscription |
clientSecret | Client Secret for your subscription |
Parameter | Description |
used | No of credits used today |
Parameter | Description |
error | error message |
statusCode | Status Code of the result |
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();
}
}
}
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);
})
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
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:
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.
jdoodle_api_postman.json
2KB
Code

Select "Raw" type and "JSON"



Content Type should be application/json
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": "[email protected]"
}
},
"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"
}
}
For any help, doubts, suggestions, etc. Please get in touch with us at [email protected]
Last modified 8mo ago