Make your first request

 

 

Prerequisites: for the following, you'll need a Mindee account and a live API subscription. You can go learn how to create an account and freely subscribe to an API here.

 

 

Create an API key

 

Go to the “credentials” section of your API. Click on “add key” to create a new token for this API.

 

 

 

 

Get your sample code

 

Go to the Documentation section and find the sample codes in the top right corner:

 

 

 

 

Call the API

 

The sample codes will help you perform the POST request to Mindee APIs in different languages, and send your inputs the right way. 

 

For all the sample codes, replace "mindee_api_url" and "your_token_here" placeholders with your own credentials. Everything is available in your API documentation.

 

Python

Make sure you have the requests package installed. If not, you can install it in your env by running : 

 

pip install requests

 

import requests

url = "mindee_api_url"

with open("/path/to/my/file", "rb") as myfile:
    files = {"file": myfile}
    headers = {"X-Inferuser-Token": "your_token_here"}
    response = requests.post(url, files=files, headers=headers)
    print(response.text)

 

 

cURL

 

curl -X POST \
  mindee_api_url \
  -H 'X-Inferuser-Token: your_token_here' \
  -H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' \
  -F file=@/path/to/your/file.png

 

 

Javascript

Load the following code in an html file and open it with your web browser. The page displays a button allowing you to upload an image. Once uploaded, go check your console, the response is there.

 

<form onsubmit="mindeeSubmit(event)" >
  <input type="file" id="my-file-input" name="file" />
  <input type="submit" />
</form>

<script type="text/javascript">
const mindeeSubmit = (evt) => {
  evt.preventDefault()
  let myFileInput = document.getElementById('my-file-input');
  let myFile = myFileInput.files[0]
  if (!myFile) { return }
  let data = new FormData();
  data.append("file", myFile, myFile.name);

  let xhr = new XMLHttpRequest();

  xhr.addEventListener("readystatechange", function () {
    if (this.readyState === 4) {
      console.log(this.responseText);
    }
  });

  xhr.open("POST", "mindee_api_url");
  xhr.setRequestHeader("X-Inferuser-Token", "your_token_here");
  xhr.send(data);
}
</script>

 

You get something like this ; 

 

 

Ruby

 

require 'uri'
require 'net/http'
require 'net/https'
require 'mime/types'

url = URI("mindee_api_url")
file = "/path/to/your/file.png"

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["content-type"] = 'multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW'
request["X-Inferuser-Token"] = 'your_token_here'
request.body = "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"file\"; filename=\"#{File.basename(file)}\"\r\nContent-Type: #{MIME::Types.type_for(file)}\r\n\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--"

response = http.request(request)
puts response.read_body

 

Node.js

Make sure you have the request package installed before running this code. If not, you can install it in your env by running : 

 

npm install request

 

const fs = require("fs");
const request = require("request");
const options = {
	method: "POST",
	url: "mindee_api_url",
	headers: {
		"X-Inferuser-Token": "your_token_here",
	},
	formData : {
		"file" : fs.createReadStream("/path/to/your/file.png")
	}
};
request(options, function (err, res, body) {
	if(err) console.log(err);
	console.log(body);
});