Create a Post with an Slideshow =============================== This tutorial explains how to create an article with a slideshow. .. include:: includes/requirements.rst Procedure --------- .. include:: includes/initialize-variables.rst 2. Upload images **************** Please see our :doc:`upload-multiple-images` tutorial for more information on how to upload images. 3. Initialize particles *********************** The following code snippet shows a list of dictionaries containing information for each slide in the slideshow using the schema expected for the :doc:`/api/reference/drafts` and :doc:`/api/reference/posts`. .. code:: python particles = [ { 'headline': 'This is the first particle', 'body': "Some content here!", 'is_image': True, 'image_id': image_api_response[0]['id'], 'media': image_api_response[0]['shortcode'], 'manual_image_crops': image_api_response[0]['manual_image_crops'], 'caption': 'First element caption', }, { 'headline': 'This is the second particle', 'body': 'More content here', 'is_image': True, 'image_id': image_api_response[1]['id'], 'media': image_api_response[1]['shortcode'], 'manual_image_crops': image_api_response[1]['manual_image_crops'], 'caption': 'Second element caption', }, { 'headline': 'This is the third particle', 'body': 'Content for this particle', 'is_image': True, 'image_id': image_api_response[2]['id'], 'media': image_api_response[2]['shortcode'], 'manual_image_crops': image_api_response[2]['manual_image_crops'], 'caption': 'Third element caption', }, ] 4. Create a draft ***************** Create a new draft using the :doc:`/api/reference/drafts`. .. code:: python response = requests.post( 'https://{}/api/1.3/drafts'.format(API_DOMAIN), params={'api_key': API_KEY}, json={ 'headline': 'Article with an slideshow', } ) response.raise_for_status() draft_api_response = response.json() print(draft_api_response['id']) 5. Publish the draft ******************** Once the particles schema is done, send it to the :doc:`/api/reference/drafts` using the ``listicle`` field. Finally, publish the draft and its URL. .. code:: python body_content = '''

This is a HTML piece than can contain shortcodes.

This text goes after the embedded slideshow.

'''.format(draft_api_response['id']) response = requests.put( 'https://{}/api/1.3/drafts/{}'.format(API_DOMAIN, draft_api_response['id']), params={'api_key': API_KEY}, json={ 'action': 'publish', 'body': body_content, 'listicle': { 'items': particles, 'groups': [{ 'slides': [0, 1, 2], 'settings': { 'layout': 'slideshow', 'columns': 1, 'show_thumbnails': True, }, }], }, } ) response.raise_for_status() draft_api_response = response.json() print(draft_api_response['post_url'])