Skip to content

Post API Add Post Example Text and Image

Dominik Magdaleński edited this page Jul 3, 2019 · 1 revision

Post API - /add_post - Text and Image template example

  1. Add MediaUploadRequest:

    Request:

    http --follow POST https://dive-networks.com/api/rpc/34/add_media_upload_request \
    Authorization:"Token your-api-token-here" \
    media_type=image
    

    Response:

    HTTP/1.1 201 Created
    (...headers...)
    
    {
        "result": {
            "created_at": "2019-06-21T08:44:48.158557-04:00", 
            "data": {}, 
            "expires_at": "2019-06-21T08:54:47.675749-04:00", 
            "id": 5, 
            "media_type": "image", 
            "presigned_s3_post": {
                "fields": {
                    "key": "images/9744b4c4-7900-4b4e-b6be-48bb9be1de39", 
                    "policy": "eyJleHBpcmF0aW9uIjogIjIwMTktMDYtMjFUMTI6NTQ6NDhaIiwgImNvbmRpdGlvbnMiOiBbWyJjb250ZW50LWxlbmd0aC1yYW5nZSIsIDAsIDIwOTcxNTIwXSwgeyJidWNrZXQiOiAiZGl2ZS1tZWRpYS11cGxvYWQtdGVzdC0yMjA0MjAxOSJ9LCB7ImtleSI6ICJpbWFnZXMvOTc0NGI0YzQtNzkwMC00YjRlLWI2YmUtNDhiYjliZTFkZTM5In0sIHsieC1hbXotYWxnb3JpdGhtIjogIkFXUzQtSE1BQy1TSEEyNTYifSwgeyJ4LWFtei1jcmVkZW50aWFsIjogIkFLSUFYTDdFQUdEUVFHRUhXUVFJLzIwMTkwNjIxL2V1LWNlbnRyYWwtMS9zMy9hd3M0X3JlcXVlc3QifSwgeyJ4LWFtei1kYXRlIjogIjIwMTkwNjIxVDEyNDQ0OFoifV19", 
                    "x-amz-algorithm": "AWS4-HMAC-SHA256", 
                    "x-amz-credential": "AKIAXL7EAGDQQGEHWQQI/20190621/eu-central-1/s3/aws4_request", 
                    "x-amz-date": "20190621T124448Z", 
                    "x-amz-signature": "46194b8326491e9b92b3d143147fca708817e757c7ead46bde12c87745253eb7"
                }, 
                "url": "https://dive-media-upload-test-22042019.s3.amazonaws.com/"
            }, 
            "status": "init", 
            "updated_at": "2019-06-21T08:44:48.158630-04:00"
        }
    }
    
  2. Upload image (copy URL and form field values from the MediaUploadRequest):

    Request:

    http --follow --form POST https://dive-media-upload-test-22042019.s3.amazonaws.com/ \
    key="images/9744b4c4-7900-4b4e-b6be-48bb9be1de39" \
    policy="eyJleHBpcmF0aW9uIjogIjIwMTktMDYtMjFUMTI6NTQ6NDhaIiwgImNvbmRpdGlvbnMiOiBbWyJjb250ZW50LWxlbmd0aC1yYW5nZSIsIDAsIDIwOTcxNTIwXSwgeyJidWNrZXQiOiAiZGl2ZS1tZWRpYS11cGxvYWQtdGVzdC0yMjA0MjAxOSJ9LCB7ImtleSI6ICJpbWFnZXMvOTc0NGI0YzQtNzkwMC00YjRlLWI2YmUtNDhiYjliZTFkZTM5In0sIHsieC1hbXotYWxnb3JpdGhtIjogIkFXUzQtSE1BQy1TSEEyNTYifSwgeyJ4LWFtei1jcmVkZW50aWFsIjogIkFLSUFYTDdFQUdEUVFHRUhXUVFJLzIwMTkwNjIxL2V1LWNlbnRyYWwtMS9zMy9hd3M0X3JlcXVlc3QifSwgeyJ4LWFtei1kYXRlIjogIjIwMTkwNjIxVDEyNDQ0OFoifV19" \
    x-amz-algorithm="AWS4-HMAC-SHA256" \
    x-amz-credential="AKIAXL7EAGDQQGEHWQQI/20190621/eu-central-1/s3/aws4_request" \
    x-amz-date="20190621T124448Z" \
    x-amz-signature="46194b8326491e9b92b3d143147fca708817e757c7ead46bde12c87745253eb7" \
    file@~/Pictures/sample.jpg
    

    Response:

    HTTP/1.1 204 No Content
    (...headers...)
    
  3. Get "data" from the MediaUploadRequest (it should be ready after a short while):

    Request:

    http --follow https://dive-networks.com/api/rpc/34/get_media_upload_request?id=5 \
    Authorization:"Token your-api-token-here"
    

    Response:

    HTTP/1.1 200 OK
    (...headers...)
    
    {
        "result": {
            "created_at": "2019-06-21T08:44:48.158557-04:00", 
            "data": {
                "image_height": 720, 
                "image_url": "https://cdn.filestackcontent.com/A7vPk5MRSi012J5glu7A", 
                "image_width": 480, 
                "uploaded_file_s3_bucket": "dive-cms-media", 
                "uploaded_file_s3_key": "s/i/UHxC3uopSXq91L7m8GnC_convert.jpg", 
                "uploaded_file_size_bytes": 74718
            }, 
            "expires_at": "2019-06-21T08:54:47.675749-04:00", 
            "id": 5, 
            "media_type": "image", 
            "presigned_s3_post": {
                "fields": {
                    "key": "images/9744b4c4-7900-4b4e-b6be-48bb9be1de39", 
                    "policy": "eyJleHBpcmF0aW9uIjogIjIwMTktMDYtMjFUMTI6NTY6MTFaIiwgImNvbmRpdGlvbnMiOiBbWyJjb250ZW50LWxlbmd0aC1yYW5nZSIsIDAsIDIwOTcxNTIwXSwgeyJidWNrZXQiOiAiZGl2ZS1tZWRpYS11cGxvYWQtdGVzdC0yMjA0MjAxOSJ9LCB7ImtleSI6ICJpbWFnZXMvOTc0NGI0YzQtNzkwMC00YjRlLWI2YmUtNDhiYjliZTFkZTM5In0sIHsieC1hbXotYWxnb3JpdGhtIjogIkFXUzQtSE1BQy1TSEEyNTYifSwgeyJ4LWFtei1jcmVkZW50aWFsIjogIkFLSUFYTDdFQUdEUVFHRUhXUVFJLzIwMTkwNjIxL2V1LWNlbnRyYWwtMS9zMy9hd3M0X3JlcXVlc3QifSwgeyJ4LWFtei1kYXRlIjogIjIwMTkwNjIxVDEyNDYxMVoifV19", 
                    "x-amz-algorithm": "AWS4-HMAC-SHA256", 
                    "x-amz-credential": "AKIAXL7EAGDQQGEHWQQI/20190621/eu-central-1/s3/aws4_request", 
                    "x-amz-date": "20190621T124611Z", 
                    "x-amz-signature": "33b03a64b06c03252e79b91b6b8810b0637f4c52279ab52d3e2827d663766fd6"
                }, 
                "url": "https://dive-media-upload-test-22042019.s3.amazonaws.com/"
            }, 
            "status": "succeeded", 
            "updated_at": "2019-06-21T08:46:11.780672-04:00"
        }
    }
    
  4. Add Post:

    body.json:

    {
      "template": "text+image",
      "title": "Look at that!",
      "body": "Did you see that image?",
      "content_zones": [
        15
      ],
      "image_height": 720,
      "image_url": "https://cdn.filestackcontent.com/A7vPk5MRSi012J5glu7A",
      "image_width": 480,
      "uploaded_file_s3_bucket": "dive-cms-media",
      "uploaded_file_s3_key": "s/i/UHxC3uopSXq91L7m8GnC_convert.jpg",
      "uploaded_file_size_bytes": 74718
    }
    

    Request:

    http --follow POST https://dive-networks.com/api/rpc/34/add_post \
    Authorization:"Token your-api-token-here" \
    < body.json
    

    Response:

    HTTP/1.1 201 Created
    (...headers...)
    
    {
        "result": {
            "background_color": "ffffff", 
            "body": "Did you see that image?", 
            "content_zones": [
                15
            ], 
            "duration": null, 
            "frequency": 300, 
            "fullscreen_playback": false, 
            "id": 13354, 
            "iframe_url": null, 
            "image_height": 720, 
            "image_layout": "auto", 
            "image_url": "https://cdn.filestackcontent.com/A7vPk5MRSi012J5glu7A", 
            "image_width": 480, 
            "intro_background_color": null, 
            "intro_text_color": null, 
            "is_published": true, 
            "media_type": null, 
            "override_end": null, 
            "override_start": null, 
            "pdf_height": null, 
            "pdf_numpages": null, 
            "pdf_thumbnail_url": null, 
            "pdf_url": null, 
            "pdf_width": null, 
            "priority": "low", 
            "schedule_end": "2019-06-28T08:49:21.195179-04:00", 
            "schedule_start": "2019-06-21T08:49:21.195131-04:00", 
            "show_data_source_in_player": true, 
            "show_post_in_player_window": true, 
            "show_publication_time": false, 
            "show_text_in_ticker": false, 
            "show_title_in_player": true, 
            "subtitle": null, 
            "template": "text+image", 
            "text_color": "000000", 
            "text_layout": "auto", 
            "title": "Look at that!", 
            "uploaded_file_s3_bucket": "dive-cms-media", 
            "uploaded_file_s3_key": "s/i/UHxC3uopSXq91L7m8GnC_convert.jpg", 
            "uploaded_file_size_bytes": 74718, 
            "video_filename": null, 
            "video_url": null, 
            "youtube_url": null
        }
    }