mmmttzz
mmmttzz

Reputation: 81

Assistance Needed with User Creation in AXIS Entry Manager via VAPIX API

I'm currently working on integrating with the AXIS Entry Manager through the VAPIX API, and I've hit a bit of a roadblock. I'm trying to create a user via a cURL request, but I keep encountering errors and it seems I'm not formatting the user information correctly.

I'm attempting to make a POST request to the following URL: http://myip/vapix/pacs/, using Digest authentication with the credentials (root / ******). My goal is to add a new user with specific attributes, including first and last names.

Here's the PHP cURL snippet I'm using:

$url = 'http://myip/vapix/pacs/';
$username = 'root';
$password = '*****';

$userData = [
    "User" => [
        [
            "Name" => "Freeman, Gordon",
            "Description" => "",
            "Attribute" => [
                [
                    "Name" => "FirstName",
                    "Value" => "Gordon"
                ],
                [
                    "Name" => "LastName",
                    "Value" => "Freeman"
                ]
            ]
        ]
    ]
];

$jsonPayload = json_encode($userData);

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, ['action' => 'axudb:SetUser', 'User' => $jsonPayload]); // Notera: Justera detta beroende på API:s förväntningar
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);

$response = curl_exec($ch);

if (curl_errno($ch)) {
    echo 'cURL Error: ' . curl_error($ch);
} else {
    echo "Response: \n$response";
}

curl_close($ch);

However, I keep receiving the following error messages:

  1. "No action specified! path: /vapix/pacs/ options: action=&"
  2. "Well-formed error, simple parse error: axudb:User - Expected boundary at pos 91 \n {"User":\n"

It seems I'm not structuring the User data correctly for the API to process my request. I've consulted the documentation but haven't found a clear example that matches my use case. Also if i leave User empty it works and returns a token as the documentation says it should.

If anyone here has experience with creating users in AXIS Entry Manager via the VAPIX API and could guide me on how to properly format the user data for my cURL request, I would greatly appreciate it. Also, any insights on handling the error codes mentioned above would be incredibly helpful.

Thank you in advance for any assistance!

Upvotes: 1

Views: 98

Answers (0)

Related Questions