AJAX in action files

In this article:


    The actions files in Hostedshop are used to add items to the cart, log users in, etc. It is now possible to use AJAX to, for example, add items to the cart and get an AJAX response back. This avoids reloading the page and provides a better user experience.

    This option will be expanded as needed.

    Our AJAX action files or AJAX endpoints are not REST APIs, but POST/GET endpoints with a JSON response. All our endpoints have underlying actions that determine the final action to be taken on each endpoint. With cart, it could for example be interesting to add something to the cart or remove something from the cart.

    All endpoints always deliver the same response. A JSON object contains the following parameters:
     

    Parameter

    Value

    Description

    text

    (string)

    The text to be displayed to the user

    status

    (int)

    Statuscode; 0 for success, 1 for error

    type

    (string)

    The action type in a word

    itemId

    (int)

    Id for the updated entity, e.g. a product

    Walkthrough of action endpoints:

    Description of /actions/cart/ endpoint:

    This endpoint is for all cart actions./actions/cart/ har følgende actions:

    • /actions/cart/add (add to basket) - POST endpoint
       

    Parameter

    Required

    Value

    Description

    product [xx] [amount]

    ×

    (int)

    Product quantity to add to cart, where xx is the product ID.

    product [xx] [variant]

     

    (int)

    Product variant to add to cart, where xx is the product ID.

    product [xx] [additional][yy][]

     

    (int)

    Product option, where xx is the product id and yy is the option id.

    product [xx][packet_products][]

     

    (int)

    Product package product, where xx is the product id and xx is the product id.

    • /actions/cart/remove (remove from basket) - GET endpoint
       

    Parameter

    Required

    Value

    Description

    id

    ×

    (int)

    The cart ID to delete

    • /actions/cart/plus (update product in cart with an extra) - GET endpoint
       

    Parameter

    Required

    Value

    Description

    id

    ×

    (int)

    The cart id that should be updated

     

    • /actions/cart/minus (remove 1, by 1 same as remove, number of single product in cart) - GET endpoint
       

    Parameter

    Required

    Value

    Description

    id

    ×

    (int)

    The cart ID to be updated

    • /actions/cart/update (reload cart) - GET endpoint
       

    Parameter

    Required

    Value

    Description

     

     

     

     

    • /actions/cart/empty (empty cart) - GET endpoint
       

    Parameter

    Required

    Value

    Description

     

     

     

     

    • /actions/cart/couponAdd  (add discount code to cart) - POST endpoint

    Parameter

    Required

    Value

    Description

    coupon

    ×

    (string)

    Coupon code to add to basket.

    • /actions/cart/couponRemove (remove discount code from cart) - GET endpoint
       

    Parameter

    Required

    Value

    Description

     

     

     

     

    • /actions/cart/reorder (reorder order) - GET endpoint
       

    Parameter

    Required

    Value

    Description

    id

    ×

    (int)

    The order ID to be reordered

    • /actions/cart/reorderItem (reorder product from order) - GET endpoint
       

    Parameter

    Required

    Value

    Description

    id

    ×

    (int)

    The order line ID to reorder


    Description of the /actions/user/ endpoint:

    This endpoint is for all user actions. /actions/user/ har følgende actions:

    • /actions/user/add (create a user) - POST endpoint
       

    Parameter

    Required

    Value

    Description

    firstname

    ×

    (string)

    User first name

    lastname

    ×

    (string)

    User last name

    address

    ×

    (string)

    User adress

    zipcode

    ×

    (string)

    User postalcode

    city

    ×

    (string)

    User's city

    email

    ×

    (string)

    User email

    password

    ×

    (string)

    User password

    passwordConfirmation

    ×

    (string)

    User password confirmation

     

    vatNumber

    (depending on setting)

    (string)

    User/company CVR

    eanNumber

    (depending on setting)

    (string)

    User/public EAN

    phone

    (depending on setting)

    (string)

    User phone number

    mobilephone

     

    (string)

    User mobilephone number

    company

     

    (string)

    User/company name

    country

     

    (string)

    User country

    countryCode

     

    (string)

    User country code

    state

     

    (string)

    User state

    birthday

     

    (string) (dd/mm/yyyy)

    User birthday

    newsletter

     

    (boolean)

    Sign up for the newsletter

    interestGroups

     

    (int) eller (array)

    User interest group IDs

    userGroup

     

    (int)

    User group ID

    • /actions/user/logout (log user out) - GET endpoint
       

    Parameter

    Required

    Value

    Description

     

     

     

     

    • /actions/user/login (log user in) - POST endpoint
       

    Parameter

    Required

    Value

    Description

    username

    ×

    (string)

    Username (email)

    password

    ×

    (string)

    User password

    • /actions/user/login (log bruger ind) - POST endpoint
       

    Parameter

    Required

    Value

    Description

    username

    ×

    (string)

    Username (email)

    password

    ×

    (string)

    User password

    • /actions/user/add2b (opret en B2B bruger) - POST endpoint
       

    Parameter

    Required

    Value

    Description

    firstname

    ×

    (string)

    User first name

    lastname

    ×

    (string)

    User last name

    address

    ×

    (string)

    User address

    zipcode

    ×

    (string)

    User postal code

    city

    ×

    (string)

    User city name

    email

    ×

    (string)

    User email

    password

    ×

    (string)

    User password

    passwordConfirmation

    ×

    (string)

    User password confirmation

    vatNumber

    (either VAT or EAN)

    (string)

    User/company CVR

    eanNumber

    (either VAT or EAN)

    (string)

    User/public EAN

    phone

    (depending on setting)

    (string)

    User phone number

    mobilephone

     

    (string)

    User mobile number

    company

     

    (string)

    User/company name

    country

     

    (string)

    User country

    countryCode

     

    (string)

    User country code

    state

     

    (string)

    User state

    birthday

     

    (string) (dd/mm/yyyy)

    User birthday

    newsletter

     

    (boolean)

    User signs up for newsletter

    interestGroups

     

    (int) or (array)

    User interest group IDs

    userGroup

     

    (int)

    User group ID

    • /actions/user/edit (edit user) or () - POST endpoint
       

    Parameter

    Required

    Value

    Description

    firstname

    ×

    (string)

    User first name

    lastname

    ×

    (string)

    User last name

    address

    ×

    (string)

    User address

    zipcode

    ×

    (string)

    User postal code

    city

    ×

    (string)

    User city name

    email

    ×

    (string)

    User email

    password

    ×

    (string)

    User password

    passwordConfirmation

    ×

    (string)

    User password confirmation

    vatNumber

    (depending on setting)

    (string)

    User/company CVR

    eanNumber

    (depending on setting)

    (string)

    User/public EAN

    phone

    (depending on setting)

    (string)

    User phone number

    mobilephone

     

    (string)

    User mobile number

    company

     

    (string)

    User/company name

    country

     

    (string)

    User country

    countryCode

     

    (string)

    User country code

    state

     

    (string)

    User state

    birthday

     

    (string) (dd/mm/yyyy)

    User birthday

    newsletter

     

    (boolean)

    Should user sign up for the newsletter

    interestGroups

     

    (int) or (array)

    User interest group IDs

    interestGroupsOff

     

    (int) or (array)

    Id of user interest groups interest groups

    • /actions/user/editpassword (edit user password) - POST endpoint
       

    Parameter

    Required

    Value

    Description

    passwordOld

    ×

    (string)

    User password

    passwordNew

    ×

    (string)

    New user password

    passwordNewConfirm

    ×

    (string)

    New user password verification

    • /actions/user/editemail (edit user email) - POST endpoint
       

    Parameter

    Required

    Value

    Description

    email

    ×

    (string)

    User email

    password

    ×

    (string)

    User password

    passwordConfirm

    ×

    (string)

    User password confirmation

    • /actions/user/passwordsend (send new password) - POST endpoint
       
    • /actions/user/passwordrecover (send new password) - POST endpoint
       

    Parameter

    Required

    Value

    Description

    email

    ×

    (string)

    User email

    • /actions/user/remove (request user deletion) - GET endpoint
       

    Parameter

    Required

    Value

    Description