It's a simple vercel function which creates Content entries based on Asset data.
Fully configurable through query parameters.
- Run
vercel
cli and answer the questions. - Set environment variables.
Variable | Description |
---|---|
CONTENTFUL_SPACE_ID | https://www.contentful.com/help/spaces/find-space-id/ |
CONTENTFUL_ENVIRONMENT_ID | Optional Next to search in the menu. master will be used if not defined |
CONTENTFUL_MANAGEMENT_API_KEY | https://app.contentful.com/account/profile/cma_tokens |
CONTENTFUL_HOOK_SECRET | Optional Your custom text to secure the endpoint |
Parameter | Default | Description |
---|---|---|
contentTypeToCreate |
required |
Content type api id which will be used for entry creation |
referenceField |
required |
Field which will reference created Asset. Can be a list of fields separated by , |
titleField |
optional |
Asset field title data will be put into this field for contentTypeToCreate . Can be a list of fields separated by , |
descriptionField |
optional |
Asset field description data will be put into this field for contentTypeToCreate . Can be a list of fields separated by , |
fileField |
optional |
Assetfilename will be put into this field for contentTypeToCreate . Can be a list of fields separated by , |
locale |
en-US |
Which locale to use when filling out the fields |
idSuffix |
-media |
Same asset id will be used for entry. Only difference is idSuffix |
- Go to you
master
environment - Click cog icon next to your profile avatar
- Select Webhooks menu entry
- Click
+ Add Webhook
button - Fill in descriptive name
- Use POST method for URL. Use your vercel deployment URL as the root suffixed with
/api/createAsset
and add parameters. For example:https://vercel-contentful-hook-tasks.vercel.app/api/createAsset?contentTypeToCreate=mediaImage&referenceField=image&titleField=alt,internalName&descriptionField=figcaption
- For trigger - check
Publish
onAsset
row in Content Events. - (Optional) If you have
CONTENTFUL_HOOK_SECRET
configured- In
Headers
click+ Add secret headers
button - For key use
authorization
and for value - same value configured inCONTENTFUL_HOOK_SECRET
environment variable.
- In
- Ensure that for Payload
Use default payload
is selected. - Click save
If this project is deployed and everything is configured correctly - your content entry will be created once Asset is published.