You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi there, thank you for your amazing work with this API.
As i'm trying to automate the process of creating individual access to a VPN server, I have developed a PHP script that creates a user certificate using the API endpoints System > Certificates.
Is there any available endpoint allowing me to export the vpn client config using this certificate ?
@mrizkihidayat66 once you have the endpoint class written to /usr/local/pkg/RESTAPI/Endpoints/ you'll need to run pfsense-restapi buildendponts to generate the endpoint in the pfSense web root.
You may find these resources useful for building out models and endpoints as well:
@jaredhendrickson13 Hi, thank you. I can now make the API respond, but I still can't get it to return what I expect. Can you help me? I want to be able to download an OpenVPN client configuration file from the API.
The majority of the work for this feature is done and currently in next_minor. Still needs additional tests written and some quirkiness with some of the required pfSense functions to be fully ironed out. Assuming all that goes well, it should be included in v2.6.0.
Dev build v2.6.0-dev-772a828 has this feature implemented and tested for anyone looking to test their own implementations early or get any last minute bugs worked out.
A stable v2.6.0 release likely won't be until shortly after pfSense CE 2.8.1 and pfSense Plus 25.07 are released, so still likely a couple weeks out at least.
@cvanbrummelen Yes, but it is a two step process. The GET /api/v2/vpn/client_export/configs endpoint lists the client export configuration settings you have saved for your OpenVPN servers. If you haven't yet saved an export configuration using the 'Save as default' UI button, or via POST /api/v2/vpn/openvpn/client_export/config, it would be expected that the data list is empty. This process is the API equivalent of reading/saving the main settings on the Client Export page:
Once a configuration is saved, you use its id to generate the actual client installation file. This is done with the POST /api/v2/vpn/openvpn/client_export endpoint, which is the equivalent of using the download links at the bottom of the page:
@jaredhendrickson13 this does push me in the right direction but Im still missing something I think.
I now saved the default config and doing a post to vpn/openvpn/client_export gives more.
However, when I send over the id, type, certref and username I get the error: The OpenVPN client export failed for the following reason: Could not find client certificate.
However If I check the username and refid they are correct.
I did some further debugging and it seems the code from openvpn-client-export.inc (from pfSense itself) is returning the wrong thing.
In this line "$cert = $user['cert'][$crtid];" the $crtid is 30. However the $user array/object returning has the cert with id 30. The certificate itself is ID 30 but inside the $user object/array it has a key value of 0.
When I hardcore the $crtid to 0 it does return the configs.
@cvanbrummelen I'll probably need more info to say for sure. Go ahead and open a new bug report for that issue so I can keep better track of it. In that report, if you can include examples of the requests you're using to reproduce the issue along with the user, certificate, OpenVPN server, and OpenVPN client export config sections from your XML configuration (feel free to obfuscate sensitive data), that will help me determine exactly what's happening and the best way to fix it.
Activity
mrizkihidayat66 commentedon Dec 18, 2024
usr\local\pkg\RESTAPI\Endpoints\VPNOpenVPNExportsEndpoint.inc
usr\local\pkg\RESTAPI\Endpoints\VPNOpenVPNExportEndpoint.inc
usr\local\pkg\RESTAPI\Models\OpenVPNExport.inc
Hi @jaredhendrickson13 can you help me with this case, I'm trying to create this endpoint but not works with 404 Not Found error :'(
jaredhendrickson13 commentedon Dec 18, 2024
@mrizkihidayat66 once you have the endpoint class written to /usr/local/pkg/RESTAPI/Endpoints/ you'll need to run
pfsense-restapi buildendpontsto generate the endpoint in the pfSense web root.You may find these resources useful for building out models and endpoints as well:
https://pfrest.org/BUILDING_CUSTOM_MODEL_CLASSES/
https://pfrest.org/BUILDING_CUSTOM_ENDPOINT_CLASSES/
mrizkihidayat66 commentedon Dec 19, 2024
@jaredhendrickson13 Hi, thank you. I can now make the API respond, but I still can't get it to return what I expect. Can you help me? I want to be able to download an OpenVPN client configuration file from the API.
Ceald1 commentedon Jan 25, 2025
Any updates on this? I also can't figure out how to export the ovpn file from the API?
cvanbrummelen commentedon May 13, 2025
Would love to have this added aswell.
CyberHippo commentedon Jun 5, 2025
That would be a great feature!
cvanbrummelen commentedon Jul 8, 2025
Any luck on getting it to work @mrizkihidayat66 ?
jaredhendrickson13 commentedon Jul 8, 2025
The majority of the work for this feature is done and currently in
next_minor. Still needs additional tests written and some quirkiness with some of the required pfSense functions to be fully ironed out. Assuming all that goes well, it should be included in v2.6.0.cvanbrummelen commentedon Jul 10, 2025
Greate news!
refactor: separate config logic from business logic in OpenVPNClientE…
test(OpenVPNClientExport): add tests for OpenVPN client exports #368
jaredhendrickson13 commentedon Jul 26, 2025
Dev build v2.6.0-dev-772a828 has this feature implemented and tested for anyone looking to test their own implementations early or get any last minute bugs worked out.
A stable v2.6.0 release likely won't be until shortly after pfSense CE 2.8.1 and pfSense Plus 25.07 are released, so still likely a couple weeks out at least.
cvanbrummelen commentedon Sep 8, 2025
I might be doing something wrong but when I call vpn/openvpn/client_export/configs
The return is a 200 code but the data is empty.
Array ( [code] => 200 [status] => ok [response_id] => SUCCESS [message] => [data] => Array ( ) )
This should return all client exports available on the VPN > OpenVPN > Client Export tab right?
jaredhendrickson13 commentedon Sep 9, 2025
@cvanbrummelen Yes, but it is a two step process. The GET /api/v2/vpn/client_export/configs endpoint lists the client export configuration settings you have saved for your OpenVPN servers. If you haven't yet saved an export configuration using the 'Save as default' UI button, or via POST /api/v2/vpn/openvpn/client_export/config, it would be expected that the
datalist is empty. This process is the API equivalent of reading/saving the main settings on the Client Export page:Once a configuration is saved, you use its
idto generate the actual client installation file. This is done with the POST /api/v2/vpn/openvpn/client_export endpoint, which is the equivalent of using the download links at the bottom of the page:cvanbrummelen commentedon Sep 9, 2025
@jaredhendrickson13 this does push me in the right direction but Im still missing something I think.
I now saved the default config and doing a post to vpn/openvpn/client_export gives more.
However, when I send over the id, type, certref and username I get the error: The OpenVPN client export failed for the following reason: Could not find client certificate.
However If I check the username and refid they are correct.
cvanbrummelen commentedon Sep 9, 2025
I did some further debugging and it seems the code from openvpn-client-export.inc (from pfSense itself) is returning the wrong thing.
In this line "$cert = $user['cert'][$crtid];" the $crtid is 30. However the $user array/object returning has the cert with id 30. The certificate itself is ID 30 but inside the $user object/array it has a key value of 0.
When I hardcore the $crtid to 0 it does return the configs.
cvanbrummelen commentedon Sep 22, 2025
Any info about this @jaredhendrickson13 ?
jaredhendrickson13 commentedon Sep 23, 2025
@cvanbrummelen I'll probably need more info to say for sure. Go ahead and open a new bug report for that issue so I can keep better track of it. In that report, if you can include examples of the requests you're using to reproduce the issue along with the user, certificate, OpenVPN server, and OpenVPN client export config sections from your XML configuration (feel free to obfuscate sensitive data), that will help me determine exactly what's happening and the best way to fix it.