# Create a listing using the API

**URL:** <https://community.hivepress.io/t/create-a-listing-using-the-api/10657>\
**Category:** HivePress\
**Tags:** code\
**Created:** [April 25, 2024, 8:30pm UTC](https://community.hivepress.io/t/create-a-listing-using-the-api/10657 "2024-04-25T20:30:07Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![thefourcraft](https://community.hivepress.io/user_avatar/community.hivepress.io/thefourcraft/32/8986_2.png) [@thefourcraft](https://community.hivepress.io/u/thefourcraft)\
**Post date:** [April 25, 2024, 8:30pm UTC](https://community.hivepress.io/t/create-a-listing-using-the-api/10657/1 "2024-04-25T20:30:07Z")

</div>

I want to integrate a Hivepress website with a 3rd party something

But from searching the forum, I found out that this is impossible because the API isn’t 100% covered yet

> [@Add listing via API](https://community.hivepress.io/t/add-listing-via-api/5530):
>
> Is it possible to add listings via API? We currently have a Python script for creating listing descriptions with OpenAI API, and would love to extend its functionality to be able add listings automatically with the REST API- however I noticed the current endpoints were only for updating, deleting, hiding, and reporting listings.

But, WordPress has a good API and form working with Hivepress I know that at the end of the day, this is just a post type “hp\_listing” that handles all the listings

The category for listings is a custom field? or it’s the same as all other post types?

## About API

> **[Update a listing | HivePress REST API documentation](https://bump.sh/hivepress/doc/rest-api/operation/operation-post-listings-parameter)**
>
> In addition to the default listing fields, you can also update custom fields added via the listing attributes or HivePress extensions.

> “In addition to the default listing fields, you can also update custom fields added via the listing attributes or HivePress extensions.”

So, if I have a field that is called “hello\_world” and it’s a text = string field I simply need to make the request like this

Request example

```auto
{
  "title": "string",
  "description": "string"
  "hello_world": "string"
}

```

---

<div class="post-metadata">

**Author:** ![andrii](https://community.hivepress.io/user_avatar/community.hivepress.io/andrii/32/2951_2.png) [@andrii](https://community.hivepress.io/u/andrii)\
**Post date:** [April 26, 2024, 11:41am UTC](https://community.hivepress.io/t/create-a-listing-using-the-api/10657/4 "2024-04-26T11:41:52Z")

</div>

Hi,

Sorry, there are currently no endpoints for listing creation, but we are planning to add this feature. As a workaround, we recommend using the default WP REST API, which is possible because a listing is a custom post type.

---

<div class="post-metadata">

**Author:** ![thefourcraft](https://community.hivepress.io/user_avatar/community.hivepress.io/thefourcraft/32/8986_2.png) [@thefourcraft](https://community.hivepress.io/u/thefourcraft)\
**Post date:** [May 8, 2024, 12:38pm UTC](https://community.hivepress.io/t/create-a-listing-using-the-api/10657/5 "2024-05-08T12:38:10Z")

</div>

The custom post type name is `hp_listing`  
also, the endpoint needs to be activated using this snipit

```php
add_filter( 'register_post_type_args', 'add_rest_api_to_listing_post_type', 10, 2 );
function add_rest_api_to_listing_post_type( $args, $post_type ) {
	// Let's make sure that we're customizing the post type we really need
	if ( $post_type !== 'hp_listing' ) {
		return $args;
	}
	
	$args['show_in_rest'] = true;
	
	return $args;
}

```

---

<div class="post-metadata">

**Author:** ![thefourcraft](https://community.hivepress.io/user_avatar/community.hivepress.io/thefourcraft/32/8986_2.png) [@thefourcraft](https://community.hivepress.io/u/thefourcraft)\
**Post date:** [May 8, 2024, 12:40pm UTC](https://community.hivepress.io/t/create-a-listing-using-the-api/10657/6 "2024-05-08T12:40:54Z")

</div>

Yes, but how can I fill out custom attributes? in the listing?  
From reading the API-limited documentation

> In addition to the default listing fields, you can also update custom fields added via the listing attributes or HivePress extensions.

```auto
{
  "title": "string",
  "description": "string"
  "hello_world": "integer"
  "date": "format_date(iso_date)"
}

```

---

<div class="post-metadata">

**Author:** ![thefourcraft](https://community.hivepress.io/user_avatar/community.hivepress.io/thefourcraft/32/8986_2.png) [@thefourcraft](https://community.hivepress.io/u/thefourcraft)\
**Post date:** [May 8, 2024, 12:49pm UTC](https://community.hivepress.io/t/create-a-listing-using-the-api/10657/7 "2024-05-08T12:49:18Z")

</div>

Also, how do you use the categories? Are they added using the regular WordPress API?

Thanks for the help in advance! 🙂

---

<div class="post-metadata">

**Author:** ![ihor](https://community.hivepress.io/user_avatar/community.hivepress.io/ihor/32/5_2.png) [@ihor](https://community.hivepress.io/u/ihor)\
**Post date:** [May 15, 2024, 7:56pm UTC](https://community.hivepress.io/t/create-a-listing-using-the-api/10657/9 "2024-05-15T19:56:00Z")

</div>

I’m sorry for the delay.

Yes, with the current version you have to use the default WP REST API for the “hp\_listing” post type. The listing submission form is basically the listing update form, because the listing auto-draft is already created if you click the Add Listing button.

Attributes are implemented depending on their type, e.g. text/number attributes are implemented as post meta fields with “hp\_” prefix. Selectable attributes are implemented as custom taxonomies with “hp\_listing\_” prefix, the listing category is a custom taxonomy of “hp\_listing\_category” name.

This way you can still set all the values for attributes on WP level.

---

<div class="post-metadata">

**Author:** ![thefourcraft](https://community.hivepress.io/user_avatar/community.hivepress.io/thefourcraft/32/8986_2.png) [@thefourcraft](https://community.hivepress.io/u/thefourcraft)\
**Post date:** [May 17, 2024, 10:30am UTC](https://community.hivepress.io/t/create-a-listing-using-the-api/10657/10 "2024-05-17T10:30:22Z")

</div>

So I use the WordPress (WP API) for everything  
got it…

---

<div class="post-metadata">

**Author:** ![system](https://community.hivepress.io/user_avatar/community.hivepress.io/system/32/13990_2.png) [@system](https://community.hivepress.io/u/system)\
**Post date:** [June 16, 2024, 10:31am UTC](https://community.hivepress.io/t/create-a-listing-using-the-api/10657/11 "2024-06-16T10:31:19Z")

</div>

Closed on June 16, 2024, 10:31am UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
