Media item is missing on the post UI

  • We created a media item (text file) for the particular post by using the create media API. We got the 201 responses. In the create media API response, we can see the mapping with the post. And also we can see the attached media item in the media library. But when we check on the particular post UI, we cannot see the particular media item.

    We used ecommerce license and admin credentials.

    Do we need to give any permission or are there any issue with the way we create the media item?

    This is how we created the media item for the particular post.

    Authorization: Bearer Token

    Headers: Content-Type, multipart/form-data

    The API response which we got:

    {

        “id”: 1438,

        “date”: “2023-01-04T12:09:39”,

        “date_gmt”: “2023-01-04T06:39:39”,

        “guid”: {

            “rendered”: “https://kendra905.wpcomstaging.com/wp-content/uploads/2023/01/PSLWordpress.txt”,

            “raw”: “https://kendra905.wpcomstaging.com/wp-content/uploads/2023/01/PSLWordpress.txt”

        },

        “modified”: “2023-01-04T12:09:39”,

        “modified_gmt”: “2023-01-04T06:39:39”,

        “slug”: “it_qa_tw_1”,

        “status”: “inherit”,

        “type”: “attachment”,

        “link”: “https://kendra905.wpcomstaging.com/2023/01/04/qa_it_tw_123/it_qa_tw_1/”,

        “title”: {

            “raw”: “IT_QA_TW_1”,

            “rendered”: “IT_QA_TW_1”

        },

        “author”: 228051134,

        “comment_status”: “open”,

        “ping_status”: “closed”,

        “template”: “”,

        “meta”: {

            “advanced_seo_description”: “”,

            “jetpack_seo_html_title”: “”,

            “jetpack_seo_noindex”: false,

            “jetpack_post_was_ever_published”: false

        },

        “permalink_template”: “https://kendra905.wpcomstaging.com/2023/01/04/qa_it_tw_123/%postname%/”,

        “generated_slug”: “it_qa_tw_1”,

        “jetpack_sharing_enabled”: true,

        “jetpack_likes_enabled”: true,

        “jetpack_shortlink”: “https://wp.me/aemAkY-nc”,

        “description”: {

            “raw”: “”,

            “rendered”: “IT_QA_TW_1\n”

        },

        “caption”: {

            “raw”: “”,

            “rendered”: “

    IT_QA_TW_1\n”

        },

        “alt_text”: “”,

        “media_type”: “file”,

        “mime_type”: “text/plain”,

        “media_details”: {

            “filesize”: 12,

            “sizes”: []

        },

        “post”: 1436,

        “source_url”: “https://kendra905.wpcomstaging.com/wp-content/uploads/2023/01/PSLWordpress.txt”,

        “missing_image_sizes”: [],

        “_links”: {

            “self”: [

                {

                    “href”: “https://public-api.wordpress.com/wp/v2/sites/kendra905.wpcomstaging.com/media/1438”

                }

            ],

            “collection”: [

                {

                    “href”: “https://public-api.wordpress.com/wp/v2/sites/kendra905.wpcomstaging.com/media”

                }

            ],

            “about”: [

                {

                    “href”: “https://public-api.wordpress.com/wp/v2/sites/kendra905.wpcomstaging.com/types/attachment”

                }

            ],

            “author”: [

                {

                    “embeddable”: true,

                    “href”: “https://public-api.wordpress.com/wp/v2/sites/kendra905.wpcomstaging.com/users/228051134”

                }

            ],

            “replies”: [

                {

                    “embeddable”: true,

                    “href”: “https://public-api.wordpress.com/wp/v2/sites/kendra905.wpcomstaging.com/comments?post=1438”

                }

            ],

            “wp:action-unfiltered-html”: [

                {

                    “href”: “https://public-api.wordpress.com/wp/v2/sites/kendra905.wpcomstaging.com/media/1438?post=1438”

                }

            ],

            “wp:action-assign-author”: [

                {

                    “href”: “https://public-api.wordpress.com/wp/v2/sites/kendra905.wpcomstaging.com/media/1438?post=1438”

                }

            ],

            “curies”: [

                {

                    “name”: “wp”,

                    “href”: “https://api.w.org/{rel}”,

                    “templated”: true

                }

            ]

        },

        “author_wpcom”: 228051134

    }

    The blog I need help with is: (visible only to logged in users)

  • Hi, could this be related to the which regularly appears? I see this exists, when I remove from the URL:
    https://kendra905.wpcomstaging.com/wp-content/uploads/2023/01/PSLWordpress.txt

  • hi,

    I can see the attachment when I open this url.(https://kendra905.wpcomstaging.com/wp-content/uploads/2023/01/PSLWordpress.txt)

    But my query is I cannot see the attachment when I open the post which I attached the file. Because I attached this file for particular post.(post id = 1436)

    In the create media API response, we can see the attachment is mapping with the post.
    “post”: 1436,

    But in the post UI, I am not able to see any attachment.


    Do we need to give any permission or are there any issue with the way we create the media item?

  • I think the issue is that the incorrect address is being added as the attachment. While https://kendra905.wpcomstaging.com/wp-content/uploads/2023/01/PSLWordpress.txt works as we expect, your original message showed that the address is referenced like this instead (I removed the semicolon at the end to force the code at the end to remain visible):

    https://kendra905.wpcomstaging.com/wp-content/uploads/2023/01/PSLWordpress.txt&#8221

    It seems possible that it’s not working, because of the extra characters on the end – I think the second quotation mark ” is being included as part of the URL, and not as follows:

        "source_url": "https://kendra905.wpcomstaging.com/wp-content/uploads/2023/01/PSLWordpress.txt"

    I’m not sure why your quotation marks are appearing as UTF-8 code (info: https://www.w3schools.com/charsets/ref_utf_punctuation.asp ) but I may suggest ensuring that you replace all the quotation marks while working in plain text (no formatting).

  • Hi,
    I didn’t make any changes there. Just copied and pasted the response from the postman. May be some issue in the plain text.
    Here I have pasted under the code option.(no any formatting)
    Hope you can see the correct response now.

    Are there any issue with the way we create the media item for the post?
    If yes, can you share the correct way to create the media item for some particular post through the create media API?

    {
      "id":1438,
      "date":"2023-01-04T12:09:39",
      "date_gmt":"2023-01-04T06:39:39",
      "guid":{
        "rendered":"https:\/\/kendra905.wpcomstaging.com\/wp-content\/uploads\/2023\/01\/PSLWordpress.txt",
        "raw":"https:\/\/kendra905.wpcomstaging.com\/wp-content\/uploads\/2023\/01\/PSLWordpress.txt"
      },
      "modified":"2023-01-04T12:09:39",
      "modified_gmt":"2023-01-04T06:39:39",
      "slug":"it_qa_tw_1",
      "status":"inherit",
      "type":"attachment",
      "link":"https:\/\/kendra905.wpcomstaging.com\/2023\/01\/04\/qa_it_tw_123\/it_qa_tw_1\/",
      "title":{
        "raw":"IT_QA_TW_1",
        "rendered":"IT_QA_TW_1"
      },
      "author":228051134,
      "comment_status":"open",
      "ping_status":"closed",
      "template":"",
      "meta":{
        "advanced_seo_description":"",
        "jetpack_seo_html_title":"",
        "jetpack_seo_noindex":false,
        "jetpack_post_was_ever_published":false
      },
      "permalink_template":"https:\/\/kendra905.wpcomstaging.com\/2023\/01\/04\/qa_it_tw_123\/%postname%\/",
      "generated_slug":"it_qa_tw_1",
      "jetpack_sharing_enabled":true,
      "jetpack_likes_enabled":true,
      "jetpack_shortlink":"https:\/\/wp.me\/aemAkY-nc",
      "description":{
        "raw":"",
        "rendered":"<p class=\"attachment\"><a href='https:\/\/kendra905.wpcomstaging.com\/wp-content\/uploads\/2023\/01\/PSLWordpress.txt'>IT_QA_TW_1<\/a><\/p>\n"
      },
      "caption":{
        "raw":"",
        "rendered":"<p>IT_QA_TW_1<\/p>\n"
      },
      "alt_text":"",
      "media_type":"file",
      "mime_type":"text\/plain",
      "media_details":{
        "filesize":12,
        "sizes":[
        ]
      },
      "post":1436,
      "source_url":"https:\/\/kendra905.wpcomstaging.com\/wp-content\/uploads\/2023\/01\/PSLWordpress.txt",
      "missing_image_sizes":[
      ],
      "_links":{
        "self":[
          {
            "href":"https:\/\/public-api.wordpress.com\/wp\/v2\/sites\/kendra905.wpcomstaging.com\/media\/1438"
          }],
        "collection":[
          {
            "href":"https:\/\/public-api.wordpress.com\/wp\/v2\/sites\/kendra905.wpcomstaging.com\/media"
          }],
        "about":[
          {
            "href":"https:\/\/public-api.wordpress.com\/wp\/v2\/sites\/kendra905.wpcomstaging.com\/types\/attachment"
          }],
        "author":[
          {
            "embeddable":true,
            "href":"https:\/\/public-api.wordpress.com\/wp\/v2\/sites\/kendra905.wpcomstaging.com\/users\/228051134"
          }],
        "replies":[
          {
            "embeddable":true,
            "href":"https:\/\/public-api.wordpress.com\/wp\/v2\/sites\/kendra905.wpcomstaging.com\/comments?post=1438"
          }],
        "wp:action-unfiltered-html":[
          {
            "href":"https:\/\/public-api.wordpress.com\/wp\/v2\/sites\/kendra905.wpcomstaging.com\/media\/1438?post=1438"
          }],
        "wp:action-assign-author":[
          {
            "href":"https:\/\/public-api.wordpress.com\/wp\/v2\/sites\/kendra905.wpcomstaging.com\/media\/1438?post=1438"
          }],
        "curies":[
          {
            "name":"wp",
            "href":"https:\/\/api.w.org\/{rel}",
            "templated":true
          }]
      },
      "author_wpcom":228051134
    }
  • In all honesty while we can troubleshoot a simple issue like a possible extra space or other typo in a URL, the forums aren’t the best place for API help as the developer information is provided for developers themselves to be able to work with the API in various ways; there’s a little more information about that here:
    https://wordpress.com/support/help-support-options/

    That said, it’s worth comparing your work to the data here, and ensure that you’re using the correct parameter to attach the media item:
    https://developer.wordpress.com/docs/api/1.1/post/sites/%24site/posts/new/

  • The topic ‘Media item is missing on the post UI’ is closed to new replies.