Create post

This example shows how to integrate another application with zira feed by demonstrating how to automatically create post on zira channel using data retrieved by RSS feed.

Posting on zira channel will notify all channel followers when new post was added.

The example code can be easily modified in order to support data fetching from any API endpoint

1. Create new application and generate API-key

add application2
Add New Application
add application3
Generate API Key

For more details: Applications & API Keys

2. copy the channel-id

As describe in Add post API-Reference, the expected payload is:

{
    "title":"Post title",
    "content": "Post content",
    "toChannelId": "The channel id, where the post will appear"
}

The channel id can be copied from the address bar as appear in bellow image:

copy channel id
Copy channel id from address bar

3. Code example

This example is written in javascript.

const url  = 'https://feeds.simplecast.com/54nAGcIl' // this is a url for rss feed
const newPostUrl = 'https://api.zira.us/public/post' // this is the url for creation of a new post
const apiKey = '9c3bd0ea-1ada-42b2-859d-c12196c6336e' // this is the application key 

// npm install -s rss-parser
const Parser = require('rss-parser') // this node module is used the fetch and parse rss feed.
// npm install -s rss-parser
const fetch = require('node-fetch') // this node module is used to send a POST request.

const parser = new Parser()

async function getLatestItem(){
    const feed = await parser.parseURL(url)

// here we are creating the post content
    const content = 'Date: ' + feed.items[0].pubDate + '\n' +  feed.items[0].contentSnippet + '\n Link : \n' + feed.items[0].enclosure.url 

    const myBody = {
        content : content,
        toChannelId : '5789'
    }
    const options = {
        method : 'POST', 
        body : JSON.stringify(myBody),
        headers : {
            'X-API-Key' : apiKey,
            'Content-Type' : 'application/json'
        }
    }
    await fetch(newPostUrl, options)
}
getLatestItem()

4. Result

the result of this execution is a generation of a single post with the latest entry at the rss feed:

rss post
News post created by application fetching latest post of rss feed

Related videos