Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

How to build a request for AcceptableMediaTypes ?

0 Kudos

Hi, I am working on insert/deep insert. I came across an EntityType which has an annotation of AcceptableMediaTypes. I went through the documentation but unable to find any demo request/JSON/XML for AcceptableMediaTypes.

I am using this https://services.odata.org/V4/TripPinService/$metadata, there is an Entity type named Photo.

I am looking for a POST request payload to insert\deep insert data along with media using postman. Can someone please help me out?

8 REPLIES 8

evanireland
Advisor
Advisor

See here:

http://docs.oasis-open.org/odata/odata/v4.0/errata03/os/complete/part1-protocol/odata-v4.0-errata03-...

First, POST the media content to the Photos entity set, then get the Location header from the response.

Then, use PATCH (or PUT) on the Location URL to set the non-media properties (if any) - for example the Name property in the case of Photo.

0 Kudos

Hi Evan, could you please guide me on how to create a request in postman, for eg if I want to insert an image for Entity type Photo in https://services.odata.org/V4/TripPinService/$metadata. So what should be the request? like request body, URL, where should I pass the image content, Content type. you can also direct me to an example if there is one for inserting an image. Your response will be appreciated.

evanireland
Advisor
Advisor
0 Kudos

With Postman, try POST to https://services.odata.org/V4/TripPinService/Photos

For the "Body", choose "raw" and select a JPEG file, e.g. you might get a sample JPEG file from from https://www.fileformat.info/format/jpeg/sample/index.htm

Then click "Send".

Response will look something like this:

{ "@odata.context": "http://services.odata.org/V4/TripPinService/$metadata#Photos/$entity", "@odata.id": "http://services.odata.org/V4/TripPinService/Photos(1247)", "@odata.editLink": "http://services.odata.org/V4/TripPinService/Photos(1247)", "@odata.mediaContentType": "image/jpeg", "@odata.mediaEtag": "W/\"08D91FBB44CC4A17\"", "Id": 1247, "Name": null }

0 Kudos

Hi Evan, I followed what you mentioned above but instead of choosing the raw I chose binary and it worked fine as can be seen in the below screenshot.

then I used PATCH request to update the Name but I was unable to as can be seen in the below screenshot, can you please guide me if I am doing something wrong while updating?

Also, what will happen in the case of Deep insert, will it work the same, is there a working postman request or example in which i can look into?

your response will be appreciated.

evanireland
Advisor
Advisor
0 Kudos

Sounds like a service (back-end) problem. Microsoft owns that particular service.

Perhaps you could try Mobile Back-End Tools (https://help.sap.com/doc/f53c64b93e5140918d676b927a3cd65b/Cloud/en-US/docs-en/guides/getting-started/mbt/introduction.html) to build a service that works for updates.

Try using it with Visual Studio Code and this metadata.csdl.xml

<?xml version="1.0" encoding="utf-8"?> <edmx:Edmx Version="4.0" xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx"> <edmx:DataServices> <Schema Namespace="media.example.com" Alias="Self" xmlns="http://docs.oasis-open.org/odata/ns/edm"> <EntityType Name="Artist"> <Key> <PropertyRef Name="id"/> </Key> <Property Name="id" Type="Edm.Int32" Nullable="false"/> <Property Name="firstName" Type="Edm.String" Nullable="false"/> <Property Name="lastName" Type="Edm.String" Nullable="false"/> <Property Name="dateOfBirth" Type="Edm.Date" Nullable="false"/> <Property Name="placeOfBirth" Type="Edm.GeographyPoint" Nullable="false"/> <NavigationProperty Name="images" Type="Collection(Self.Image)" /> <NavigationProperty Name="videos" Type="Collection(Self.Video)" /> </EntityType> <EntityType Name="Image" HasStream="true"> <Key> <PropertyRef Name="id"/> </Key> <Property Name="id" Type="Edm.Guid" Nullable="false"/> <Property Name="label" Type="Edm.String" Nullable="true"/> <Property Name="created" Type="Edm.DateTimeOffset" Nullable="false"/> <Property Name="updated" Type="Edm.DateTimeOffset" Nullable="false"/> <Property Name="imageContent" Type="Edm.Stream" Nullable="false"/> <Property Name="imageOptionalContent" Type="Edm.Stream" Nullable="true"/> <NavigationProperty Name="artist" Type="Self.Artist" /> </EntityType> <EntityType Name="Video"> <Key> <PropertyRef Name="id"/> </Key> <Property Name="id" Type="Edm.Guid" Nullable="false"/> <Property Name="label" Type="Edm.String" Nullable="true"/> <Property Name="created" Type="Edm.DateTimeOffset" Nullable="false"/> <Property Name="updated" Type="Edm.DateTimeOffset" Nullable="false"/> <Property Name="content" Type="Edm.Stream" Nullable="false"/> <Property Name="optionalContent" Type="Edm.Stream" Nullable="true"/> <NavigationProperty Name="artist" Type="Self.Artist" /> </EntityType> <EntityContainer Name="MediaService"> <EntitySet Name="Artists" EntityType="Self.Artist"> <NavigationPropertyBinding Path="images" Target="Images"/> <NavigationPropertyBinding Path="videos" Target="Videos"/> </EntitySet> <EntitySet Name="Images" EntityType="Self.Image"> <NavigationPropertyBinding Path="artist" Target="Artists"/> </EntitySet> <EntitySet Name="Videos" EntityType="Self.Video"> <NavigationPropertyBinding Path="artist" Target="Artists"/> </EntitySet> </EntityContainer> </Schema> </edmx:DataServices> </edmx:Edmx>

evanireland
Advisor
Advisor
0 Kudos

Attaching the media metadata again. mediaschema.xml

0 Kudos

Hi Evan, thanks for the response, there is one more thing that I want to perform. I want to know how to send the payload in deep insert with Media Type Entity.

For ex: I am using this https://services.odata.org/V4/TripPinService/$metadata and in this i want to insert Person Entity type along with Photo Entity Type. In this case what should be the Deep Insert payload through which I can test it on postman? Could you please help me out?

evanireland
Advisor
Advisor
0 Kudos

It isn't possible to deep insert a media entity (e.g. Photo) along with the creation of a regular entity parent (e.g. Person). The two requests would need to be separate.

The request body for a media entity creation (e.g. Photo) needs to be just the media content (e.g. binary JPEG content). There's no way for it to be also containing the JSON content for the parent's properties.