{"id":3484,"date":"2024-08-09T10:11:55","date_gmt":"2024-08-09T02:11:55","guid":{"rendered":"https:\/\/five.co\/?p=3484"},"modified":"2024-08-13T11:54:34","modified_gmt":"2024-08-13T03:54:34","slug":"6-simple-odata-post-examples","status":"publish","type":"post","link":"https:\/\/preview-php85.dzine.org\/five\/blog\/6-simple-odata-post-examples\/","title":{"rendered":"6 Simple OData POST Examples"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Learn How to Use OData&#8217;s POST Method with Simple Examples<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s explore how OData <code>POST<\/code> requests can be used to modify and create new resources in a collection. We&#8217;ll use a simple <code>Products<\/code> collection as the basis for these examples.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To learn more about the OData <code>$filter<\/code> query, <a href=\"https:\/\/preview-php85.dzine.org\/five\/blog\/odata-filter-queries-explained\/\">read our blog post here<\/a>.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n<div class=\"root-eb-toc-j5ec6 wp-block-essential-blocks-table-of-contents\"><div class=\"eb-parent-wrapper eb-parent-eb-toc-j5ec6 \"><div class=\"eb-toc-container eb-toc-j5ec6  eb-toc-is-not-sticky eb-toc-not-collapsible eb-toc-initially-not-collapsed eb-toc-scrollToTop style-1 list-style-none\" data-scroll-top=\"false\" data-scroll-top-icon=\"fas fa-angle-up\" data-collapsible=\"false\" data-sticky-hide-mobile=\"false\" data-sticky=\"false\" data-scroll-target=\"scroll_to_toc\" data-copy-link=\"false\" data-editor-type=\"\" data-hide-desktop=\"false\" data-hide-tab=\"false\" data-hide-mobile=\"false\" data-itemcollapsed=\"false\" data-highlight-scroll=\"false\"><div class=\"eb-toc-header\"><h2 class=\"eb-toc-title\">Table of Contents<\/h2><\/div><div class=\"eb-toc-wrapper \" data-headers=\"[{&quot;level&quot;:2,&quot;content&quot;:&quot;Learn How to Use OData&apos;s POST Method with Simple Examples&quot;,&quot;text&quot;:&quot;Learn How to Use OData&apos;s POST Method with Simple Examples&quot;,&quot;link&quot;:&quot;learn-how-to-use-odatas-post-method-with-simple-examples&quot;},{&quot;level&quot;:2,&quot;content&quot;:&quot;OData Post Examples - A Simple Scenario&quot;,&quot;text&quot;:&quot;OData Post Examples - A Simple Scenario&quot;,&quot;link&quot;:&quot;odata-post-examples-a-simple-scenario&quot;},{&quot;level&quot;:3,&quot;content&quot;:&quot;1. Basic OData POST Example: Creating a New Product&quot;,&quot;text&quot;:&quot;1. Basic OData POST Example: Creating a New Product&quot;,&quot;link&quot;:&quot;1-basic-odata-post-example-creating-a-new-product&quot;},{&quot;level&quot;:3,&quot;content&quot;:&quot;2. POST with Server-Side Defaults: Handling Missing Fields&quot;,&quot;text&quot;:&quot;2. POST with Server-Side Defaults: Handling Missing Fields&quot;,&quot;link&quot;:&quot;2-post-with-server-side-defaults-handling-missing-fields&quot;},{&quot;level&quot;:3,&quot;content&quot;:&quot;3. POST with Relationships: Creating a Product and Assigning a Category&quot;,&quot;text&quot;:&quot;3. POST with Relationships: Creating a Product and Assigning a Category&quot;,&quot;link&quot;:&quot;3-post-with-relationships-creating-a-product-and-assigning-a-category&quot;},{&quot;level&quot;:3,&quot;content&quot;:&quot;4. POST with Complex Types: Including Additional Information in a Complex Property&quot;,&quot;text&quot;:&quot;4. POST with Complex Types: Including Additional Information in a Complex Property&quot;,&quot;link&quot;:&quot;4-post-with-complex-types-including-additional-information-in-a-complex-property&quot;},{&quot;level&quot;:3,&quot;content&quot;:&quot;5. POST with Deep Insertion: Creating a Product with a New Category&quot;,&quot;text&quot;:&quot;5. POST with Deep Insertion: Creating a Product with a New Category&quot;,&quot;link&quot;:&quot;5-post-with-deep-insertion-creating-a-product-with-a-new-category&quot;},{&quot;level&quot;:3,&quot;content&quot;:&quot;6. POST with Batch Requests: Creating Multiple Products in a Single Request&quot;,&quot;text&quot;:&quot;6. POST with Batch Requests: Creating Multiple Products in a Single Request&quot;,&quot;link&quot;:&quot;6-post-with-batch-requests-creating-multiple-products-in-a-single-request&quot;},{&quot;level&quot;:3,&quot;content&quot;:&quot;Summary: OData Post Examples&quot;,&quot;text&quot;:&quot;Summary: OData Post Examples&quot;,&quot;link&quot;:&quot;summary-odata-post-examples&quot;}]\" data-visible=\"[true,true,true,true,true,true]\" data-delete-headers=\"[{&quot;label&quot;:&quot;Learn How to Use OData&apos;s POST Method with Simple Examples&quot;,&quot;value&quot;:&quot;learn-how-to-use-odatas-post-method-with-simple-examples&quot;,&quot;isDelete&quot;:false},{&quot;label&quot;:&quot;OData Post Examples - A Simple Scenario&quot;,&quot;value&quot;:&quot;odata-post-examples-a-simple-scenario&quot;,&quot;isDelete&quot;:false},{&quot;label&quot;:&quot;1. Basic OData POST Example: Creating a New Product&quot;,&quot;value&quot;:&quot;1-basic-odata-post-example-creating-a-new-product&quot;,&quot;isDelete&quot;:false},{&quot;label&quot;:&quot;2. POST with Server-Side Defaults: Handling Missing Fields&quot;,&quot;value&quot;:&quot;2-post-with-server-side-defaults-handling-missing-fields&quot;,&quot;isDelete&quot;:false},{&quot;label&quot;:&quot;3. POST with Relationships: Creating a Product and Assigning a Category&quot;,&quot;value&quot;:&quot;3-post-with-relationships-creating-a-product-and-assigning-a-category&quot;,&quot;isDelete&quot;:false},{&quot;label&quot;:&quot;4. POST with Complex Types: Including Additional Information in a Complex Property&quot;,&quot;value&quot;:&quot;4-post-with-complex-types-including-additional-information-in-a-complex-property&quot;,&quot;isDelete&quot;:false},{&quot;label&quot;:&quot;5. POST with Deep Insertion: Creating a Product with a New Category&quot;,&quot;value&quot;:&quot;5-post-with-deep-insertion-creating-a-product-with-a-new-category&quot;,&quot;isDelete&quot;:false},{&quot;label&quot;:&quot;6. POST with Batch Requests: Creating Multiple Products in a Single Request&quot;,&quot;value&quot;:&quot;6-post-with-batch-requests-creating-multiple-products-in-a-single-request&quot;,&quot;isDelete&quot;:false},{&quot;label&quot;:&quot;Summary: OData Post Examples&quot;,&quot;value&quot;:&quot;summary-odata-post-examples&quot;,&quot;isDelete&quot;:false}]\" data-smooth=\"true\" data-top-offset=\"\"><div class=\"eb-toc__list-wrap\"><ul class=\"eb-toc__list\"><li><a href=\"#learn-how-to-use-odatas-post-method-with-simple-examples\">Learn How to Use OData&#8217;s POST Method with Simple Examples<\/a><li><a href=\"#odata-post-examples-a-simple-scenario\">OData Post Examples &#8211; A Simple Scenario<\/a><ul class=\"eb-toc__list\"><li><a href=\"#1-basic-odata-post-example-creating-a-new-product\">1. Basic OData POST Example: Creating a New Product<\/a><li><a href=\"#2-post-with-server-side-defaults-handling-missing-fields\">2. POST with Server-Side Defaults: Handling Missing Fields<\/a><li><a href=\"#3-post-with-relationships-creating-a-product-and-assigning-a-category\">3. POST with Relationships: Creating a Product and Assigning a Category<\/a><li><a href=\"#4-post-with-complex-types-including-additional-information-in-a-complex-property\">4. POST with Complex Types: Including Additional Information in a Complex Property<\/a><li><a href=\"#5-post-with-deep-insertion-creating-a-product-with-a-new-category\">5. POST with Deep Insertion: Creating a Product with a New Category<\/a><li><a href=\"#6-post-with-batch-requests-creating-multiple-products-in-a-single-request\">6. POST with Batch Requests: Creating Multiple Products in a Single Request<\/a><li><a href=\"#summary-odata-post-examples\">Summary: OData Post Examples<\/a><\/li><\/ul><\/ul><\/div><\/div><\/div><\/div><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained\">\n<p class=\"has-text-align-center wp-block-paragraph\"><strong><span style=\"text-decoration: underline;\">Code-Along: Develop an OData Data View in a Responsive Web App<\/span><\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Follow our <a href=\"https:\/\/preview-php85.dzine.org\/five\/code-along\/how-to-develop-an-odata-data-view\/\" target=\"_blank\" rel=\"noreferrer noopener\">step-by-step code-along tutorial<\/a> and learn how to build a web app that connects to an OData service as a data source. This code-along guide is ideal for anyone building custom apps or software on an OData API.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n<\/div><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">OData <code>Post<\/code> Examples &#8211; A Simple Scenario<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Imagine we have an OData service that exposes a <code>Products<\/code> entity set. Each product has the following properties:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>ID<\/code> (integer)<\/li>\n\n\n\n<li><code>Name<\/code> (string)<\/li>\n\n\n\n<li><code>Category<\/code> (string)<\/li>\n\n\n\n<li><code>Price<\/code> (decimal)<\/li>\n\n\n\n<li><code>StockQuantity<\/code> (integer)<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">1. Basic OData POST Example: Creating a New Product<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s first explore the simplest of all cases where the client wants to add a new product to the <code>Products<\/code> collection.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>IMPORTANT<\/em>: The POST body MUST always contain a single valid entity representation.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here&#8217;s our <code>POST<\/code> request.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#abb2bf;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282c34\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"POST serviceRoot\/Products\nContent-Type: application\/json\n\n{\n  &quot;Name&quot;: &quot;Laptop&quot;,\n  &quot;Category&quot;: &quot;Electronics&quot;,\n  &quot;Price&quot;: 1200.00,\n  &quot;StockQuantity&quot;: 50\n}\" style=\"color:#abb2bf;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki one-dark-pro\" style=\"background-color: #282c34\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #ABB2BF\">POST serviceRoot\/Products<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">Content-Type: application\/json<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">  <\/span><span style=\"color: #E06C75\">&quot;Name&quot;<\/span><span style=\"color: #ABB2BF\">: <\/span><span style=\"color: #98C379\">&quot;Laptop&quot;<\/span><span style=\"color: #ABB2BF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">  <\/span><span style=\"color: #E06C75\">&quot;Category&quot;<\/span><span style=\"color: #ABB2BF\">: <\/span><span style=\"color: #98C379\">&quot;Electronics&quot;<\/span><span style=\"color: #ABB2BF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">  <\/span><span style=\"color: #E06C75\">&quot;Price&quot;<\/span><span style=\"color: #ABB2BF\">: <\/span><span style=\"color: #D19A66\">1200.00<\/span><span style=\"color: #ABB2BF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">  <\/span><span style=\"color: #E06C75\">&quot;StockQuantity&quot;<\/span><span style=\"color: #ABB2BF\">: <\/span><span style=\"color: #D19A66\">50<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">To explain, the client sends a <code>POST<\/code> request to the <code>Products<\/code> collection\u2019s URL. The request body contains the properties of the new product. The server assigns an <code>ID<\/code> to the new product and stores it in the <code>Products<\/code> collection.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here is what our JSON Response would look like:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#abb2bf;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282c34\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"{\n  &quot;ID&quot;: 1,\n  &quot;Name&quot;: &quot;Laptop&quot;,\n  &quot;Category&quot;: &quot;Electronics&quot;,\n  &quot;Price&quot;: 1200.00,\n  &quot;StockQuantity&quot;: 50\n}\" style=\"color:#abb2bf;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki one-dark-pro\" style=\"background-color: #282c34\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #ABB2BF\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">  <\/span><span style=\"color: #E06C75\">&quot;ID&quot;<\/span><span style=\"color: #ABB2BF\">: <\/span><span style=\"color: #D19A66\">1<\/span><span style=\"color: #ABB2BF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">  <\/span><span style=\"color: #E06C75\">&quot;Name&quot;<\/span><span style=\"color: #ABB2BF\">: <\/span><span style=\"color: #98C379\">&quot;Laptop&quot;<\/span><span style=\"color: #ABB2BF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">  <\/span><span style=\"color: #E06C75\">&quot;Category&quot;<\/span><span style=\"color: #ABB2BF\">: <\/span><span style=\"color: #98C379\">&quot;Electronics&quot;<\/span><span style=\"color: #ABB2BF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">  <\/span><span style=\"color: #E06C75\">&quot;Price&quot;<\/span><span style=\"color: #ABB2BF\">: <\/span><span style=\"color: #D19A66\">1200.00<\/span><span style=\"color: #ABB2BF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">  <\/span><span style=\"color: #E06C75\">&quot;StockQuantity&quot;<\/span><span style=\"color: #ABB2BF\">: <\/span><span style=\"color: #D19A66\">50<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">2. POST with Server-Side Defaults: Handling Missing Fields<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s make this a bit more complex. In this <code>POST <\/code>request, the client adds a new product but omits the <code>StockQuantity<\/code>. The server should use a default value for this field.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#abb2bf;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282c34\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"POST serviceRoot\/Products\nContent-Type: application\/json\n\n{\n  &quot;Name&quot;: &quot;Smartphone&quot;,\n  &quot;Category&quot;: &quot;Electronics&quot;,\n  &quot;Price&quot;: 800.00\n}\" style=\"color:#abb2bf;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki one-dark-pro\" style=\"background-color: #282c34\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #ABB2BF\">POST serviceRoot\/Products<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">Content-Type: application\/json<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">  <\/span><span style=\"color: #E06C75\">&quot;Name&quot;<\/span><span style=\"color: #ABB2BF\">: <\/span><span style=\"color: #98C379\">&quot;Smartphone&quot;<\/span><span style=\"color: #ABB2BF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">  <\/span><span style=\"color: #E06C75\">&quot;Category&quot;<\/span><span style=\"color: #ABB2BF\">: <\/span><span style=\"color: #98C379\">&quot;Electronics&quot;<\/span><span style=\"color: #ABB2BF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">  <\/span><span style=\"color: #E06C75\">&quot;Price&quot;<\/span><span style=\"color: #ABB2BF\">: <\/span><span style=\"color: #D19A66\">800.00<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p class=\"wp-block-paragraph\">Note how the <code>StockQuantity<\/code> is missing in the request. The server assigns a default value (e.g., 0) to the <code>StockQuantity<\/code> field and generates a <code>ID<\/code> for the new product.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here&#8217;s our JSON response:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#abb2bf;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282c34\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"{\n  &quot;ID&quot;: 2,\n  &quot;Name&quot;: &quot;Smartphone&quot;,\n  &quot;Category&quot;: &quot;Electronics&quot;,\n  &quot;Price&quot;: 800.00,\n  &quot;StockQuantity&quot;: 0\n}\" style=\"color:#abb2bf;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki one-dark-pro\" style=\"background-color: #282c34\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #ABB2BF\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">  <\/span><span style=\"color: #E06C75\">&quot;ID&quot;<\/span><span style=\"color: #ABB2BF\">: <\/span><span style=\"color: #D19A66\">2<\/span><span style=\"color: #ABB2BF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">  <\/span><span style=\"color: #E06C75\">&quot;Name&quot;<\/span><span style=\"color: #ABB2BF\">: <\/span><span style=\"color: #98C379\">&quot;Smartphone&quot;<\/span><span style=\"color: #ABB2BF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">  <\/span><span style=\"color: #E06C75\">&quot;Category&quot;<\/span><span style=\"color: #ABB2BF\">: <\/span><span style=\"color: #98C379\">&quot;Electronics&quot;<\/span><span style=\"color: #ABB2BF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">  <\/span><span style=\"color: #E06C75\">&quot;Price&quot;<\/span><span style=\"color: #ABB2BF\">: <\/span><span style=\"color: #D19A66\">800.00<\/span><span style=\"color: #ABB2BF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">  <\/span><span style=\"color: #E06C75\">&quot;StockQuantity&quot;<\/span><span style=\"color: #ABB2BF\">: <\/span><span style=\"color: #D19A66\">0<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">3. POST with Relationships: Creating a Product and Assigning a Category<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Next up, the client wants to add a new product and also associate it with an existing category using a relationship. For this example, we assume that the <code>Category<\/code> field is a navigation property that links to an <code>Categories<\/code> entity.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here&#8217;s our <code>POST <\/code>request:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#abb2bf;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282c34\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"POST serviceRoot\/Products\nContent-Type: application\/json\n\n{\n  &quot;Name&quot;: &quot;Tablet&quot;,\n  &quot;Price&quot;: 400.00,\n  &quot;StockQuantity&quot;: 100,\n  &quot;Category@odata.bind&quot;: &quot;serviceRoot\/Categories(1)&quot;\n}\" style=\"color:#abb2bf;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki one-dark-pro\" style=\"background-color: #282c34\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #ABB2BF\">POST serviceRoot\/Products<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">Content-Type: application\/json<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">  <\/span><span style=\"color: #E06C75\">&quot;Name&quot;<\/span><span style=\"color: #ABB2BF\">: <\/span><span style=\"color: #98C379\">&quot;Tablet&quot;<\/span><span style=\"color: #ABB2BF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">  <\/span><span style=\"color: #E06C75\">&quot;Price&quot;<\/span><span style=\"color: #ABB2BF\">: <\/span><span style=\"color: #D19A66\">400.00<\/span><span style=\"color: #ABB2BF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">  <\/span><span style=\"color: #E06C75\">&quot;StockQuantity&quot;<\/span><span style=\"color: #ABB2BF\">: <\/span><span style=\"color: #D19A66\">100<\/span><span style=\"color: #ABB2BF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">  <\/span><span style=\"color: #E06C75\">&quot;Category@odata.bind&quot;<\/span><span style=\"color: #ABB2BF\">: <\/span><span style=\"color: #98C379\">&quot;serviceRoot\/Categories(1)&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p class=\"wp-block-paragraph\">What has changed? The <code>Category@odata.bind<\/code> property is used to associate the new product with an existing category. The value is the URL to the specific category.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here&#8217;s what our JSON response would look like:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#abb2bf;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282c34\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"{\n  &quot;ID&quot;: 3,\n  &quot;Name&quot;: &quot;Tablet&quot;,\n  &quot;Price&quot;: 400.00,\n  &quot;StockQuantity&quot;: 100,\n  &quot;Category&quot;: {\n    &quot;ID&quot;: 1,\n    &quot;Name&quot;: &quot;Electronics&quot;\n  }\n}\" style=\"color:#abb2bf;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki one-dark-pro\" style=\"background-color: #282c34\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #ABB2BF\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">  <\/span><span style=\"color: #E06C75\">&quot;ID&quot;<\/span><span style=\"color: #ABB2BF\">: <\/span><span style=\"color: #D19A66\">3<\/span><span style=\"color: #ABB2BF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">  <\/span><span style=\"color: #E06C75\">&quot;Name&quot;<\/span><span style=\"color: #ABB2BF\">: <\/span><span style=\"color: #98C379\">&quot;Tablet&quot;<\/span><span style=\"color: #ABB2BF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">  <\/span><span style=\"color: #E06C75\">&quot;Price&quot;<\/span><span style=\"color: #ABB2BF\">: <\/span><span style=\"color: #D19A66\">400.00<\/span><span style=\"color: #ABB2BF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">  <\/span><span style=\"color: #E06C75\">&quot;StockQuantity&quot;<\/span><span style=\"color: #ABB2BF\">: <\/span><span style=\"color: #D19A66\">100<\/span><span style=\"color: #ABB2BF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">  <\/span><span style=\"color: #E06C75\">&quot;Category&quot;<\/span><span style=\"color: #ABB2BF\">: {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">    <\/span><span style=\"color: #E06C75\">&quot;ID&quot;<\/span><span style=\"color: #ABB2BF\">: <\/span><span style=\"color: #D19A66\">1<\/span><span style=\"color: #ABB2BF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">    <\/span><span style=\"color: #E06C75\">&quot;Name&quot;<\/span><span style=\"color: #ABB2BF\">: <\/span><span style=\"color: #98C379\">&quot;Electronics&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">4. POST with Complex Types: Including Additional Information in a Complex Property<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Now the client wants to add a new product with additional information, such as dimensions, which is represented as a complex type. The <code>Dimensions<\/code> property includes <code>Length<\/code>, <code>Width<\/code>, and <code>Height<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here&#8217;s our POST request that we send to the OData Products endpoint.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#abb2bf;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282c34\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"POST serviceRoot\/Products\nContent-Type: application\/json\n\n{\n  &quot;Name&quot;: &quot;Monitor&quot;,\n  &quot;Category&quot;: &quot;Electronics&quot;,\n  &quot;Price&quot;: 250.00,\n  &quot;StockQuantity&quot;: 20,\n  &quot;Dimensions&quot;: {\n    &quot;Length&quot;: 24.5,\n    &quot;Width&quot;: 14.0,\n    &quot;Height&quot;: 5.5\n  }\n}\" style=\"color:#abb2bf;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki one-dark-pro\" style=\"background-color: #282c34\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #ABB2BF\">POST serviceRoot\/Products<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">Content-Type: application\/json<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">  <\/span><span style=\"color: #E06C75\">&quot;Name&quot;<\/span><span style=\"color: #ABB2BF\">: <\/span><span style=\"color: #98C379\">&quot;Monitor&quot;<\/span><span style=\"color: #ABB2BF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">  <\/span><span style=\"color: #E06C75\">&quot;Category&quot;<\/span><span style=\"color: #ABB2BF\">: <\/span><span style=\"color: #98C379\">&quot;Electronics&quot;<\/span><span style=\"color: #ABB2BF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">  <\/span><span style=\"color: #E06C75\">&quot;Price&quot;<\/span><span style=\"color: #ABB2BF\">: <\/span><span style=\"color: #D19A66\">250.00<\/span><span style=\"color: #ABB2BF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">  <\/span><span style=\"color: #E06C75\">&quot;StockQuantity&quot;<\/span><span style=\"color: #ABB2BF\">: <\/span><span style=\"color: #D19A66\">20<\/span><span style=\"color: #ABB2BF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">  <\/span><span style=\"color: #E06C75\">&quot;Dimensions&quot;<\/span><span style=\"color: #ABB2BF\">: {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">    <\/span><span style=\"color: #E06C75\">&quot;Length&quot;<\/span><span style=\"color: #ABB2BF\">: <\/span><span style=\"color: #D19A66\">24.5<\/span><span style=\"color: #ABB2BF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">    <\/span><span style=\"color: #E06C75\">&quot;Width&quot;<\/span><span style=\"color: #ABB2BF\">: <\/span><span style=\"color: #D19A66\">14.0<\/span><span style=\"color: #ABB2BF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">    <\/span><span style=\"color: #E06C75\">&quot;Height&quot;<\/span><span style=\"color: #ABB2BF\">: <\/span><span style=\"color: #D19A66\">5.5<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>Dimensions<\/code> property is a complex type that groups related information together: it contains length, width, and height.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Our sample JSON response looks like this:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#abb2bf;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282c34\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"{\n  &quot;ID&quot;: 4,\n  &quot;Name&quot;: &quot;Monitor&quot;,\n  &quot;Category&quot;: &quot;Electronics&quot;,\n  &quot;Price&quot;: 250.00,\n  &quot;StockQuantity&quot;: 20,\n  &quot;Dimensions&quot;: {\n    &quot;Length&quot;: 24.5,\n    &quot;Width&quot;: 14.0,\n    &quot;Height&quot;: 5.5\n  }\n}\" style=\"color:#abb2bf;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki one-dark-pro\" style=\"background-color: #282c34\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #ABB2BF\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">  <\/span><span style=\"color: #E06C75\">&quot;ID&quot;<\/span><span style=\"color: #ABB2BF\">: <\/span><span style=\"color: #D19A66\">4<\/span><span style=\"color: #ABB2BF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">  <\/span><span style=\"color: #E06C75\">&quot;Name&quot;<\/span><span style=\"color: #ABB2BF\">: <\/span><span style=\"color: #98C379\">&quot;Monitor&quot;<\/span><span style=\"color: #ABB2BF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">  <\/span><span style=\"color: #E06C75\">&quot;Category&quot;<\/span><span style=\"color: #ABB2BF\">: <\/span><span style=\"color: #98C379\">&quot;Electronics&quot;<\/span><span style=\"color: #ABB2BF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">  <\/span><span style=\"color: #E06C75\">&quot;Price&quot;<\/span><span style=\"color: #ABB2BF\">: <\/span><span style=\"color: #D19A66\">250.00<\/span><span style=\"color: #ABB2BF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">  <\/span><span style=\"color: #E06C75\">&quot;StockQuantity&quot;<\/span><span style=\"color: #ABB2BF\">: <\/span><span style=\"color: #D19A66\">20<\/span><span style=\"color: #ABB2BF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">  <\/span><span style=\"color: #E06C75\">&quot;Dimensions&quot;<\/span><span style=\"color: #ABB2BF\">: {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">    <\/span><span style=\"color: #E06C75\">&quot;Length&quot;<\/span><span style=\"color: #ABB2BF\">: <\/span><span style=\"color: #D19A66\">24.5<\/span><span style=\"color: #ABB2BF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">    <\/span><span style=\"color: #E06C75\">&quot;Width&quot;<\/span><span style=\"color: #ABB2BF\">: <\/span><span style=\"color: #D19A66\">14.0<\/span><span style=\"color: #ABB2BF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">    <\/span><span style=\"color: #E06C75\">&quot;Height&quot;<\/span><span style=\"color: #ABB2BF\">: <\/span><span style=\"color: #D19A66\">5.5<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">5. POST with Deep Insertion: Creating a Product with a New Category<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s make things even more complex. Now, the client wants to create a new product and simultaneously create a new category for it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>POST Request<\/strong>:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#abb2bf;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282c34\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"POST serviceRoot\/Products\nContent-Type: application\/json\n\n{\n  &quot;Name&quot;: &quot;Headphones&quot;,\n  &quot;Price&quot;: 150.00,\n  &quot;StockQuantity&quot;: 75,\n  &quot;Category&quot;: {\n    &quot;Name&quot;: &quot;Audio Equipment&quot;\n  }\n}\" style=\"color:#abb2bf;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki one-dark-pro\" style=\"background-color: #282c34\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #ABB2BF\">POST serviceRoot\/Products<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">Content-Type: application\/json<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">  <\/span><span style=\"color: #E06C75\">&quot;Name&quot;<\/span><span style=\"color: #ABB2BF\">: <\/span><span style=\"color: #98C379\">&quot;Headphones&quot;<\/span><span style=\"color: #ABB2BF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">  <\/span><span style=\"color: #E06C75\">&quot;Price&quot;<\/span><span style=\"color: #ABB2BF\">: <\/span><span style=\"color: #D19A66\">150.00<\/span><span style=\"color: #ABB2BF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">  <\/span><span style=\"color: #E06C75\">&quot;StockQuantity&quot;<\/span><span style=\"color: #ABB2BF\">: <\/span><span style=\"color: #D19A66\">75<\/span><span style=\"color: #ABB2BF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">  <\/span><span style=\"color: #E06C75\">&quot;Category&quot;<\/span><span style=\"color: #ABB2BF\">: {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">    <\/span><span style=\"color: #E06C75\">&quot;Name&quot;<\/span><span style=\"color: #ABB2BF\">: <\/span><span style=\"color: #98C379\">&quot;Audio Equipment&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p class=\"wp-block-paragraph\">In our POST request, the client provides the details for both the <code>Product<\/code> and the <code>Category<\/code>. The server creates both the product and the associated category.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here&#8217;s our response payload:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#abb2bf;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282c34\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"{\n  &quot;ID&quot;: 5,\n  &quot;Name&quot;: &quot;Headphones&quot;,\n  &quot;Price&quot;: 150.00,\n  &quot;StockQuantity&quot;: 75,\n  &quot;Category&quot;: {\n    &quot;ID&quot;: 3,\n    &quot;Name&quot;: &quot;Audio Equipment&quot;\n  }\n}\" style=\"color:#abb2bf;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki one-dark-pro\" style=\"background-color: #282c34\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #ABB2BF\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">  <\/span><span style=\"color: #E06C75\">&quot;ID&quot;<\/span><span style=\"color: #ABB2BF\">: <\/span><span style=\"color: #D19A66\">5<\/span><span style=\"color: #ABB2BF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">  <\/span><span style=\"color: #E06C75\">&quot;Name&quot;<\/span><span style=\"color: #ABB2BF\">: <\/span><span style=\"color: #98C379\">&quot;Headphones&quot;<\/span><span style=\"color: #ABB2BF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">  <\/span><span style=\"color: #E06C75\">&quot;Price&quot;<\/span><span style=\"color: #ABB2BF\">: <\/span><span style=\"color: #D19A66\">150.00<\/span><span style=\"color: #ABB2BF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">  <\/span><span style=\"color: #E06C75\">&quot;StockQuantity&quot;<\/span><span style=\"color: #ABB2BF\">: <\/span><span style=\"color: #D19A66\">75<\/span><span style=\"color: #ABB2BF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">  <\/span><span style=\"color: #E06C75\">&quot;Category&quot;<\/span><span style=\"color: #ABB2BF\">: {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">    <\/span><span style=\"color: #E06C75\">&quot;ID&quot;<\/span><span style=\"color: #ABB2BF\">: <\/span><span style=\"color: #D19A66\">3<\/span><span style=\"color: #ABB2BF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">    <\/span><span style=\"color: #E06C75\">&quot;Name&quot;<\/span><span style=\"color: #ABB2BF\">: <\/span><span style=\"color: #98C379\">&quot;Audio Equipment&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">6. POST with Batch Requests: Creating Multiple Products in a Single Request<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Oftentimes, we have to add more than just one product. Here&#8217;s how we can add multiple products in a single batch request.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#abb2bf;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282c34\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"POST serviceRoot\/$batch\nContent-Type: multipart\/mixed; boundary=batch_boundary\n\n--batch_boundary\nContent-Type: application\/http\nContent-Transfer-Encoding: binary\n\nPOST serviceRoot\/Products\nContent-Type: application\/json\n\n{\n  &quot;Name&quot;: &quot;Keyboard&quot;,\n  &quot;Category&quot;: &quot;Electronics&quot;,\n  &quot;Price&quot;: 75.00,\n  &quot;StockQuantity&quot;: 200\n}\n\n--batch_boundary\nContent-Type: application\/http\nContent-Transfer-Encoding: binary\n\nPOST serviceRoot\/Products\nContent-Type: application\/json\n\n{\n  &quot;Name&quot;: &quot;Mouse&quot;,\n  &quot;Category&quot;: &quot;Electronics&quot;,\n  &quot;Price&quot;: 40.00,\n  &quot;StockQuantity&quot;: 300\n}\n\n--batch_boundary--\" style=\"color:#abb2bf;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki one-dark-pro\" style=\"background-color: #282c34\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #ABB2BF\">POST serviceRoot\/$batch<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">Content-Type: multipart\/mixed; boundary=batch_boundary<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">--batch_boundary<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">Content-Type: application\/http<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">Content-Transfer-Encoding: binary<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">POST serviceRoot\/Products<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">Content-Type: application\/json<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">  <\/span><span style=\"color: #E06C75\">&quot;Name&quot;<\/span><span style=\"color: #ABB2BF\">: <\/span><span style=\"color: #98C379\">&quot;Keyboard&quot;<\/span><span style=\"color: #ABB2BF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">  <\/span><span style=\"color: #E06C75\">&quot;Category&quot;<\/span><span style=\"color: #ABB2BF\">: <\/span><span style=\"color: #98C379\">&quot;Electronics&quot;<\/span><span style=\"color: #ABB2BF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">  <\/span><span style=\"color: #E06C75\">&quot;Price&quot;<\/span><span style=\"color: #ABB2BF\">: <\/span><span style=\"color: #D19A66\">75.00<\/span><span style=\"color: #ABB2BF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">  <\/span><span style=\"color: #E06C75\">&quot;StockQuantity&quot;<\/span><span style=\"color: #ABB2BF\">: <\/span><span style=\"color: #D19A66\">200<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">--batch_boundary<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">Content-Type: application\/http<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">Content-Transfer-Encoding: binary<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">POST serviceRoot\/Products<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">Content-Type: application\/json<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">  <\/span><span style=\"color: #E06C75\">&quot;Name&quot;<\/span><span style=\"color: #ABB2BF\">: <\/span><span style=\"color: #98C379\">&quot;Mouse&quot;<\/span><span style=\"color: #ABB2BF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">  <\/span><span style=\"color: #E06C75\">&quot;Category&quot;<\/span><span style=\"color: #ABB2BF\">: <\/span><span style=\"color: #98C379\">&quot;Electronics&quot;<\/span><span style=\"color: #ABB2BF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">  <\/span><span style=\"color: #E06C75\">&quot;Price&quot;<\/span><span style=\"color: #ABB2BF\">: <\/span><span style=\"color: #D19A66\">40.00<\/span><span style=\"color: #ABB2BF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">  <\/span><span style=\"color: #E06C75\">&quot;StockQuantity&quot;<\/span><span style=\"color: #ABB2BF\">: <\/span><span style=\"color: #D19A66\">300<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">--batch_boundary--<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p class=\"wp-block-paragraph\">Batch requests allow the client to send multiple requests in a single HTTP request. Each part of the batch corresponds to a separate <code>POST<\/code> request.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Our sample JSON response looks like this:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#abb2bf;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282c34\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"{\n  &quot;responses&quot;: [\n    {\n      &quot;status&quot;: 201,\n      &quot;body&quot;: {\n        &quot;ID&quot;: 6,\n        &quot;Name&quot;: &quot;Keyboard&quot;,\n        &quot;Category&quot;: &quot;Electronics&quot;,\n        &quot;Price&quot;: 75.00,\n        &quot;StockQuantity&quot;: 200\n      }\n    },\n    {\n      &quot;status&quot;: 201,\n      &quot;body&quot;: {\n        &quot;ID&quot;: 7,\n        &quot;Name&quot;: &quot;Mouse&quot;,\n        &quot;Category&quot;: &quot;Electronics&quot;,\n        &quot;Price&quot;: 40.00,\n        &quot;StockQuantity&quot;: 300\n      }\n    }\n  ]\n}\" style=\"color:#abb2bf;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki one-dark-pro\" style=\"background-color: #282c34\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #ABB2BF\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">  <\/span><span style=\"color: #E06C75\">&quot;responses&quot;<\/span><span style=\"color: #ABB2BF\">: [<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">    {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">      <\/span><span style=\"color: #E06C75\">&quot;status&quot;<\/span><span style=\"color: #ABB2BF\">: <\/span><span style=\"color: #D19A66\">201<\/span><span style=\"color: #ABB2BF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">      <\/span><span style=\"color: #E06C75\">&quot;body&quot;<\/span><span style=\"color: #ABB2BF\">: {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">        <\/span><span style=\"color: #E06C75\">&quot;ID&quot;<\/span><span style=\"color: #ABB2BF\">: <\/span><span style=\"color: #D19A66\">6<\/span><span style=\"color: #ABB2BF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">        <\/span><span style=\"color: #E06C75\">&quot;Name&quot;<\/span><span style=\"color: #ABB2BF\">: <\/span><span style=\"color: #98C379\">&quot;Keyboard&quot;<\/span><span style=\"color: #ABB2BF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">        <\/span><span style=\"color: #E06C75\">&quot;Category&quot;<\/span><span style=\"color: #ABB2BF\">: <\/span><span style=\"color: #98C379\">&quot;Electronics&quot;<\/span><span style=\"color: #ABB2BF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">        <\/span><span style=\"color: #E06C75\">&quot;Price&quot;<\/span><span style=\"color: #ABB2BF\">: <\/span><span style=\"color: #D19A66\">75.00<\/span><span style=\"color: #ABB2BF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">        <\/span><span style=\"color: #E06C75\">&quot;StockQuantity&quot;<\/span><span style=\"color: #ABB2BF\">: <\/span><span style=\"color: #D19A66\">200<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">      }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">    },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">    {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">      <\/span><span style=\"color: #E06C75\">&quot;status&quot;<\/span><span style=\"color: #ABB2BF\">: <\/span><span style=\"color: #D19A66\">201<\/span><span style=\"color: #ABB2BF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">      <\/span><span style=\"color: #E06C75\">&quot;body&quot;<\/span><span style=\"color: #ABB2BF\">: {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">        <\/span><span style=\"color: #E06C75\">&quot;ID&quot;<\/span><span style=\"color: #ABB2BF\">: <\/span><span style=\"color: #D19A66\">7<\/span><span style=\"color: #ABB2BF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">        <\/span><span style=\"color: #E06C75\">&quot;Name&quot;<\/span><span style=\"color: #ABB2BF\">: <\/span><span style=\"color: #98C379\">&quot;Mouse&quot;<\/span><span style=\"color: #ABB2BF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">        <\/span><span style=\"color: #E06C75\">&quot;Category&quot;<\/span><span style=\"color: #ABB2BF\">: <\/span><span style=\"color: #98C379\">&quot;Electronics&quot;<\/span><span style=\"color: #ABB2BF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">        <\/span><span style=\"color: #E06C75\">&quot;Price&quot;<\/span><span style=\"color: #ABB2BF\">: <\/span><span style=\"color: #D19A66\">40.00<\/span><span style=\"color: #ABB2BF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">        <\/span><span style=\"color: #E06C75\">&quot;StockQuantity&quot;<\/span><span style=\"color: #ABB2BF\">: <\/span><span style=\"color: #D19A66\">300<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">      }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">    }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">  ]<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">Summary: OData Post Examples<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">OData\u2019s powerful query language makes it a powerful data access technology. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">These examples show how OData <code>POST<\/code> requests can be used to create new resources in a collection, progressively adding more complex features such as handling missing fields, managing relationships, working with complex types, deep insertion, and batch processing. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Each request sends data to the server, which processes it and responds with the created entities, allowing for efficient and structured data management.<\/p>\n\n\n\n<div style=\"background-color: #001524;\"><hr style=\"height: 5px;\">\n<pre style=\"text-align: center; overflow: hidden; white-space: pre-line;\"><span style=\"color: #f1ebda; background-color: #4588d8; font-size: calc(18px + 0.390625vw);\"><strong>Connect to OData, Build a Web App<\/strong><br><span style=\"font-size: 14pt;\">Rapidly build and deploy custom software&nbsp;<\/span><\/span><\/pre>\n<p style=\"text-align: center;\"><a href=\"https:\/\/preview-php85.dzine.org\/five\/get-started\" target=\"_blank\" rel=\"noopener\"><button style=\"background-color: #f8b92b; border: none; color: black; padding: 20px; text-align: center; text-decoration: none; display: inline-block; font-size: 18px; cursor: pointer; margin: 4px 2px; border-radius: 5px;\"><strong>Get Instant Access<\/strong><\/button><br><\/a><\/p>\n<hr style=\"height: 5px;\"><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Learn How to Use OData&#8217;s POST Method with Simple Examples Let&#8217;s explore how OData POST requests can be used to modify and create new resources in a collection. We&#8217;ll use a simple Products collection as the basis for these examples. To learn more about the OData $filter query, read our blog post here. Code-Along: Develop [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":3488,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_eb_attr":"","_uag_custom_page_level_css":"","footnotes":""},"categories":[21],"tags":[],"class_list":["post-3484","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog"],"acf":[],"uagb_featured_image_src":{"full":["https:\/\/preview-php85.dzine.org\/five\/wp-content\/uploads\/2024\/08\/Five.Co-6-Simple-OData-Post-Examples.jpg",1280,720,false],"thumbnail":["https:\/\/preview-php85.dzine.org\/five\/wp-content\/uploads\/2024\/08\/Five.Co-6-Simple-OData-Post-Examples-150x150.jpg",150,150,true],"medium":["https:\/\/preview-php85.dzine.org\/five\/wp-content\/uploads\/2024\/08\/Five.Co-6-Simple-OData-Post-Examples-300x169.jpg",300,169,true],"medium_large":["https:\/\/preview-php85.dzine.org\/five\/wp-content\/uploads\/2024\/08\/Five.Co-6-Simple-OData-Post-Examples-768x432.jpg",768,432,true],"large":["https:\/\/preview-php85.dzine.org\/five\/wp-content\/uploads\/2024\/08\/Five.Co-6-Simple-OData-Post-Examples-1024x576.jpg",1024,576,true],"1536x1536":["https:\/\/preview-php85.dzine.org\/five\/wp-content\/uploads\/2024\/08\/Five.Co-6-Simple-OData-Post-Examples.jpg",1280,720,false],"2048x2048":["https:\/\/preview-php85.dzine.org\/five\/wp-content\/uploads\/2024\/08\/Five.Co-6-Simple-OData-Post-Examples.jpg",1280,720,false]},"uagb_author_info":{"display_name":"Dominik Keller","author_link":"https:\/\/preview-php85.dzine.org\/five\/author\/f1v5_ed3_my\/"},"uagb_comment_info":0,"uagb_excerpt":"Learn How to Use OData&#8217;s POST Method with Simple Examples Let&#8217;s explore how OData POST requests can be used to modify and create new resources in a collection. We&#8217;ll use a simple Products collection as the basis for these examples. To learn more about the OData $filter query, read our blog post here. Code-Along: Develop&hellip;","_links":{"self":[{"href":"https:\/\/preview-php85.dzine.org\/five\/wp-json\/wp\/v2\/posts\/3484","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/preview-php85.dzine.org\/five\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/preview-php85.dzine.org\/five\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/preview-php85.dzine.org\/five\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/preview-php85.dzine.org\/five\/wp-json\/wp\/v2\/comments?post=3484"}],"version-history":[{"count":0,"href":"https:\/\/preview-php85.dzine.org\/five\/wp-json\/wp\/v2\/posts\/3484\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/preview-php85.dzine.org\/five\/wp-json\/wp\/v2\/media\/3488"}],"wp:attachment":[{"href":"https:\/\/preview-php85.dzine.org\/five\/wp-json\/wp\/v2\/media?parent=3484"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/preview-php85.dzine.org\/five\/wp-json\/wp\/v2\/categories?post=3484"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/preview-php85.dzine.org\/five\/wp-json\/wp\/v2\/tags?post=3484"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}