API: How do I properly create versions with correct release date?

PepiMK

New member
The documentation is a bit unfinished here, but I was able to post new releases.

What doesn't work those is the release_date. The field is the same returned when reading released, and is the one in the documentation.

How do I set the release date from the API when creating a new release version?

PHP:
    protected function create_xenforo_resource_version(string $resource_id, string $version, int $release_date, string $download_url): mixed
    {
        $aHeaders = ['Content-Type: application/x-www-form-urlencoded', 'XF-Api-Key: ' . $this->XenForoAPIKey];
        $aFields = array(
            'resource_id' => $resource_id,
            'version_string' => $version,
            'release_date' => $release_date,
            'external_download_url' => $download_url,
        );
        $ch = curl_init();
        /**
         * api/resource-versions/{$resource_id}/ - invalid endpoint, only GET and DELETE allowed");
         * api/resources/{$resource_id}/versions/ - invalid endpoint, only GET allowed
         */
        curl_setopt($ch, CURLOPT_URL, $this->XenForoURL . "api/resource-versions/");
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($aFields));
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $aHeaders);
        $output = curl_exec($ch);
        curl_close($ch);    
        return json_decode($output);
    }
 
I haven't played around with APIs, but have with form submissions that require a POST or GET request. I also looked into APIs quickly about DELETE, and it all looks pretty much the same.

I don't know if this is helpful with APIs, but with my cases submitting forms, I needed to set GET and POST for forms at times. Could perhaps be the same for APIs?

PHP:
        curl_setopt($ch, CURLOPT_POST, 1);
To:
PHP:
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
 
The other fields (version & download link) are accepted, so it would be strange if that would have to do with GET vs. POST.

Plus, GET only returns data, POST creates entries, and entries are created. So it's doing POST for sure.

And based on the error being that only GET and DELETE are allowed, if it would still GET instead of POST, I wouldn't get that error message.

Maybe one could argue if the value needs to be 1 or true.
But based on new versions appearing with correct data, it gets the correct data.
PHP:
        curl_setopt($ch, CURLOPT_POST, value: 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($new_fields));
 
Back
Top Bottom