How to set custom field values when creating new page via API ?

Post Reply
metamouse
Jr. Bludit
Posts: 3
Joined: Sun Sep 12, 2021 6:37 am
Location: USA
Contact:

Using the API, how do I pass the custom field values when creating a new page? Please I'd appreciate some help with this. Just need to know if it's even possible and how the format is to send in the curl post.
Example of new page fields via api.

Code: Select all

$fields = array(
            'token' => "ahblah",
            'authentication' => "blahblah",
            'title' => $szz['title'],
            'content' => $szz['description'],
            'slug' => $szz['slug'],
            'coverImage' => $mainimg,
            'tags' => $tagsz,
            'custom' => array (
      'boxart' => $szz['boxart'],
      'horizontalHeaderImage' => $szz['horizontalHeaderImage']
    )
        );
$fields_string = http_build_query($fields);
Doesn't work, can someone show me how to send the custom array along with the new page data?
Last edited by metamouse on Sun Sep 12, 2021 3:53 pm, edited 1 time in total.
User avatar
diego
Site Admin
Posts: 764
Joined: Sat May 16, 2015 2:53 pm
Contact:

Hi,
yes you can send the custom field through the API, but first, you need to define the custom fields in Admin panel > Settings > Custom fields.

Here is the part of the code for the page creation and the custom fields.
https://github.com/bludit/bludit/blob/m ... hp#L68-L78

Regards
Diego
metamouse
Jr. Bludit
Posts: 3
Joined: Sun Sep 12, 2021 6:37 am
Location: USA
Contact:

diego wrote: Sun Sep 12, 2021 1:04 pm Hi,
yes you can send the custom field through the API, but first, you need to define the custom fields in Admin panel > Settings > Custom fields.

Here is the part of the code for the page creation and the custom fields.
https://github.com/bludit/bludit/blob/m ... hp#L68-L78

Regards
Diego
Hey thanks for replying, I already read over that part of the code and still don't know how to send the data correctly. Can you please show me how to pass the data?

I already have defined the custom fields and they show up correctly in the admin panel.
User avatar
diego
Site Admin
Posts: 764
Joined: Sat May 16, 2015 2:53 pm
Contact:

I don't know your code, I mean how do you encode to JSON, I can show you an example I just did with curl command.

Admin panel > Settings > Custom field

Code: Select all

{
    "subtitle": {
        "type": "string",
        "placeholder": "Subtitle for the page"
    }
}
Curl to the API with the custom subtitle

Code: Select all

curl 'http://localhost/api/pages' -H 'content-type: application/json' --data-raw '{"token":"xxxxxxxxxxxxxxx","authentication":"xxxxxxxxxxx", "title":"My new page", "custom":{"subtitle":"Movie time"}}
User avatar
diego
Site Admin
Posts: 764
Joined: Sat May 16, 2015 2:53 pm
Contact:

Notice to create a page via API you need to use the method POST and send the parameters via POST.

Please follow the documentation example and then add the custom field.

https://docs.bludit.com/en/api/create-a-new-page
metamouse
Jr. Bludit
Posts: 3
Joined: Sun Sep 12, 2021 6:37 am
Location: USA
Contact:

diego wrote: Sun Sep 12, 2021 4:44 pm I don't know your code, I mean how do you encode to JSON, I can show you an example I just did with curl command.

Admin panel > Settings > Custom field

Code: Select all

{
    "subtitle": {
        "type": "string",
        "placeholder": "Subtitle for the page"
    }
}
Curl to the API with the custom subtitle

Code: Select all

curl 'http://localhost/api/pages' -H 'content-type: application/json' --data-raw '{"token":"xxxxxxxxxxxxxxx","authentication":"xxxxxxxxxxx", "title":"My new page", "custom":{"subtitle":"Movie time"}}
Exactly what I needed. Thanks a ton!
Post Reply