Skip to content

Post API Add Post Example Image

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

Post API - /add_post - 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-24T05:33:50.440799-04:00", 
            "data": {}, 
            "expires_at": "2019-06-24T05:43:49.858294-04:00", 
            "id": 6, 
            "media_type": "image", 
            "presigned_s3_post": {
                "fields": {
                    "key": "images/ca5b6182-081c-41fb-b022-065fcc617730", 
                    "policy": "eyJleHBpcmF0aW9uIjogIjIwMTktMDYtMjRUMDk6NDM6NTBaIiwgImNvbmRpdGlvbnMiOiBbWyJjb250ZW50LWxlbmd0aC1yYW5nZSIsIDAsIDIwOTcxNTIwXSwgeyJidWNrZXQiOiAiZGl2ZS1tZWRpYS11cGxvYWQtdGVzdC0yMjA0MjAxOSJ9LCB7ImtleSI6ICJpbWFnZXMvY2E1YjYxODItMDgxYy00MWZiLWIwMjItMDY1ZmNjNjE3NzMwIn0sIHsieC1hbXotYWxnb3JpdGhtIjogIkFXUzQtSE1BQy1TSEEyNTYifSwgeyJ4LWFtei1jcmVkZW50aWFsIjogIkFLSUFYTDdFQUdEUVFHRUhXUVFJLzIwMTkwNjI0L2V1LWNlbnRyYWwtMS9zMy9hd3M0X3JlcXVlc3QifSwgeyJ4LWFtei1kYXRlIjogIjIwMTkwNjI0VDA5MzM1MFoifV19", 
                    "x-amz-algorithm": "AWS4-HMAC-SHA256", 
                    "x-amz-credential": "AKIAXL7EAGDQQGEHWQQI/20190624/eu-central-1/s3/aws4_request", 
                    "x-amz-date": "20190624T093350Z", 
                    "x-amz-signature": "35bc9c991913186d4fc42d4ca0a1463b9bc259eabe5c3a6229cdd7280f4680fa"
                }, 
                "url": "https://dive-media-upload-test-22042019.s3.amazonaws.com/"
            }, 
            "status": "init", 
            "updated_at": "2019-06-24T05:33:50.440834-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/ca5b6182-081c-41fb-b022-065fcc617730" \
    policy="eyJleHBpcmF0aW9uIjogIjIwMTktMDYtMjRUMDk6NDM6NTBaIiwgImNvbmRpdGlvbnMiOiBbWyJjb250ZW50LWxlbmd0aC1yYW5nZSIsIDAsIDIwOTcxNTIwXSwgeyJidWNrZXQiOiAiZGl2ZS1tZWRpYS11cGxvYWQtdGVzdC0yMjA0MjAxOSJ9LCB7ImtleSI6ICJpbWFnZXMvY2E1YjYxODItMDgxYy00MWZiLWIwMjItMDY1ZmNjNjE3NzMwIn0sIHsieC1hbXotYWxnb3JpdGhtIjogIkFXUzQtSE1BQy1TSEEyNTYifSwgeyJ4LWFtei1jcmVkZW50aWFsIjogIkFLSUFYTDdFQUdEUVFHRUhXUVFJLzIwMTkwNjI0L2V1LWNlbnRyYWwtMS9zMy9hd3M0X3JlcXVlc3QifSwgeyJ4LWFtei1kYXRlIjogIjIwMTkwNjI0VDA5MzM1MFoifV19" \
    x-amz-algorithm="AWS4-HMAC-SHA256" \
    x-amz-credential="AKIAXL7EAGDQQGEHWQQI/20190624/eu-central-1/s3/aws4_request" \
    x-amz-date="20190624T093350Z" \
    x-amz-signature="35bc9c991913186d4fc42d4ca0a1463b9bc259eabe5c3a6229cdd7280f4680fa" \
    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=6 \
    Authorization:"Token your-api-token-here"
    

    Response:

    HTTP/1.1 200 OK
    (...headers...)
    
    {
        "result": {
            "created_at": "2019-06-24T05:33:50.440799-04:00", 
            "data": {
                "image_height": 720, 
                "image_url": "https://cdn.filestackcontent.com/escEC1dbRTSuDb2auadt", 
                "image_width": 480, 
                "uploaded_file_s3_bucket": "dive-cms-media", 
                "uploaded_file_s3_key": "s/i/cYbs0jTDSqywwZFzS9KR_convert.jpg", 
                "uploaded_file_size_bytes": 74718
            }, 
            "expires_at": "2019-06-24T05:43:49.858294-04:00", 
            "id": 6, 
            "media_type": "image", 
            "presigned_s3_post": {
                "fields": {
                    "key": "images/ca5b6182-081c-41fb-b022-065fcc617730", 
                    "policy": "eyJleHBpcmF0aW9uIjogIjIwMTktMDYtMjRUMDk6NDU6NDBaIiwgImNvbmRpdGlvbnMiOiBbWyJjb250ZW50LWxlbmd0aC1yYW5nZSIsIDAsIDIwOTcxNTIwXSwgeyJidWNrZXQiOiAiZGl2ZS1tZWRpYS11cGxvYWQtdGVzdC0yMjA0MjAxOSJ9LCB7ImtleSI6ICJpbWFnZXMvY2E1YjYxODItMDgxYy00MWZiLWIwMjItMDY1ZmNjNjE3NzMwIn0sIHsieC1hbXotYWxnb3JpdGhtIjogIkFXUzQtSE1BQy1TSEEyNTYifSwgeyJ4LWFtei1jcmVkZW50aWFsIjogIkFLSUFYTDdFQUdEUVFHRUhXUVFJLzIwMTkwNjI0L2V1LWNlbnRyYWwtMS9zMy9hd3M0X3JlcXVlc3QifSwgeyJ4LWFtei1kYXRlIjogIjIwMTkwNjI0VDA5MzU0MFoifV19", 
                    "x-amz-algorithm": "AWS4-HMAC-SHA256", 
                    "x-amz-credential": "AKIAXL7EAGDQQGEHWQQI/20190624/eu-central-1/s3/aws4_request", 
                    "x-amz-date": "20190624T093540Z", 
                    "x-amz-signature": "750cf13d286df2779b6ae6ffbe0bcc3e6f505cf4524ad3f9880570561614b78f"
                }, 
                "url": "https://dive-media-upload-test-22042019.s3.amazonaws.com/"
            }, 
            "status": "succeeded", 
            "updated_at": "2019-06-24T05:35:40.089865-04:00"
        }
    }
    
  4. Add Post:

    body.json:

    {
      "template": "image",
      "title": "Look at that!",
      "content_zones": [
        15
      ],
      "image_height": 720,
      "image_url": "https://cdn.filestackcontent.com/escEC1dbRTSuDb2auadt",
      "image_width": 480,
      "uploaded_file_s3_bucket": "dive-cms-media",
      "uploaded_file_s3_key": "s/i/cYbs0jTDSqywwZFzS9KR_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": null, 
            "content_zones": [
                15
            ], 
            "duration": null, 
            "frequency": 300, 
            "fullscreen_playback": false, 
            "id": 13355, 
            "iframe_url": null, 
            "image_height": 720, 
            "image_layout": "auto", 
            "image_url": "https://cdn.filestackcontent.com/escEC1dbRTSuDb2auadt", 
            "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-07-01T05:38:57.863637-04:00", 
            "schedule_start": "2019-06-24T05:38:57.863583-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": "image", 
            "text_color": null, 
            "text_layout": "auto", 
            "title": "Look at that!", 
            "uploaded_file_s3_bucket": "dive-cms-media", 
            "uploaded_file_s3_key": "s/i/cYbs0jTDSqywwZFzS9KR_convert.jpg", 
            "uploaded_file_size_bytes": 74718, 
            "video_filename": null, 
            "video_url": null, 
            "youtube_url": null
        }
    }