podlove / podlove-publisher

Podlove Podcast Publisher for WordPress
https://wordpress.org/plugins/podlove-podcasting-plugin-for-wordpress/
MIT License
295 stars 82 forks source link

Add Contributor via API #1440

Open Simon1050 opened 4 months ago

Simon1050 commented 4 months ago

Hey there, I have a question. I am using the podlove-api (podlove version 4.0.13) to edit an episode on wordpress. But I do not understand how to add a contributor to the episode. I have tried the endpoints /wp-json/podlove/v2/episodes/72/contributions and /wp-json/podlove/v2/episodes/contributions/72 with { "contributor_id": 1, "role_id": 1, "group_id": 1, "position": 0, "comment": "Host of the episode." } as body, but no contributors were added.

Can somebody tell me, how this is done correctly?

Simon

dnkbln commented 4 months ago

Hello Simon, if you use the endpoint /wp-json/podlove/v2/episode/{episode_id}/contributions the input is a array of contributor. The payload should be

{
    "contributors": [
        {
            "contributor_id": 1,
            "role_id": 1,
            "group_id": 1,
            "position": 10,
            "comment": "Moderator"
        }
    ]
}

If you have more the one Contributor, you can add more objects to the array. But with this method the existing episode contributions will be delete before we add the new ones.

If you use the endpoint /wp-json/podlove/v2/episode/contributions/{id}. The id doesn't mean the episode_id. It means a episode_contributions_id.

GET /wp-json/podlove/v2/episode/{episode_id}/contributions has following result

{
    "_version": "v2",
    "contribution": [
        {
            "id": "371", <---- this is the episode contribution id
            "contributor_id": "1",
            "role_id": "1",
            "group_id": 0,
            "position": "10",
            "comment": "Moderator",
            "default_contributor": true
        }
    ]
}

I hope that helps you.
Dirk
Simon1050 commented 2 months ago

Hi Dirk, sorry for my late answer.

I have tried to add this contributor

{
    "contributors": [
        {
            "contributor_id": 44,
            "role_id": 0,
            "group_id": 0,
            "position": "0",
            "comment": "Test"
        }
    ]
}

by posting to wp-json/podlove/v2/episodes/361/contributions.

But if I try to control this, I only get this result from wp-json/podlove/v2/episodes/361/contributions

{
    "_version": "v2",
    "contribution": [
        {
            "id": "578",
            "contributor_id": null,
            "role_id": 0,
            "group_id": 0,
            "position": null,
            "comment": "",
            "default_contributor": false
        }
    ]
}

from a get request.

On the webpage is shown an empty contributor:

Screenshot 2024-04-14 143816

Do you have any other ideas what I am doing wrong?

Simon

dnkbln commented 2 months ago

Could you please check if the contributor_id 44 is existing. The route wp-json/podlove/v2/contributors deliver a list of the existing contributors. If you aren't authenticate you will get only public contributors.

May I should improve the API. If the contributor_id not exist i should return with an error.

Simon1050 commented 2 months ago

That would be great. And thank You. Now it is working when I post to /wp-json/podlove/v2/episodes/{id}/contributions and then to /wp-json/podlove/v2/episodes/contributions/{id} with the returned contribution id from first request.