Authentication examples
Argip API is protected with OAuth 2.0. Every request to the API must carry an access token in the header Authorization: Bearer <access token>.
We support the Client Credentials flow, used for server-to-server (machine-to-machine) communication. You need three pieces of information:
- Client ID
- Client secret
- Token endpoint:
https://identityserver.argip.com.pl/connect/token
Contact our sales department to get your Client ID and Client secret.
Send a POST request to the token endpoint with the fields grant_type=client_credentials, client_id and client_secret as a form (Content-Type: application/x-www-form-urlencoded). A JSON body is rejected with 400 {"error":"invalid_request"}.
Please DO NOT request a new access token for every API call! A token is valid for 8 hours (expires_in = 28800 seconds). Keep it and request a new one shortly before it expires.
The token endpoint answers:
{
"access_token": "eyJhbGciOiJSUzI1NiIs...",
"expires_in": 28800,
"token_type": "Bearer"
}
Each example below gets a token and uses it to call GET https://argipapi.argip.com.pl/v1/Customer/Info. Replace YOUR_CLIENT_ID and YOUR_CLIENT_SECRET with your credentials, and in real code read them from configuration, never hard-code them.
cURL
Linux, macOS or Git Bash (uses jq to read the token):
TOKEN=$(curl -s -X POST https://identityserver.argip.com.pl/connect/token \ -d grant_type=client_credentials \ -d client_id=YOUR_CLIENT_ID \ -d client_secret=YOUR_CLIENT_SECRET | jq -r .access_token) curl -H "Authorization: Bearer $TOKEN" https://argipapi.argip.com.pl/v1/Customer/Info
Windows cmd (copy access_token from the first response into the second command):
curl -X POST https://identityserver.argip.com.pl/connect/token -d "grant_type=client_credentials&client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET" curl -H "Authorization: Bearer ACCESS_TOKEN" https://argipapi.argip.com.pl/v1/Customer/Info
PowerShell
$token = Invoke-RestMethod -Method Post -Uri "https://identityserver.argip.com.pl/connect/token" `
-ContentType "application/x-www-form-urlencoded" `
-Body @{ grant_type = "client_credentials"; client_id = "YOUR_CLIENT_ID"; client_secret = "YOUR_CLIENT_SECRET" }
Invoke-RestMethod -Uri "https://argipapi.argip.com.pl/v1/Customer/Info" `
-Headers @{ Authorization = "Bearer $($token.access_token)" }
C# (.NET 8 or newer)
using System.Net.Http.Headers;
using System.Text.Json;
using var http = new HttpClient();
// FormUrlEncodedContent sends the fields as application/x-www-form-urlencoded.
var tokenResponse = await http.PostAsync("https://identityserver.argip.com.pl/connect/token",
new FormUrlEncodedContent(new Dictionary<string, string>
{
["grant_type"] = "client_credentials",
["client_id"] = "YOUR_CLIENT_ID",
["client_secret"] = "YOUR_CLIENT_SECRET",
}));
tokenResponse.EnsureSuccessStatusCode();
using var token = JsonDocument.Parse(await tokenResponse.Content.ReadAsStringAsync());
var accessToken = token.RootElement.GetProperty("access_token").GetString();
http.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
Console.WriteLine(await http.GetStringAsync("https://argipapi.argip.com.pl/v1/Customer/Info"));
Java (11 or newer)
import java.net.URI;
import java.net.URLEncoder;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.charset.StandardCharsets;
import java.util.regex.Pattern;
public class ArgipApiExample {
public static void main(String[] args) throws Exception {
var http = HttpClient.newHttpClient();
var form = "grant_type=client_credentials"
+ "&client_id=" + URLEncoder.encode("YOUR_CLIENT_ID", StandardCharsets.UTF_8)
+ "&client_secret=" + URLEncoder.encode("YOUR_CLIENT_SECRET", StandardCharsets.UTF_8);
var tokenRequest = HttpRequest.newBuilder(URI.create("https://identityserver.argip.com.pl/connect/token"))
.header("Content-Type", "application/x-www-form-urlencoded")
.POST(HttpRequest.BodyPublishers.ofString(form))
.build();
var tokenJson = http.send(tokenRequest, HttpResponse.BodyHandlers.ofString()).body();
// Use a JSON library (Jackson, Gson) in real code; a regex keeps this example dependency-free.
var matcher = Pattern.compile("\"access_token\"\\s*:\\s*\"([^\"]+)\"").matcher(tokenJson);
if (!matcher.find()) throw new IllegalStateException("No access token: " + tokenJson);
var apiRequest = HttpRequest.newBuilder(URI.create("https://argipapi.argip.com.pl/v1/Customer/Info"))
.header("Authorization", "Bearer " + matcher.group(1))
.GET()
.build();
System.out.println(http.send(apiRequest, HttpResponse.BodyHandlers.ofString()).body());
}
}
Kotlin (JVM 11 or newer)
import java.net.URI
import java.net.URLEncoder
import java.net.http.HttpClient
import java.net.http.HttpRequest
import java.net.http.HttpResponse
import java.nio.charset.StandardCharsets
fun main() {
val http = HttpClient.newHttpClient()
val form = listOf(
"grant_type" to "client_credentials",
"client_id" to "YOUR_CLIENT_ID",
"client_secret" to "YOUR_CLIENT_SECRET",
).joinToString("&") { (key, value) -> "$key=${URLEncoder.encode(value, StandardCharsets.UTF_8)}" }
val tokenRequest = HttpRequest.newBuilder(URI.create("https://identityserver.argip.com.pl/connect/token"))
.header("Content-Type", "application/x-www-form-urlencoded")
.POST(HttpRequest.BodyPublishers.ofString(form))
.build()
val tokenJson = http.send(tokenRequest, HttpResponse.BodyHandlers.ofString()).body()
// Use a JSON library (kotlinx.serialization, Jackson) in real code; a regex keeps this example dependency-free.
val accessToken = Regex("\"access_token\"\\s*:\\s*\"([^\"]+)\"").find(tokenJson)?.groupValues?.get(1)
?: error("No access token: $tokenJson")
val apiRequest = HttpRequest.newBuilder(URI.create("https://argipapi.argip.com.pl/v1/Customer/Info"))
.header("Authorization", "Bearer $accessToken")
.GET()
.build()
println(http.send(apiRequest, HttpResponse.BodyHandlers.ofString()).body())
}
PHP (8.0 or newer, ext-curl)
<?php
$curl = curl_init('https://identityserver.argip.com.pl/connect/token');
curl_setopt_array($curl, [
CURLOPT_POST => true,
// http_build_query() sends the fields as application/x-www-form-urlencoded.
CURLOPT_POSTFIELDS => http_build_query([
'grant_type' => 'client_credentials',
'client_id' => 'YOUR_CLIENT_ID',
'client_secret' => 'YOUR_CLIENT_SECRET',
]),
CURLOPT_RETURNTRANSFER => true,
]);
$token = json_decode(curl_exec($curl), true);
if (!isset($token['access_token'])) {
exit('Token error: ' . json_encode($token) . PHP_EOL);
}
$curl = curl_init('https://argipapi.argip.com.pl/v1/Customer/Info');
curl_setopt_array($curl, [
CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . $token['access_token']],
CURLOPT_RETURNTRANSFER => true,
]);
echo curl_exec($curl), PHP_EOL;
Python (3.8 or newer, pip install requests)
import requests
token_response = requests.post(
"https://identityserver.argip.com.pl/connect/token",
# data= sends application/x-www-form-urlencoded (json= would be rejected)
data={
"grant_type": "client_credentials",
"client_id": "YOUR_CLIENT_ID",
"client_secret": "YOUR_CLIENT_SECRET",
},
timeout=30,
)
token_response.raise_for_status()
access_token = token_response.json()["access_token"]
response = requests.get(
"https://argipapi.argip.com.pl/v1/Customer/Info",
headers={"Authorization": f"Bearer {access_token}"},
timeout=60,
)
response.raise_for_status()
print(response.json())
JavaScript (Node.js 18 or newer, save as example.mjs)
const tokenResponse = await fetch("https://identityserver.argip.com.pl/connect/token", {
method: "POST",
// URLSearchParams is sent as application/x-www-form-urlencoded.
body: new URLSearchParams({
grant_type: "client_credentials",
client_id: "YOUR_CLIENT_ID",
client_secret: "YOUR_CLIENT_SECRET",
}),
});
if (!tokenResponse.ok) throw new Error(`Token error ${tokenResponse.status}: ${await tokenResponse.text()}`);
const { access_token } = await tokenResponse.json();
const response = await fetch("https://argipapi.argip.com.pl/v1/Customer/Info", {
headers: { Authorization: `Bearer ${access_token}` },
});
console.log(await response.json());
Go
package main
import (
"encoding/json"
"fmt"
"io"
"net/http"
"net/url"
)
func main() {
// PostForm sends the fields as application/x-www-form-urlencoded.
resp, err := http.PostForm("https://identityserver.argip.com.pl/connect/token", url.Values{
"grant_type": {"client_credentials"},
"client_id": {"YOUR_CLIENT_ID"},
"client_secret": {"YOUR_CLIENT_SECRET"},
})
if err != nil {
panic(err)
}
defer resp.Body.Close()
var token struct {
AccessToken string `json:"access_token"`
ExpiresIn int `json:"expires_in"`
}
if err := json.NewDecoder(resp.Body).Decode(&token); err != nil || token.AccessToken == "" {
panic(fmt.Sprintf("token error: HTTP %d", resp.StatusCode))
}
req, _ := http.NewRequest(http.MethodGet, "https://argipapi.argip.com.pl/v1/Customer/Info", nil)
req.Header.Set("Authorization", "Bearer "+token.AccessToken)
apiResp, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer apiResp.Body.Close()
body, _ := io.ReadAll(apiResp.Body)
fmt.Println(string(body))
}
Ruby
require "net/http"
require "json"
require "uri"
# post_form sends the fields as application/x-www-form-urlencoded.
token_response = Net::HTTP.post_form(
URI("https://identityserver.argip.com.pl/connect/token"),
"grant_type" => "client_credentials",
"client_id" => "YOUR_CLIENT_ID",
"client_secret" => "YOUR_CLIENT_SECRET"
)
raise "Token error #{token_response.code}: #{token_response.body}" unless token_response.is_a?(Net::HTTPSuccess)
access_token = JSON.parse(token_response.body)["access_token"]
uri = URI("https://argipapi.argip.com.pl/v1/Customer/Info")
request = Net::HTTP::Get.new(uri)
request["Authorization"] = "Bearer #{access_token}"
response = Net::HTTP.start(uri.host, uri.port, use_ssl: true) { |http| http.request(request) }
puts response.body
Postman
- Create a request
GET https://argipapi.argip.com.pl/v1/Customer/Info. - On the Authorization tab choose type OAuth 2.0.
- Under Configure New Token set Grant type = Client Credentials, Access Token URL =
https://identityserver.argip.com.pl/connect/token, your Client ID and Client Secret, and Client Authentication = Send client credentials in body. - Click Get New Access Token, then Use Token and Send.
Next: browse all endpoints and try them in the API documentation (click Authorize and paste your access token).