Search code examples
http-poststrapi

POST request to create entry is not mapping fields to another collection in Strapi


There are 3 collections, judges,courts and proceedings. While creating a new entry in proceedings which has court, judge, docket(PDF), startdate and endate as their fields i am able to map docket(PDF) using the ID in media library but same doesn't work for court and judges.

Here is my POST call to create a entry:

{
    "startdate": "2020-11-10",
    "enddate": "2020-11-25",
    "judge": {
        "id": 1
    },
    "docket": {
        "id": 1
    },
    "court": {
        "id": 1
    }
}

and my response is:

{
    "id": 24,
    "startdate": "2020-11-10",
    "judge": {},
    "enddate": "2020-11-25",
    "court": {},
    "created_by": null,
    "updated_by": null,
    "created_at": "2020-11-25T09:11:08.338Z",
    "updated_at": "2020-11-25T09:11:08.360Z",
    "docket": [
        {
            "id": 1,
            "name": "Agenda-1.pdf",
            "alternativeText": "",
            "caption": "",
            "width": null,
            "height": null,
            "formats": null,
            "hash": "Agenda_1_708f0363ef",
            "ext": ".pdf",
            "mime": "application/pdf",
            "size": 282.99,
            "url": "/uploads/Agenda_1_708f0363ef.pdf",
            "previewUrl": null,
            "provider": "local",
            "provider_metadata": null,
            "created_by": 1,
            "updated_by": 1,
            "created_at": "2020-08-17T14:07:45.656Z",
            "updated_at": "2020-08-17T14:07:45.862Z"
        }
    ]
}

How do i map court and judge fields just like docket?


Solution

  • Did you try like that :

    {
        "startdate": "2020-11-10",
        "enddate": "2020-11-25",
        "judge": 1,
        "docket": {
            "id": 1
        },
        "court": 1
    }
    

    I guess you can have more than one docket because it’s an array in the output, but for the judge and the court probably just one. So you can do it like there : https://strapi.io/documentation/v3.x/content-api/api-endpoints.html#create-an-entry