live_help Notes

assignment This action requires one of theses roles: Shop manager, Advanced tutor

settings Params

Param name Description
campus_id optional . Must be String

The campus id or slug

product optional , nil allowed . Must be a Hash
product[name] required . Must be String

The name. Must be unique.

product[description] required . Must be String

The description.

product[price] required . Must be Fixnum

The price.

product[quantity] optional , nil allowed . Must be Fixnum

The quantity.

product[begin_at] optional , nil allowed . Must be DateTime

The begin at.

product[end_at] optional , nil allowed . Must be DateTime

The end at.

product[category_id] required . Must be Fixnum

The category id.

product[kind] required . Must be one of: user, manager, auto.

The kind.

product[slug] optional , nil allowed . Must be String

The slug.

product[image] required . Must be File

The image.

product[is_uniq] optional , nil allowed . Must be one of: true, false.

Is it is uniq ?

product[one_time_purchase] optional , nil allowed . Must be one of: true, false.

Is it one time purchase ?

product[campus_products_attributes] optional , nil allowed . Must be an Array of nested elements

The campus products attributes.

product[campus_products_attributes][campus_id] required . Must be Fixnum

The campus id.

product[campus_products_attributes][_destroy] optional , nil allowed . Must be String

The destroy.

POST /v2/products
{
  "product": {
    "campus_products_attributes": [
      {
        "campus_id": "5"
      }
    ],
    "name": "Chuck Norris's keyboard doesn't have a Ctrl key because nothing controls Chuck Norris.",
    "description": "Utapau",
    "price": "10",
    "quantity": "10",
    "begin_at": "2017-05-22 13:43:51 UTC",
    "end_at": "2023-11-22 13:43:51 UTC",
    "category_id": "3",
    "kind": "auto",
    "slug": "Kashyyyk",
    "image": {
      "tempfile": [],
      "original_filename": "logo.png",
      "content_type": "image/png+xml",
      "headers": "Content-Disposition: form-data; name=\"product[image]\"; filename=\"logo.png\"\r\nContent-Type: image/png+xml\r\nContent-Length: 3058\r\n"
    },
    "is_uniq": "true",
    "one_time_purchase": "true"
  }
}
201
{
  "id": 6,
  "name": "Chuck Norris's keyboard doesn't have a Ctrl key because nothing controls Chuck Norris.",
  "description": "Utapau",
  "price": 10,
  "quantity": 10,
  "begin_at": "2017-05-22T13:43:51.000Z",
  "end_at": "2023-11-22T13:43:51.000Z",
  "category_id": 3,
  "created_at": "2017-11-22T13:43:52.063Z",
  "updated_at": "2017-11-22T13:43:52.097Z",
  "kind": "auto",
  "slug": "chuck-norris-s-keyboard-doesn-t-have-a-ctrl-key-because-nothing-controls-chuck-norris",
  "image": {
    "url": "/uploads/product/image/6/logo.png",
    "thumb": {
      "url": "/uploads/product/image/6/thumb_logo.png"
    }
  },
  "is_uniq": true,
  "one_time_purchase": true
}
curl  -X POST -H "Authorization: Bearer YOUR_ACCESS_TOKEN" -H "Content-Type: application/json" -d '{"product":{"campus_products_attributes":[{"campus_id":"5"}],"name":"Chuck Norris's keyboard doesn't have a Ctrl key because nothing controls Chuck Norris.","description":"Utapau","price":"10","quantity":"10","begin_at":"2017-05-22 13:43:51 UTC","end_at":"2023-11-22 13:43:51 UTC","category_id":"3","kind":"auto","slug":"Kashyyyk","image":{"tempfile":[],"original_filename":"logo.png","content_type":"image/png+xml","headers":"Content-Disposition: form-data; name=\"product[image]\"; filename=\"logo.png\"\r\nContent-Type: image/png+xml\r\nContent-Length: 3058\r\n"},"is_uniq":"true","one_time_purchase":"true"}}' "https://api.intra.42.fr/v2/products"

{
  "id": 6,
  "name": "Chuck Norris's keyboard doesn't have a Ctrl key because nothing controls Chuck Norris.",
  "description": "Utapau",
  "price": 10,
  "quantity": 10,
  "begin_at": "2017-05-22T13:43:51.000Z",
  "end_at": "2023-11-22T13:43:51.000Z",
  "category_id": 3,
  "created_at": "2017-11-22T13:43:52.063Z",
  "updated_at": "2017-11-22T13:43:52.097Z",
  "kind": "auto",
  "slug": "chuck-norris-s-keyboard-doesn-t-have-a-ctrl-key-because-nothing-controls-chuck-norris",
  "image": {
    "url": "/uploads/product/image/6/logo.png",
    "thumb": {
      "url": "/uploads/product/image/6/thumb_logo.png"
    }
  },
  "is_uniq": true,
  "one_time_purchase": true
}
require "oauth2"
UID = "Your application uid"
SECRET = "Your application secret"
client = OAuth2::Client.new(UID, SECRET, site: "https://api.intra.42.fr")
token = client.client_credentials.get_token

params = {product: {campus_products_attributes: [{campus_id: "5"}], name: "Chuck Norris's keyboard doesn't have a Ctrl key because nothing controls Chuck Norris.", description: "Utapau", price: "10", quantity: "10", begin_at: "2017-05-22 13:43:51 UTC", end_at: "2023-11-22 13:43:51 UTC", category_id: "3", kind: "auto", slug: "Kashyyyk", image: {tempfile: [], original_filename: "logo.png", content_type: "image/png+xml", headers: "Content-Disposition: form-data; name="product[image]"; filename="logo.png"
Content-Type: image/png+xml
Content-Length: 3058
"}, is_uniq: "true", one_time_purchase: "true"}}
response = token.post("/v2/products", params: params)
response.status
# => 201
response.parsed
# => {"id"=>6, "name"=>"Chuck Norris's keyboard doesn't have a Ctrl key because nothing controls Chuck Norris.", "description"=>"Utapau", "price"=>10, "quantity"=>10, "begin_at"=>"2017-05-22T13:43:51.000Z", "end_at"=>"2023-11-22T13:43:51.000Z", "category_id"=>3, "created_at"=>"2017-11-22T13:43:52.063Z", "updated_at"=>"2017-11-22T13:43:52.097Z", "kind"=>"auto", "slug"=>"chuck-norris-s-keyboard-doesn-t-have-a-ctrl-key-because-nothing-controls-chuck-norris", "image"=>{"url"=>"/uploads/product/image/6/logo.png", "thumb"=>{"url"=>"/uploads/product/image/6/thumb_logo.png"}}, "is_uniq"=>true, "one_time_purchase"=>true}