Hi,
I think my thought process is correct in the way I’m trying to achieve this, but I’m not sure how to go about it. I’ve searched a few things on Google but I’m new to Postman and this is going over my head, so I apologize in advance.
I’m working with an API that deals with blog posts. In this process, I’d like to “GET” a blog post, run a script that looks at the description value and splits the string into the first 300 characters and assigning that to a new variable, then “PUT” (update) the blog post using this new variable.
In this example, I’ve blocked out any sensitive information and used X’s instead.
1. GET request
https://api.bigcommerce.com/stores/xxxxxxxxxx/v2/blog/posts/{id}
This should return a JSON object with the blog post data. Something like this (for example):
{
"id": 1,
"title": "Welcome to BigCommerce",
"url": "/blog/welcome-bigcommerce/",
"body": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed lacinia ex id ullamcorper suscipit. Phasellus sed augue aliquet, dictum risus in, dictum purus. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Phasellus diam orci, finibus vel arcu id, tempus lobortis sapien. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed lacinia ex id ullamcorper suscipit.",
"is_published": true,
"meta_description": "Blank meta desc"
}
2. Script
Take the JSON, build out another object using the same information (in this case we only want to deal with the body and meta description values.
let metadesc = obj.body.substring(0,300);
3. Create JSON object for body of next request
Somehow translate the metadesc variable into the body of the request
{
"meta_description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed lacinia ex id ullamcorper suscipit. Phasellus sed augue aliquet, dictum risus in, dictum purus. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Phasellus diam orci, finibus vel arcu id, tempus lobort"
}
4. Run PUT request and iterate through the IDs (we have 500 blog posts)
https://api.bigcommerce.com/stores/xxxxxxxxxx/v2/blog/posts/{id}
Sorry for this long-winded question. The end-goal is to scrape our store for 500 blog posts, grab them and take the first 300 characters of the description and insert it into the meta desc field. Rather than do this by hand, I know I can use Postman to do this. I have an idea of how to go about this task but not sure how to combine these steps, where to put the script, or how to iterate the PUT request.
Thanks!