Copy link to clipboard
Copied
Hello all,
I am new to this.
I would like to use the BC API to create a blog from a user submitted webapp. A user submits a webapp and the confirmation page takes them to a webapp layout with all details. There a confirm button that should trigger my script below. Page is https://docteur.worldsecuresystems.com/users/submit-a-blog-post you can login as testuser and pass as test1234
My BC API is giving me an error. See below:
<script type="text/javascript">
var access_token = BCAPI.Helper.Site.getAccessToken();
// Wait for the page to load first
window.onload = function() {
var a = document.getElementById("blogPosting");
a.onclick = function() {
$.ajax({
url: "/webresources/api/v3/sites/current/blogposts",
type: "POST",
connection: "keep-alive",
contentType: "application/json",
headers: {
"Authorization": access_token
},
processData: false,
data: JSON.stringify({
"blogId": 11089,
"postTitle": "{tag_name_nolink}",
"createBy": '{module_entityid}',
"postFeaturedImage": '{tag_featuredimage_value}',
"postBody": "{tag_description}",
"releaseDate":' {tag_releasedate}',
"lastUpdateDate": '{tag_lastupdatedate}',
"postUrl": '{tag_itemurl_nolink}',
"metaBlogPostTitle": "{tag_name_nolink}",
"metaBlogPostDescription": "{tag_description}"
})
}).done(function() {
console.log(msg);
})
.fail(function() {
alert( "vous avez eu une erreur veuillez revoir votre code" );
})
return false;
}
}
</script>
I think the issue is with my access token. So far no amount of literature or explanation from chat guys is clear to me. Can someone help me understand how to get an access token?
Copy link to clipboard
Copied
API is not accessible from front-end. Access token could not be obtained from front-end. You could create an admin app that will fetch user web app submissions and convert it to blogs, but that will only work from BC admin. You'll need to trigger the process each time.
Copy link to clipboard
Copied
Just throwing this idea out there:
Another useful method, using UPGR8R's methods mentioned above, is to create a JSON data file from the user submitted web app items within the BC Admin. Then using {module_json} you can read the web app data from the front end, place into a collection and display in a blog styled format.
You would still have the issue of needing to trigger the "webapp-item-to-json export" process. Have not tried exploring this too much, other than from 3rd party servers running a cron type scheduler.
Copy link to clipboard
Copied
Thanks for the responses.
Much appreciated.
Copy link to clipboard
Copied
Jeane,
I'd propose another solution for you. Instead of writing an app to convert a webapp item to a blog post, why not simply use this web app to output like a blog? Unless you really need the authors or tag cloud or other aspects of the built in blog module, I would seriously consider outputting the user submitted web app items as the blog.
At Fuel we use web apps for everything; hardly ever use the built in modules. This scenario you've described above suites a web app environment over the built in modules perfectly.
Try consider this solution as there are many options available to you to make your web app display like a blog. My favourite is {module_webapps id="Blog" filter="all" template="/path/to/template.liquid"}