404 Variation Option not found when creating multiple options at once


#1

Hello,

I’m using the following process:

1. create a product

POST https://api.moltin.com/v2/products
{"intra_available":false,"discount_ratio":10,"hours_count":80,"showcase":false,"document_url":"https://superma
n.com/training.pdf","learning_goal":"Improve yourself","requirement":"Human being","teaching_method":"One step at a time","attendance_mode":"MOOC","initial_place_count":5,"trainer":"Clark Kent (himself)","customer":"17a42a7d-9620-4eb4-9bc4-7342c3e920b5","cpf_code":"azerty","type":"product","name":"How to Be Superman","slug":"daily-planet-s-how-to-be-superman-2018-06-17","sku":"17a42a7d-9620-4eb4-9bc4-7342c3e920b5-how-to-be-superman-2018-06-17","manage_stock":true,"description":"Superman is bla bla bla","price":[{"amount":99900,"currency":"EUR","includes_tax":false}],"status":"live","commodity_type":"digital"})

2. create a variation

POST https://api.moltin.com/v2/variations
{"type":"product-variation","name":"training_dates_bb253222-2f5a-4fd0-889f-f92b12ea555c"}

3. create variation options (parallel)

We create a variation option per training date:

  • 17/06/2018
  • 02/07/2018
  • 17/07/2018

17/06/2018

POST https://api.moltin.com/v2/variations/86bcbca4-1c46-4a01-b2ac-90f2e557588a/options
{"type":"option","name":"training_date_2018-06-17","description":"Variation on training date"}

02/07/2018

POST https://api.moltin.com/v2/variations/86bcbca4-1c46-4a01-b2ac-90f2e557588a/options
{"type":"option","name":"training_date_2018-07-02","description":"Variation on training date"}

17/07/2018

POST https://api.moltin.com/v2/variations/86bcbca4-1c46-4a01-b2ac-90f2e557588a/options
{"type":"option","name":"training_date_2018-07-17","description":"Variation on training date"}

4. create modifiers

17/06/2018

POST https://api.moltin.com/v2/variations/86bcbca4-1c46-4a01-b2ac-90f2e557588a/options/e198617c-0d66-4dbe-99bb-e633e1e40a8a/modifiers
{"type":"modifier","modifier_type":"slug_append","value":"_2018-06-17"}

02/07/2018

POST https://api.moltin.com/v2/variations/86bcbca4-1c46-4a01-b2ac-90f2e557588a/options/fb7e7d18-81aa-4f20-b8dc-5ff44e3a78d8/modifiers
{"type":"modifier","modifier_type":"slug_append","value":"_2018-07-02"}

17/07/2018

POST https://api.moltin.com/v2/variations/86bcbca4-1c46-4a01-b2ac-90f2e557588a/options/a5d37f55-8f8b-4c4d-8e1c-541e0668a94d/modifiers
{"type":"modifier","modifier_type":"slug_append","value":"_2018-07-17"}
MoltinError(404,Not Found,ArrayBuffer(MoltinErrorReason(None,404,None,Some(Variation Option not found),The requested variation option could not be found)))

My theory is that I should use an array of variation options because POST is replacing the current variation option (and not adding a new one) ?

If this is the case, I think the documentation should use an array with one element (instead of an object).

Thanks,
Guillaume


#2

query

POST https://api.moltin.com/v2/variations/bf0ee6e0-7a5e-4691-b211-babfe6ba197d/options

payload

[{"type":"option","name":"training_date_2018-06-17","description":"Variation on training date"},{"type":"option","name":"training_date_2018-07-02","description":"Variation on training date"},{"type":"option","name":"training_date_2018-07-17","description":"Variation on training date"}]

response

MoltinError(422,Unprocessable Entity,ArrayBuffer(MoltinErrorReason(None,422,None,Some(Failed Validation),The data.type field is required.), MoltinErrorReason(None,422,None,Some(Failed Validation),The data.name field is required.), MoltinErrorReason(None,422,None,Some(Failed Validation),The data.description field is required.)))

No it’s not possible to send an array of options… so I don’t know why the API returns a 404… ? I’m pretty sure the variation option exists because I’m using the id returned from POST https://api.moltin.com/v2/variations/86bcbca4-1c46-4a01-b2ac-90f2e557588a/options.


#3

I think there’s a race condition somewhere.

Below are the response from Moltin API:

First option

{
  "data": {
    "type": "product-variation",
    "id": "c950a6ed-60d3-4a2a-9272-76868c72ec39",
    "name": "training_dates_d0b47593-0b6c-48f5-a2bd-a6b8c9e16331",
    "options": [
      {
        "id": "d0b827da-79b9-4174-aa24-24e46dfc7eab",
        "name": "training_date_2018-06-17",
        "description": "Variation on training date",
        "modifiers": []
      }
    ],
    "relationships": {
      "options": {
        "data": [
          {
            "type": "option",
            "id": "d0b827da-79b9-4174-aa24-24e46dfc7eab"
          }
        ]
      }
    }
  }
}

Second option

{
  "data": {
    "type": "product-variation",
    "id": "c950a6ed-60d3-4a2a-9272-76868c72ec39",
    "name": "training_dates_d0b47593-0b6c-48f5-a2bd-a6b8c9e16331",
    "options": [
      {
        "id": "d0b827da-79b9-4174-aa24-24e46dfc7eab",
        "name": "training_date_2018-06-17",
        "description": "Variation on training date",
        "modifiers": []
      },
      {
        "id": "b17b7cf8-7e22-4c82-8a1e-ea823939a43a",
        "name": "training_date_2018-07-02",
        "description": "Variation on training date",
        "modifiers": []
      }
    ],
    "relationships": {
      "options": {
        "data": [
          {
            "type": "option",
            "id": "d0b827da-79b9-4174-aa24-24e46dfc7eab"
          },
          {
            "type": "option",
            "id": "b17b7cf8-7e22-4c82-8a1e-ea823939a43a"
          }
        ]
      }
    }
  }
}

Third option

{
  "data": {
    "type": "product-variation",
    "id": "c950a6ed-60d3-4a2a-9272-76868c72ec39",
    "name": "training_dates_d0b47593-0b6c-48f5-a2bd-a6b8c9e16331",
    "options": [
      {
        "id": "d0b827da-79b9-4174-aa24-24e46dfc7eab",
        "name": "training_date_2018-06-17",
        "description": "Variation on training date",
        "modifiers": []
      },
      {
        "id": "c76bcaee-ab1b-4e3e-b15f-2ae7986bab8a",
        "name": "training_date_2018-07-17",
        "description": "Variation on training date",
        "modifiers": []
      }
    ],
    "relationships": {
      "options": {
        "data": [
          {
            "type": "option",
            "id": "d0b827da-79b9-4174-aa24-24e46dfc7eab"
          },
          {
            "type": "option",
            "id": "c76bcaee-ab1b-4e3e-b15f-2ae7986bab8a"
          }
        ]
      }
    }
  }
}

There’s only two options in the last response.
As you can see training_date_2018-07-02 was overridden by training_date_2018-07-17.

Maybe the API is doing the following:

  • read the current state (since the two requests are in parallel both get the same state with only one option training_date_2018-06-17)
  • add the new option to the state
    • first request: training_date_2018-06-17 + training_date_2018-07-02
    • second request: training_date_2018-06-17 + training_date_2018-07-17
  • persist the state
    • training_date_2018-06-17 + training_date_2018-07-02 is persisted
    • training_date_2018-06-17 + training_date_2018-07-17 is persisted (training_date_2018-07-02 is gone)

#4

I can confirm that if I create variation option sequentially then this issue is gone


#5

I’ve also noticed the same issue with modifiers:

POST https://api.moltin.com/v2/products/43cbe49e-83e8-4b30-ba68-d5a0e1ecf3c2/build
MoltinError(422,Unprocessable Entity,ArrayBuffer(MoltinErrorReason(None,422,None,Some(Variation Option has no modifier attached.),The `training_date_2018-07-17` variation option (with an ID of `a7fa0624-c4e1-451f-ba3b-a85356e021ba`) cannot be used to generate child products as no modifiers are attached.)))

And indeed my modifier has been erased:

{
  "data": {
    "type": "product-variation",
    "id": "e61d36a0-e881-4c7a-b01d-554e281b93dd",
    "name": "training_dates_0cd2ee4b-5a4c-48be-a58f-a8b2eeeee982",
    "options": [
      {
        "id": "7f5947c3-aa6a-49e4-88c4-daf9851dd0a0",
        "name": "training_date_2018-06-17",
        "description": "Variation on training date",
        "modifiers": [
          {
            "id": "d57be6c6-331a-440d-a27f-9c749b5084c6",
            "type": "slug_append",
            "value": "_2018-06-17"
          },
          {
            "id": "ac1f8a97-01f5-4296-aabc-3d5b6b076480",
            "type": "sku_append",
            "value": "_2018-06-17"
          }
        ]
      },
      {
        "id": "e76b9b27-a424-4d90-9368-7db596abdc9d",
        "name": "training_date_2018-07-02",
        "description": "Variation on training date",
        "modifiers": [
          {
            "id": "06689aea-10f9-4f05-99ec-1ed7d86295af",
            "type": "slug_append",
            "value": "_2018-07-02"
          },
          {
            "id": "750e1ab0-b5ea-47d6-bbc7-4d047bf31dce",
            "type": "sku_append",
            "value": "_2018-07-02"
          }
        ]
      },
      {
        "id": "256b8b30-c864-4882-932a-6ffb71a7fb90",
        "name": "training_date_2018-07-17",
        "description": "Variation on training date",
        "modifiers": []
      }
    ],
    "relationships": {
      "options": {
        "data": [
          {
            "type": "option",
            "id": "7f5947c3-aa6a-49e4-88c4-daf9851dd0a0"
          },
          {
            "type": "option",
            "id": "e76b9b27-a424-4d90-9368-7db596abdc9d"
          },
          {
            "type": "option",
            "id": "256b8b30-c864-4882-932a-6ffb71a7fb90"
          }
        ]
      }
    }
  },
  "included": {
    "options": [
      {
        "type": "option",
        "id": "7f5947c3-aa6a-49e4-88c4-daf9851dd0a0",
        "name": "training_date_2018-06-17",
        "description": "Variation on training date",
        "relationships": {
          "modifiers": {
            "data": [
              {
                "type": "modifier",
                "id": "d57be6c6-331a-440d-a27f-9c749b5084c6"
              },
              {
                "type": "modifier",
                "id": "ac1f8a97-01f5-4296-aabc-3d5b6b076480"
              }
            ]
          }
        }
      },
      {
        "type": "option",
        "id": "e76b9b27-a424-4d90-9368-7db596abdc9d",
        "name": "training_date_2018-07-02",
        "description": "Variation on training date",
        "relationships": {
          "modifiers": {
            "data": [
              {
                "type": "modifier",
                "id": "06689aea-10f9-4f05-99ec-1ed7d86295af"
              },
              {
                "type": "modifier",
                "id": "750e1ab0-b5ea-47d6-bbc7-4d047bf31dce"
              }
            ]
          }
        }
      },
      {
        "type": "option",
        "id": "256b8b30-c864-4882-932a-6ffb71a7fb90",
        "name": "training_date_2018-07-17",
        "description": "Variation on training date",
        "relationships": {
          "modifiers": {
            "data": []
          }
        }
      }
    ],
    "modifiers": [
      {
        "id": "d57be6c6-331a-440d-a27f-9c749b5084c6",
        "type": "modifier",
        "modifier_type": "slug_append",
        "value": "_2018-06-17"
      },
      {
        "id": "ac1f8a97-01f5-4296-aabc-3d5b6b076480",
        "type": "modifier",
        "modifier_type": "sku_append",
        "value": "_2018-06-17"
      },
      {
        "id": "06689aea-10f9-4f05-99ec-1ed7d86295af",
        "type": "modifier",
        "modifier_type": "slug_append",
        "value": "_2018-07-02"
      },
      {
        "id": "750e1ab0-b5ea-47d6-bbc7-4d047bf31dce",
        "type": "modifier",
        "modifier_type": "sku_append",
        "value": "_2018-07-02"
      }
    ]
  }
}

Switching to sequential solve this issue.


#6

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.