Skip to content

Post API Add Post Example Company News

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

Post API - /add_post - Company News template example with image

  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-26T07:29:38.959393-04:00", 
            "data": {}, 
            "expires_at": "2019-06-26T07:39:38.492525-04:00", 
            "id": 37, 
            "media_type": "image", 
            "presigned_s3_post": {
                "fields": {
                    "key": "images/c51dad87-2472-49b5-9b74-35dc748a51c6", 
                    "policy": "eyJleHBpcmF0aW9uIjogIjIwMTktMDYtMjZUMTE6Mzk6MzhaIiwgImNvbmRpdGlvbnMiOiBbWyJjb250ZW50LWxlbmd0aC1yYW5nZSIsIDAsIDIwOTcxNTIwXSwgeyJidWNrZXQiOiAiZGl2ZS1tZWRpYS11cGxvYWQtdGVzdC0yMjA0MjAxOSJ9LCB7ImtleSI6ICJpbWFnZXMvYzUxZGFkODctMjQ3Mi00OWI1LTliNzQtMzVkYzc0OGE1MWM2In0sIHsieC1hbXotYWxnb3JpdGhtIjogIkFXUzQtSE1BQy1TSEEyNTYifSwgeyJ4LWFtei1jcmVkZW50aWFsIjogIkFLSUFYTDdFQUdEUVFHRUhXUVFJLzIwMTkwNjI2L2V1LWNlbnRyYWwtMS9zMy9hd3M0X3JlcXVlc3QifSwgeyJ4LWFtei1kYXRlIjogIjIwMTkwNjI2VDExMjkzOFoifV19", 
                    "x-amz-algorithm": "AWS4-HMAC-SHA256", 
                    "x-amz-credential": "AKIAXL7EAGDQQGEHWQQI/20190626/eu-central-1/s3/aws4_request", 
                    "x-amz-date": "20190626T112938Z", 
                    "x-amz-signature": "8fc68e25b62fc0bba4f996ce69d4a53480209e8f8b83ab86dd4fe90cb1ed0799"
                }, 
                "url": "https://dive-media-upload-test-22042019.s3.amazonaws.com/"
            }, 
            "status": "init", 
            "updated_at": "2019-06-26T07:29:38.959445-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/c51dad87-2472-49b5-9b74-35dc748a51c6" \
    policy="eyJleHBpcmF0aW9uIjogIjIwMTktMDYtMjZUMTE6Mzk6MzhaIiwgImNvbmRpdGlvbnMiOiBbWyJjb250ZW50LWxlbmd0aC1yYW5nZSIsIDAsIDIwOTcxNTIwXSwgeyJidWNrZXQiOiAiZGl2ZS1tZWRpYS11cGxvYWQtdGVzdC0yMjA0MjAxOSJ9LCB7ImtleSI6ICJpbWFnZXMvYzUxZGFkODctMjQ3Mi00OWI1LTliNzQtMzVkYzc0OGE1MWM2In0sIHsieC1hbXotYWxnb3JpdGhtIjogIkFXUzQtSE1BQy1TSEEyNTYifSwgeyJ4LWFtei1jcmVkZW50aWFsIjogIkFLSUFYTDdFQUdEUVFHRUhXUVFJLzIwMTkwNjI2L2V1LWNlbnRyYWwtMS9zMy9hd3M0X3JlcXVlc3QifSwgeyJ4LWFtei1kYXRlIjogIjIwMTkwNjI2VDExMjkzOFoifV19" \
    x-amz-algorithm="AWS4-HMAC-SHA256" \
    x-amz-credential="AKIAXL7EAGDQQGEHWQQI/20190626/eu-central-1/s3/aws4_request" \
    x-amz-date="20190626T112938Z" \
    x-amz-signature="8fc68e25b62fc0bba4f996ce69d4a53480209e8f8b83ab86dd4fe90cb1ed0799" \
    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=37 \
    Authorization:"Token your-api-token-here"
    

    Response:

    HTTP/1.1 200 OK
    (...headers...)
    
    {
        "result": {
            "created_at": "2019-06-26T07:29:38.959393-04:00", 
            "data": {
                "image_height": 720, 
                "image_url": "https://cdn.filestackcontent.com/mN24rLTRmGNQwwHqwaJ8", 
                "image_width": 480, 
                "uploaded_file_s3_bucket": "dive-cms-media", 
                "uploaded_file_s3_key": "s/i/Vn4W2ZzQi5dQ6iNraLg8_convert.jpg", 
                "uploaded_file_size_bytes": 74718
            }, 
            "expires_at": "2019-06-26T07:39:38.492525-04:00", 
            "id": 37, 
            "media_type": "image", 
            "presigned_s3_post": {
                "fields": {
                    "key": "images/c51dad87-2472-49b5-9b74-35dc748a51c6", 
                    "policy": "eyJleHBpcmF0aW9uIjogIjIwMTktMDYtMjZUMTE6NDA6NDlaIiwgImNvbmRpdGlvbnMiOiBbWyJjb250ZW50LWxlbmd0aC1yYW5nZSIsIDAsIDIwOTcxNTIwXSwgeyJidWNrZXQiOiAiZGl2ZS1tZWRpYS11cGxvYWQtdGVzdC0yMjA0MjAxOSJ9LCB7ImtleSI6ICJpbWFnZXMvYzUxZGFkODctMjQ3Mi00OWI1LTliNzQtMzVkYzc0OGE1MWM2In0sIHsieC1hbXotYWxnb3JpdGhtIjogIkFXUzQtSE1BQy1TSEEyNTYifSwgeyJ4LWFtei1jcmVkZW50aWFsIjogIkFLSUFYTDdFQUdEUVFHRUhXUVFJLzIwMTkwNjI2L2V1LWNlbnRyYWwtMS9zMy9hd3M0X3JlcXVlc3QifSwgeyJ4LWFtei1kYXRlIjogIjIwMTkwNjI2VDExMzA0OVoifV19", 
                    "x-amz-algorithm": "AWS4-HMAC-SHA256", 
                    "x-amz-credential": "AKIAXL7EAGDQQGEHWQQI/20190626/eu-central-1/s3/aws4_request", 
                    "x-amz-date": "20190626T113049Z", 
                    "x-amz-signature": "fb254a2d31fe6d7a905a88b2c76adaa722ffd634e275eb152adb5d9f9da5db22"
                }, 
                "url": "https://dive-media-upload-test-22042019.s3.amazonaws.com/"
            }, 
            "status": "succeeded", 
            "updated_at": "2019-06-26T07:30:49.522300-04:00"
        }
    }
    
  4. Add Post:

    body.json:

    {
      "template": "company-news",
      "title": "News from your company",
      "body": "Message for your employees...",
      "content_zones": [
        15
      ],
      "image_height": 720,
      "image_url": "https://cdn.filestackcontent.com/mN24rLTRmGNQwwHqwaJ8",
      "image_width": 480,
      "uploaded_file_s3_bucket": "dive-cms-media",
      "uploaded_file_s3_key": "s/i/Vn4W2ZzQi5dQ6iNraLg8_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": "Message for your employees...", 
            "content_zones": [
                15
            ], 
            "duration": null, 
            "frequency": 300, 
            "fullscreen_playback": false, 
            "id": 13370, 
            "iframe_url": null, 
            "image_height": 720, 
            "image_layout": "auto", 
            "image_url": "https://cdn.filestackcontent.com/mN24rLTRmGNQwwHqwaJ8", 
            "image_width": 480, 
            "intro_background_color": "6d4fc3", 
            "intro_text_color": "ffffff", 
            "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-03T07:33:04.054717-04:00", 
            "schedule_start": "2019-06-26T07:33:04.054689-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": "company-news", 
            "text_color": "000000", 
            "text_layout": "auto", 
            "title": "News from your company", 
            "uploaded_file_s3_bucket": "dive-cms-media", 
            "uploaded_file_s3_key": "s/i/Vn4W2ZzQi5dQ6iNraLg8_convert.jpg", 
            "uploaded_file_size_bytes": 74718, 
            "video_filename": null, 
            "video_url": null, 
            "youtube_url": null
        }
    }
    

Clone this wiki locally