Example
- c#
- nodejs
- java
- python
public class ImzoConfig
{
public string Api { get; set; }
public string ApiKey { get; set; }
public string UserName { get; set; }
public string Password { get; set; }
}
public class ImzoHttpClient
{
private ImzoConfig _config;
private HttpClient _httpClient;
public ImzoHttpClient(ImzoConfig config)
{
_config = config;
_httpClient = new HttpClient();
Init();
}
public HttpClient Client => _httpClient;
private void Init()
{
string token = Convert.ToBase64String(Encoding.ASCII.GetBytes($"{_config.UserName}:{_config.Password}"));
_httpClient.BaseAddress = new Uri(_config.Api);
_httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", token);
}
}
public class ImzoCreateResponseDto
{
public Guid RequestId { get; set; }
public string SecretKey { get; set; }
}
public class CommissionDocumentService
{
private readonly ImzoHttpClient _imzoHttpClient;
private readonly ImzoConfig _imzoConfig;
private const string RELATIVE_URL = "v1/SignRequest/Create";
public CommissionDocumentService(ImzoConfig config)
{
_imzoConfig = config;
_imzoHttpClient = new ImzoHttpClient(config);
}
public async Task<ImzoCreateResponseDto> PostSignRequestAsync(CommissionDocument docEntity)
{
var signRequestCreateDto = new ImzoCreateRequestDto()
{
ApiKey = _imzoConfig.ApiKey,
IsForceCreate = false,
TableId = docEntity.TableId,
DocumentId = docEntity.DocumentId,
DocumentType = "COMMISSION_CONCLUSION",
IsAllowMultiple = false,
SignData = JsonConvert.SerializeObject(docEntity),
PrintableLink = "https://testlink.uz/TestDocumentLink.pdf",
SignRequestUsers = docEntity.Members.Select(a =>
new ImzoCreateRequestUserDto
{
UserKey = a.Pinfl,
UserInfo = a.Person,
UserId = a.PersonId,
DocStatusId = StatusIdConst.SENT_TO_AGREE,
SignPriority = a.IsLeader ? 2 : 1, /* rais oxirida imzolashi kerak bo'lsa */
UserPhoneNumber = a.PhoneNumber
})
.ToList(),
SignRequestActionTypes = new List<ImzoCreateRequestActionDto>
{
new ImzoCreateRequestActionDto()
{
ActionTypeId = 2,
ActionTypeName = "Qabul qilish",
Translates = new List<ActionTranslateDto>
{
new ActionTranslateDto()
{
LanguageCode = "RU",
Name = "Принять"
},
new ActionTranslateDto()
{
LanguageCode = "UZ_CYRL",
Name = "Қабул қилиш"
},
new ActionTranslateDto()
{
LanguageCode = "UZ_LATN",
Name = "Qabul qilish"
},
new ActionTranslateDto()
{
LanguageCode = "EN",
Name = "Accept"
}
}
},
new ImzoCreateRequestActionDto()
{
ActionTypeId = 9,
ActionTypeName = "Rad etish",
Translates = new List<ActionTranslateDto>
{
new ActionTranslateDto()
{
LanguageCode = "RU",
Name = "Отклонить"
},
new ActionTranslateDto()
{
LanguageCode = "UZ_CYRL",
Name = "Рад этиш"
},
new ActionTranslateDto()
{
LanguageCode = "UZ_LATN",
Name = "Rad etish"
},
new ActionTranslateDto()
{
LanguageCode = "EN",
Name = "Reject"
}
}
}
},
SignatureMethodIds = new List<int> { SignatureMethodIdConst.E_IMZO }
};
ImzoCreateResponseDto? result = null;
var response = await _imzoHttpClient.Client.PostAsync(RELATIVE_URL, new StringContent(JsonConvert.SerializeObject(signRequestCreateDto), Encoding.UTF8, "application/json"));
if (response.IsSuccessStatusCode)
{
var responseAsString = await response.Content.ReadAsStringAsync();
result = JsonConvert.DeserializeObject<ImzoCreateResponseDto>(responseAsString);
}
Console.WriteLine($"Imzolash uchun havola: https://webimzo.uz/test/app?requestId={result.RequestId}&secretKey={result.SecretKey}");
return result;
}
}
class ImzoConfig {
constructor({ api, apiKey, userName, password }) {
this.api = api;
this.apiKey = apiKey;
this.userName = userName;
this.password = password;
}
}
const axios = require('axios');
class ImzoHttpClient {
constructor(config) {
this.config = config;
this.client = axios.create();
this.init();
}
init() {
const token = Buffer.from(`${this.config.userName}:${this.config.password}`).toString('base64');
this.client.defaults.baseURL = this.config.api;
this.client.defaults.headers.common['Authorization'] = `Basic ${token}`;
this.client.defaults.headers.common['Content-Type'] = 'application/json';
}
getClient() {
return this.client;
}
}
class ImzoCreateResponseDto {
constructor({ requestId, secretKey }) {
this.requestId = requestId;
this.secretKey = secretKey;
}
}
class CommissionDocumentService {
static RELATIVE_URL = 'v1/SignRequest/Create';
constructor(config) {
this.imzoConfig = config;
this.imzoHttpClient = new ImzoHttpClient(config);
}
async postSignRequest(docEntity) {
try {
const signRequestCreateDto = {
apiKey: this.imzoConfig.apiKey,
isForceCreate: false,
tableId: docEntity.tableId,
documentId: docEntity.documentId,
documentType: "COMMISSION_CONCLUSION",
isAllowMultiple: false,
signData: JSON.stringify(docEntity),
printableLink: "https://testlink.uz/TestDocumentLink.pdf",
signRequestUsers: docEntity.members.map(member => ({
userKey: member.pinfl,
userInfo: member.person,
userId: member.personId,
docStatusId: StatusIdConst.SENT_TO_AGREE,
signPriority: member.isLeader ? 2 : 1, // rais oxirida imzolashi kerak bo'lsa
userPhoneNumber: member.phoneNumber
})),
signRequestActionTypes: [
{
actionTypeId: 2,
actionTypeName: "Qabul qilish",
translates: [
{
languageCode: "RU",
name: "Принять"
},
{
languageCode: "UZ_CYRL",
name: "Қабул қилиш"
},
{
languageCode: "UZ_LATN",
name: "Qabul qilish"
},
{
languageCode: "EN",
name: "Accept"
}
]
},
{
actionTypeId: 9,
actionTypeName: "Rad etish",
translates: [
{
languageCode: "RU",
name: "Отклонить"
},
{
languageCode: "UZ_CYRL",
name: "Рад этиш"
},
{
languageCode: "UZ_LATN",
name: "Rad etish"
},
{
languageCode: "EN",
name: "Reject"
}
]
}
],
signatureMethodIds: [SignatureMethodIdConst.E_IMZO]
};
const response = await this.imzoHttpClient.getClient().post(
CommissionDocumentService.RELATIVE_URL,
signRequestCreateDto
);
if (response.status === 200) {
const result = new ImzoCreateResponseDto(response.data);
console.log(
`Imzolash uchun havola: https://webimzo.uz/test/app?requestId=${result.requestId}&secretKey=${result.secretKey}`
);
return result;
}
} catch (error) {
throw new Error(`Error creating sign request: ${error.message}`);
}
}
}
public class ImzoConfig {
private String api;
private String apiKey;
private String userName;
private String password;
// Getters and setters
}
public class ImzoHttpClient {
private final ImzoConfig config;
private final HttpClient httpClient;
public ImzoHttpClient(ImzoConfig config) {
this.config = config;
this.httpClient = HttpClient.newBuilder()
.version(HttpClient.Version.HTTP_2)
.build();
}
public HttpRequest.Builder createRequestBuilder() {
String auth = config.getUserName() + ":" + config.getPassword();
String encodedAuth = Base64.getEncoder().encodeToString(auth.getBytes());
return HttpRequest.newBuilder()
.header("Authorization", "Basic " + encodedAuth)
.header("Content-Type", "application/json");
}
public HttpClient getClient() {
return httpClient;
}
}
public class ImzoCreateResponseDto {
private UUID requestId;
private String secretKey;
// Getters and setters
}
public class CommissionDocumentService {
private static final String RELATIVE_URL = "v1/SignRequest/Create";
private final ImzoHttpClient imzoHttpClient;
private final ImzoConfig imzoConfig;
private final ObjectMapper objectMapper;
public CommissionDocumentService(ImzoConfig config) {
this.imzoConfig = config;
this.imzoHttpClient = new ImzoHttpClient(config);
this.objectMapper = new ObjectMapper();
}
public ImzoCreateResponseDto postSignRequest(CommissionDocument docEntity) throws Exception {
ImzoCreateRequestDto requestDto = new ImzoCreateRequestDto();
requestDto.setApiKey(imzoConfig.getApiKey());
requestDto.setIsForceCreate(false);
requestDto.setTableId(docEntity.getTableId());
requestDto.setDocumentId(docEntity.getDocumentId());
requestDto.setDocumentType("COMMISSION_CONCLUSION");
requestDto.setIsAllowMultiple(false);
requestDto.setSignData(objectMapper.writeValueAsString(docEntity));
requestDto.setPrintableLink("https://testlink.uz/TestDocumentLink.pdf");
List<ImzoCreateRequestUserDto> users = docEntity.getMembers().stream()
.map(member -> {
ImzoCreateRequestUserDto user = new ImzoCreateRequestUserDto();
user.setUserKey(member.getPinfl());
user.setUserInfo(member.getPerson());
user.setUserId(member.getPersonId());
user.setDocStatusId(StatusIdConst.SENT_TO_AGREE);
user.setSignPriority(member.isLeader() ? 2 : 1); // rais oxirida imzolashi kerak bo'lsa
user.setUserPhoneNumber(member.getPhoneNumber());
return user;
})
.collect(Collectors.toList());
requestDto.setSignRequestUsers(users);
requestDto.setSignRequestActionTypes(List.of(
createActionType(2, "Qabul qilish",
Map.of("RU", "Принять",
"UZ_CYRL", "Қабул қилиш",
"UZ_LATN", "Qabul qilish",
"EN", "Accept")),
createActionType(9, "Rad etish",
Map.of("RU", "Отклонить",
"UZ_CYRL", "Рад этиш",
"UZ_LATN", "Rad etish",
"EN", "Reject"))
));
requestDto.setSignatureMethodIds(List.of(SignatureMethodIdConst.E_IMZO));
String jsonBody = objectMapper.writeValueAsString(requestDto);
HttpRequest request = imzoHttpClient.createRequestBuilder()
.uri(URI.create(imzoConfig.getApi() + RELATIVE_URL))
.POST(HttpRequest.BodyPublishers.ofString(jsonBody))
.build();
HttpResponse<String> response = imzoHttpClient.getClient()
.send(request, HttpResponse.BodyHandlers.ofString());
if (response.statusCode() == 200) {
ImzoCreateResponseDto result = objectMapper.readValue(
response.body(), ImzoCreateResponseDto.class);
System.out.printf("Imzolash uchun havola: https://webimzo.uz/test/app?requestId=%s&secretKey=%s%n",
result.getRequestId(), result.getSecretKey());
return result;
}
throw new RuntimeException("Failed to create sign request: " + response.statusCode());
}
private ImzoCreateRequestActionDto createActionType(int id, String name, Map<String, String> translations) {
ImzoCreateRequestActionDto action = new ImzoCreateRequestActionDto();
action.setActionTypeId(id);
action.setActionTypeName(name);
List<ActionTranslateDto> translates = translations.entrySet().stream()
.map(entry -> {
ActionTranslateDto translate = new ActionTranslateDto();
translate.setLanguageCode(entry.getKey());
translate.setName(entry.getValue());
return translate;
})
.collect(Collectors.toList());
action.setTranslates(translates);
return action;
}
}
@dataclass
class ImzoConfig:
api: str
api_key: str
user_name: str
password: str
class ImzoHttpClient:
def __init__(self, config: ImzoConfig):
self.config = config
self.session = requests.Session()
self._init()
def _init(self):
auth = f"{self.config.user_name}:{self.config.password}"
token = base64.b64encode(auth.encode()).decode()
self.session.headers.update({
'Authorization': f'Basic {token}',
'Content-Type': 'application/json'
})
self.session.base_url = self.config.api
@dataclass
class ImzoCreateResponseDto:
request_id: UUID
secret_key: str
class CommissionDocumentService:
RELATIVE_URL = "v1/SignRequest/Create"
def __init__(self, config: ImzoConfig):
self.imzo_config = config
self.imzo_client = ImzoHttpClient(config)
async def post_sign_request(self, doc_entity) -> ImzoCreateResponseDto:
sign_request_create_dto = {
"apiKey": self.imzo_config.api_key,
"isForceCreate": False,
"tableId": doc_entity.table_id,
"documentId": doc_entity.document_id,
"documentType": "COMMISSION_CONCLUSION",
"isAllowMultiple": False,
"signData": json.dumps(doc_entity),
"printableLink": "https://testlink.uz/TestDocumentLink.pdf",
"signRequestUsers": [
{
"userKey": member.pinfl,
"userInfo": member.person,
"userId": member.person_id,
"docStatusId": StatusIdConst.SENT_TO_AGREE,
"signPriority": 2 if member.is_leader else 1, # rais oxirida imzolashi kerak bo'lsa
"userPhoneNumber": member.phone_number
}
for member in doc_entity.members
],
"signRequestActionTypes": [
{
"actionTypeId": 2,
"actionTypeName": "Qabul qilish",
"translates": [
{"languageCode": "RU", "name": "Принять"},
{"languageCode": "UZ_CYRL", "name": "Қабул қилиш"},
{"languageCode": "UZ_LATN", "name": "Qabul qilish"},
{"languageCode": "EN", "name": "Accept"}
]
},
{
"actionTypeId": 9,
"actionTypeName": "Rad etish",
"translates": [
{"languageCode": "RU", "name": "Отклонить"},
{"languageCode": "UZ_CYRL", "name": "Рад этиш"},
{"languageCode": "UZ_LATN", "name": "Rad etish"},
{"languageCode": "EN", "name": "Reject"}
]
}
],
"signatureMethodIds": [SignatureMethodIdConst.E_IMZO]
}
response = self.imzo_client.session.post(
f"{self.imzo_config.api}{self.RELATIVE_URL}",
json=sign_request_create_dto
)
if response.status_code == 200:
result = response.json()
print(
f"Imzolash uchun havola: https://webimzo.uz/test/app?"
f"requestId={result['requestId']}&secretKey={result['secretKey']}"
)
return ImzoCreateResponseDto(
request_id=UUID(result['requestId']),
secret_key=result['secretKey']
)
raise Exception(f"Failed to create sign request: {response.status_code}")