简体   繁体   English

在 Mikrotik 中使用未命名参数 Rest API

[英]Using Unnamed Parameter In Mikrotik Rest API

I'am making a script that can create and sign Certificate on Mikrotik using their REST API.我正在制作一个脚本,可以使用他们的 REST API 在 Mikrotik 上创建和签署证书。

The script already worked in creating the Certificate, the problem is, signing it.该脚本已经用于创建证书,问题是对其进行签名。

In Mikrotik Command Line, signing a certificate requires Unnamed Parameter, which i dont know how to specify it in the REST API Request.在 Mikrotik 命令行中,签署证书需要未命名参数,我不知道如何在 REST API 请求中指定它。

Here is the detail about the Commands that translates to the REST API Request以下是有关转换为 REST API 请求的命令的详细信息

  1. Creating A Certificate (Worked)创建证书(有效)

CMD: CMD:

> /certificate add name=client-template-to-issue copy-from="client-template" common-name="$USERNAME@$CN"

REST: REST:

URL: https://vpn.mydomain.com/rest/certificate/add
Body: {
    "common-name": "$USERNAME@$CN",
    "name":"client-template-to-issue",
    "copy-from":"client-template"
}
Response: {
    "ret": "*14"
}
  1. Signing A Certificate (Diddnt Work)签署证书(无效)

CMD: CMD:

    /certificate sign client-template-to-issue ca="$CN" name="$USERNAME@$CN"

REST: REST:

URL: https://vpn.mydomain.com/rest/certificate/sign

Body: {
    "ca": "$CN",
    "name":"$USERNAME@$CN"
}

Response: {
    "detail": "failure: At least one field specifying certificate name must be set!",
    "error": 400,
    "message": "Bad Request"
}

So how do i fix this?那么我该如何解决这个问题? the command line suggest that there is a Unnamed Parameter to specify for it to work.命令行建议有一个未命名的参数来指定它的工作。 i already tried with the URL like this我已经像这样尝试过 URL

https://vpn.mydomain.com/rest/certificate/sign/*14

and it still doesnt work它仍然不起作用

The following worked for me:以下对我有用:

URL: https://vpn.mydomain.com/rest/certificate/sign

Body: {
    "ca": "$CN",
    "number":"client-template-to-issue"  # the "name" entry from your example of creating a certificate
}

I'm just not sure if this is a bug.我只是不确定这是否是一个错误。 Tested on ROS 7.7在 ROS 7.7 上测试

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM