I am working with the CMS API and I am trying to add photos to a collection by using the API documentation and testing with Postman.
Some content on what I am trying to do:
I have a URL link that when clicked bring you to an image and I also have a title for the image. What I would like to be able to do if POST that image URL link and the image title to an Item inside a collection and they be able to have my site display the image on a page.
When reviewing the API docs under Items-> Create Collection Item I see that a field called type needs to be passed. Reviewing the Field Model I can see that it requires a FieldType and from that I can one called ExtFileRef which states “An object containing name (string) and URL (string) properties” which seems the best best to go with.
If I am to use the FieldType ExtFileRef, what custom field must be set inside the collection settings for that to work?
What would be the best approach at achieving the above using the CMS API?
I have attached a screenshot of me trying to use the ExtFileRef type but its failing due to validation, again I could be misinterpreting the documentation:
Hi @butlawr, it looks like your fields object should look more like this example from the docs. You’d just need to edit the fields to match the fields in your collection and pass the image URL as the value for the image field.
fields: {
name: 'Exciting blog post title',
slug: 'exciting-post',
_archived: false,
_draft: false,
color: '#a98080',
author: '580e640c8c9a982ac9b8b778',
'post-body': '<p>Blog post contents...</p>',
'post-summary': 'Summary of exciting blog post',
'main-image': '580e63fe8c9a982ac9b8b749'
}
I believe the issue I am faced with is due to the Content-Type the server is responding with in the headers when I request the image via the URL. It is responding with “binary/octet-stream” when I believe it should be “image/jpeg”