A sample 'ticket' given by Melanie Bouic for me to practice with CMA:
- Create a content model on contentful platform: Name "product" with the following fields:
Field name | Field value | Required |
---|---|---|
Title | short text | true |
Path | short text | |
Label | short tet | |
Introduction | long text | |
shop | reference accepting only specific values -"Shop" with appearance: "entry Link" |
Creation of script
- Communication with contentful management API
- Populate the contentType with 1 content:
Field name | Field value |
---|---|
title | sensitve pampers |
path | pampers.com/sensitive |
label | wipes |
introduction | { introduction } |
{ introduction } : Pampers Swaddlers diapers are the number one choice of hospitals, based on, protection, comfort, dryness and more. Buy now at Pampers.com
- A function to create a field name "slug" - short text with the value found in the title field. Published the content.
- create a log file (log.txt) in the following format DATE: Wed May 03 2023 10:47:22 GMT+0400 (Mauritius Standard Time) Published "filed Name"- id: "ID"
- Create another another field called "US shop" in boolean type with default value true
- append your log file with successful or unsuccessful response (in the same format above)
- Delete the field "Shop" append your log file with successful or unsuccessful response (in the same format above)
The main function is where you would run your tasks
Operations | Function | Parameters | Return |
---|---|---|---|
Connect to CMA | connect | env | |
Create an entry | createEntry | env, entry | |
Create a field | createField | env, field | |
Update a field | updateField | env, field | |
Delete a field | deleteField | env, field |
**Note: **
Re-running the script as it is would cause an error, which will be catched in a catch statement and be logged to log.txt. Plausible scenario: Creating the same field twice.
- Since, the function createField does not check if the field already exists, an error will be caught and logged.
Thank you for your attention, If you have any suggestions, please let me know. 😃