Auth
Authenticate
POST
/
auth
Authenticate
curl --request POST \
--url https://api.einvoice.sa.com:9090/v1/e-invoicing/auth \
--header 'Content-Type: application/json' \
--data '
{
"vat_number": "<string>",
"username": "<string>",
"secret": "<string>"
}
'import requests
url = "https://api.einvoice.sa.com:9090/v1/e-invoicing/auth"
payload = {
"vat_number": "<string>",
"username": "<string>",
"secret": "<string>"
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({vat_number: '<string>', username: '<string>', secret: '<string>'})
};
fetch('https://api.einvoice.sa.com:9090/v1/e-invoicing/auth', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_PORT => "9090",
CURLOPT_URL => "https://api.einvoice.sa.com:9090/v1/e-invoicing/auth",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'vat_number' => '<string>',
'username' => '<string>',
'secret' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.einvoice.sa.com:9090/v1/e-invoicing/auth"
payload := strings.NewReader("{\n \"vat_number\": \"<string>\",\n \"username\": \"<string>\",\n \"secret\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.einvoice.sa.com:9090/v1/e-invoicing/auth")
.header("Content-Type", "application/json")
.body("{\n \"vat_number\": \"<string>\",\n \"username\": \"<string>\",\n \"secret\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.einvoice.sa.com:9090/v1/e-invoicing/auth")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"vat_number\": \"<string>\",\n \"username\": \"<string>\",\n \"secret\": \"<string>\"\n}"
response = http.request(request)
puts response.read_bodyWhat it does
Exchanges your registered credentials for an access token. This token must be sent in theAuthorization header on every subsequent API call.
Request Body
string
required
Your organization’s 15-digit VAT registration number
string
required
API username assigned to your account
string
required
API secret/password assigned to your account
Example Request
curl -X POST https://api.einvoice.sa.com:9090/v1/e-invoicing/auth \
-H "Content-Type: application/json" \
-d '{
"vat_number": "311262046600003",
"username": "api",
"secret": "YOUR_SECRET"
}'
Example Response
{
"token": "eyJhbGciOiJIUzI1NiIs...",
"expires_in": 3600
}
Using the Token
Include the returned token on every following request:Authorization: Bearer eyJhbGciOiJIUzI1NiIs...
Errors
| Code | Meaning |
|---|---|
| 401 | Invalid VAT number, username, or secret |
| 400 | Missing required field |
Was this page helpful?
⌘I
Authenticate
curl --request POST \
--url https://api.einvoice.sa.com:9090/v1/e-invoicing/auth \
--header 'Content-Type: application/json' \
--data '
{
"vat_number": "<string>",
"username": "<string>",
"secret": "<string>"
}
'import requests
url = "https://api.einvoice.sa.com:9090/v1/e-invoicing/auth"
payload = {
"vat_number": "<string>",
"username": "<string>",
"secret": "<string>"
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({vat_number: '<string>', username: '<string>', secret: '<string>'})
};
fetch('https://api.einvoice.sa.com:9090/v1/e-invoicing/auth', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_PORT => "9090",
CURLOPT_URL => "https://api.einvoice.sa.com:9090/v1/e-invoicing/auth",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'vat_number' => '<string>',
'username' => '<string>',
'secret' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.einvoice.sa.com:9090/v1/e-invoicing/auth"
payload := strings.NewReader("{\n \"vat_number\": \"<string>\",\n \"username\": \"<string>\",\n \"secret\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.einvoice.sa.com:9090/v1/e-invoicing/auth")
.header("Content-Type", "application/json")
.body("{\n \"vat_number\": \"<string>\",\n \"username\": \"<string>\",\n \"secret\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.einvoice.sa.com:9090/v1/e-invoicing/auth")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"vat_number\": \"<string>\",\n \"username\": \"<string>\",\n \"secret\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body
