Skip to content
Website

Access token

You will need to request new access token on the beginning and in rare cases when access token renewal with refresh token fails.

POST/oauth/token

You will need to request new access token on the beginning and in rare cases when access token renewal with refresh token fails. Refresh token is always returned with each new or refreshed access token and you need to store it for future access token renewals.

You can request new access token if you have datamolino login/password, client_id and client_secret (resource owner password credentials grant) or when you have access code, client_id and client_secret (access code grant). Access token will be valid 2 hours since creation.

For more info please see OAuth 2.0 official protocol specification or contact our support.

Known pitfalls

In case you get response code 400 (bad request) on /oauth/token POST requests where you are posting json in the request body please check the validity of the json. For example forgotten comma after the last json key will cause the request to fail.

Headers

Name Example Description
Content-Type application/json -

Request body

{
  "client_id": "demo_client_id",
  "client_secret": "demo_client_secret",
  "username": "integrator@example.com",
  "password": "demo_password",
  "grant_type": "password"
}

Code examples

cURL

curl --request POST 'https://app.datamolino.com/oauth/token' \
  --header 'Content-Type: application/json' \
  --data '{
  "client_id": "demo_client_id",
  "client_secret": "demo_client_secret",
  "username": "integrator@example.com",
  "password": "demo_password",
  "grant_type": "password"
}'

HTTP

POST /oauth/token HTTP/1.1
Host: app.datamolino.com
Content-Type: application/json

{
  "client_id": "demo_client_id",
  "client_secret": "demo_client_secret",
  "username": "integrator@example.com",
  "password": "demo_password",
  "grant_type": "password"
}

JavaScript Fetch

const response = await fetch("https://app.datamolino.com/oauth/token", {
  method: "POST",
  headers: {
"Content-Type": "application/json"
  },
  body: JSON.stringify({
"client_id": "demo_client_id",
"client_secret": "demo_client_secret",
"username": "integrator@example.com",
"password": "demo_password",
"grant_type": "password"
  }),
});

const data = await response.json();

Node.js Axios

import axios from "axios";

const response = await axios({
  method: "post",
  url: "https://app.datamolino.com/oauth/token",
  headers: {
"Content-Type": "application/json"
  },
  data: {
"client_id": "demo_client_id",
"client_secret": "demo_client_secret",
"username": "integrator@example.com",
"password": "demo_password",
"grant_type": "password"
  }
});

console.log(response.data);

Python Requests

import requests

url = "https://app.datamolino.com/oauth/token"
headers = {
  "Content-Type": "application/json"
}
payload = {
  "client_id": "demo_client_id",
  "client_secret": "demo_client_secret",
  "username": "integrator@example.com",
  "password": "demo_password",
  "grant_type": "password"
}

response = requests.request("POST", url, headers=headers, json=payload)
response.raise_for_status()
print(response.json())

Ruby Net::HTTP

require 'json'
require 'net/http'

uri = URI("https://app.datamolino.com/oauth/token")
request = Net::HTTP::Post.new(uri)
request["Content-Type"] = "application/json"
request.body = <<~JSON
{
  "client_id": "demo_client_id",
  "client_secret": "demo_client_secret",
  "username": "integrator@example.com",
  "password": "demo_password",
  "grant_type": "password"
}
JSON

response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == "https") do |http|
  http.request(request)
end

puts JSON.parse(response.body)

Ruby on Rails

# app/services/datamolino_client.rb
require 'json'
require 'net/http'

class DatamolinoClient
  BASE_URL = "https://app.datamolino.com"

  def initialize(access_token: Rails.application.credentials.dig(:datamolino, :access_token))
@access_token = access_token
  end

  def request_access_token
uri = URI("#{BASE_URL}/oauth/token")
request = Net::HTTP::Post.new(uri)
request["Content-Type"] = "application/json"
request.body = <<~JSON
  {
    "client_id": "demo_client_id",
    "client_secret": "demo_client_secret",
    "username": "integrator@example.com",
    "password": "demo_password",
    "grant_type": "password"
  }
JSON

response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
  http.request(request)
end

JSON.parse(response.body)
  end
end

PHP Guzzle

<?php

use GuzzleHttp\Client;

$client = new Client();
$response = $client->request('POST', 'https://app.datamolino.com/oauth/token', [
'headers' => json_decode('{"Content-Type":"application/json"}', true),
'json' => json_decode('{"client_id":"demo_client_id","client_secret":"demo_client_secret","username":"integrator@example.com","password":"demo_password","grant_type":"password"}', true)
]);

echo $response->getBody();

Java OkHttp

OkHttpClient client = new OkHttpClient();

RequestBody body = RequestBody.create("{\n  \"client_id\": \"demo_client_id\",\n  \"client_secret\": \"demo_client_secret\",\n  \"username\": \"integrator@example.com\",\n  \"password\": \"demo_password\",\n  \"grant_type\": \"password\"\n}", MediaType.parse("application/json"));
Request request = new Request.Builder()
.url("https://app.datamolino.com/oauth/token")
.addHeader("Content-Type", "application/json")
.method("POST", body)
.build();

Response response = client.newCall(request).execute();

C# HttpClient

using var client = new HttpClient();
using var request = new HttpRequestMessage(HttpMethod.Post, "https://app.datamolino.com/oauth/token");
request.Content = new StringContent("{\n  \"client_id\": \"demo_client_id\",\n  \"client_secret\": \"demo_client_secret\",\n  \"username\": \"integrator@example.com\",\n  \"password\": \"demo_password\",\n  \"grant_type\": \"password\"\n}", Encoding.UTF8, "application/json");

using var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());

Go Native

client := &http.Client{}
req, err := http.NewRequest("POST", "https://app.datamolino.com/oauth/token", strings.NewReader("{\n  \"client_id\": \"demo_client_id\",\n  \"client_secret\": \"demo_client_secret\",\n  \"username\": \"integrator@example.com\",\n  \"password\": \"demo_password\",\n  \"grant_type\": \"password\"\n}"))
if err != nil { panic(err) }
req.Header.Add("Content-Type", "application/json")

res, err := client.Do(req)
if err != nil { panic(err) }
defer res.Body.Close()

body, err := io.ReadAll(res.Body)
if err != nil { panic(err) }
fmt.Println(string(body))

Swift URLSession

import Foundation

var request = URLRequest(url: URL(string: "https://app.datamolino.com/oauth/token")!)
request.httpMethod = "POST"
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.httpBody = "{\n  \"client_id\": \"demo_client_id\",\n  \"client_secret\": \"demo_client_secret\",\n  \"username\": \"integrator@example.com\",\n  \"password\": \"demo_password\",\n  \"grant_type\": \"password\"\n}".data(using: .utf8)

let (data, _) = try await URLSession.shared.data(for: request)
print(String(data: data, encoding: .utf8)!)

Responses

200 OK

Content type: application/json; charset=utf-8

{
  "access_token": "demo_access_token",
  "token_type": "bearer",
  "expires_in": 7200,
  "refresh_token": "demo_refresh_token",
  "created_at": 1571911582
}

Type to search…

↑↓ navigate↵ selectEsc close