I was able to find a solution here.
Add this to $args in setup.php
'show_in_rest' => true,
'rest_base' => 'charts'
Add this to the bottom of the setup.php file.
fistly, you’re registering the fields to get/set in the rest interface.
then you’re registering the specific meta data to the post_type = amchart
add_action("rest_api_init", function () {
register_rest_field("amchart", "_amcharts_html",
[
"get_callback" => function ($post, $field_name, $request, $object_type) {
return get_post_meta($post["id"], $field_name, true);
},
"update_callback" => function ($value, $post, $field_name, $request, $object_type) {
return update_post_meta($post->ID, $field_name, $value);
}
]);
register_rest_field("amchart", "_amcharts_javascript",
[
"get_callback" => function ($post, $field_name, $request, $object_type) {
return get_post_meta($post["id"], $field_name, TRUE);
},
"update_callback" => function ($value, $post, $field_name, $request, $object_type) {
return update_post_meta($post->ID, $field_name, $value);
}
]);
register_rest_field("amchart", "_amcharts_resources",
[
"get_callback" => function ($post, $field_name, $request, $object_type) {
return get_post_meta($post["id"], $field_name, TRUE);
},
"update_callback" => function ($value, $post, $field_name, $request, $object_type) {
return update_post_meta($post->ID, $field_name, $value);
}
]);
register_rest_field("amchart", "_amcharts_slug",
[ "get_callback" => function ($post, $field_name, $request, $object_type) {
return get_post_meta($post["id"], $field_name, TRUE);
},
"update_callback" => function ($value, $post, $field_name, $request, $object_type) {
return update_post_meta($post->ID, $field_name, $value);
}
]);
});
register_meta('amchart', '_amcharts_html', array(
"type" => "string",
"show_in_rest" => true,
"object_subtype" => "amchart"
));
register_meta('amchart', '_amcharts_javascript', array(
"type" => "string",
"show_in_rest" => true,
"object_subtype" => "amchart"
));
register_meta('amchart', '_amcharts_resources', array(
"type" => "string",
"show_in_rest" => true,
"object_subtype" => "amchart"
));
register_meta('amchart', '_amcharts_slug', array(
"type" => "string",
"show_in_rest" => true,
"object_subtype" => "amchart"
));
The valid post body is:
{
'post_type':'amchart',
'_amcharts_resources':'resource list goes here',
'_amcharts_html':'html content',
'_amcharts_javascript':'javascript content',
'slug':'_amcharts_slug', //or just use the response.id value as the slug if you do not set this explicitly
'title': 'title',
'status': 'publish' //draft, publish, etc
}