Skip to main content

Autentificare

GetAuthenticationToken

cURL
curl -X POST http://localhost:4000/NextUpServices/Services/POST/ \
-H "Content-Type: text/plain" \
-d '{"Method":"GetAuthenticationToken","Params":{"UserName":"demo_user","Password":"Demo1234","Database":"99999999"}}'
Node.js
const fetch = require('node-fetch');

async function login() {
const r = await fetch('http://localhost:4000/NextUpServices/Services/POST/', {
method: 'POST',
headers: { 'Content-Type': 'text/plain' },
body: JSON.stringify({
Method: 'GetAuthenticationToken',
Params: { UserName: 'demo_user', Password: 'Demo1234', Database: '99999999' }
})
});
const json = await r.json();
if (json.Error) throw new Error(json.Error);
return json.Result; // -> '7952bcb9...'
}
PHP
<?php
function nx_login(): string {
$ch = curl_init('http://localhost:4000/NextUpServices/Services/POST/');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => ['Content-Type: text/plain'],
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => json_encode([
'Method' => 'GetAuthenticationToken',
'Params' => ['UserName' => 'demo_user', 'Password' => 'Demo1234', 'Database' => '99999999']
])
]);
$body = json_decode(curl_exec($ch), true);
curl_close($ch);
if (!empty($body['Error'])) throw new RuntimeException($body['Error']);
return $body['Result'];
}
Python
import requests

def nx_login() -> str:
r = requests.post(
'http://localhost:4000/NextUpServices/Services/POST/',
data=json.dumps({
'Method': 'GetAuthenticationToken',
'Params': {'UserName': 'demo_user', 'Password': 'Demo1234', 'Database': '99999999'}
}),
headers={'Content-Type': 'text/plain'},
)
body = r.json()
if body.get('Error'):
raise RuntimeError(body['Error'])
return body['Result']

Logout

cURL
curl -X POST http://localhost:4000/NextUpServices/Services/POST/ \
-H "Content-Type: text/plain" \
-d "{\"AuthenticationToken\":\"$NX_TOKEN\",\"Method\":\"Logout\",\"Params\":{}}"

Wrapper helper recomandat

Node.js — helper SDK minim
class NextUpClient {
constructor(baseUrl, creds) {
this.baseUrl = baseUrl;
this.creds = creds;
this.token = null;
}
async _call(method, params = {}) {
if (!this.token && method !== 'GetAuthenticationToken') await this.login();
const envelope = { Method: method, Params: params };
if (this.token) envelope.AuthenticationToken = this.token;
const r = await fetch(this.baseUrl, {
method: 'POST',
headers: { 'Content-Type': 'text/plain' },
body: JSON.stringify(envelope)
});
const j = await r.json();
if (j.Error && /expirat|invalid/i.test(j.Error)) {
this.token = null;
return this._call(method, params); // retry o singură dată
}
if (j.Error) throw new Error(`${method}: ${j.Error}`);
return j.Result;
}
async login() {
const t = await this._call('GetAuthenticationToken', this.creds);
this.token = t;
return t;
}
async getAllArticles() { return this._call('GetAllArticles'); }
async addPartner(p) { return this._call('AddPartner', p); }
async addSaleInvoice(s) { return this._call('AddSaleInvoice', s); }
}