Get several Variants in one call

hrandyhrandy Posts: 2Member
Hello,

Is it possible, and if yes, how...to get several variants within one call. I know I can filter the call on e.g. article_code=1234, but I would like to get also e.g. =5678 and =9432. Before the call I have knowledge of 12 articlecodes I need to fetch, but now I have to make 12 seperate calls (with the cost of ~1s/call). I guess it would be possible to extend the filter something like: article_code=1234,5678,9432

Regards,
R.A. Hendriks

3 comments

  • sdohmensdohmen Posts: 12Member
    I am not sure i understand but i am assuming you just want all variants itself. This is pretty easy to do:

    COUNTL=$(curl https://api.webshopapp.com/nl/products/count.json -u "$KEY:$SECRET")
    COUNTL=${COUNTL%?}
    COUNTL=$(echo $COUNTL | cut -d ':' -f 2)
    echo "Aantal producten in de webshop:" $COUNTL

    COUNTN=1
    PAGINA=1

    while [ $COUNTN -lt $COUNTL ]
    do
            curl -g 'https://api.webshopapp.com/nl/products.xml?limit=250&page='$PAGINA -u "$KEY:$SECRET" > $PAD/producten/products_$PAGINA.xml
            curl -g 'https://api.webshopapp.com/nl/variants.xml?limit=250&page='$PAGINA -u "$KEY:$SECRET" > $PAD/producten/variants_$PAGINA.xml

            PAGINA=$((PAGINA+1))
            echo $PAGINA
            COUNTN=$((COUNTN+250))
            echo $COUNTN

    done

    This above loops over the variants and gets them all in seperate xml files. From there you can do whatever you want with them.
  • Alex LugoAlex Lugo Posts: 96Administrator, Lightspeed Staff moderator
    Hi,

    Currently, there isn't a method to do that. You could fetch all the variants and then filter those ones that you need from the results, or as you mentioned, make single calls.
    Alex Lugo
    API Support Specialist
    Lightspeed HQ
  • hrandyhrandy Posts: 2Member
    Hi,

    Ok, clear. A loop is not specifically the way to go (I am doing that at the moment, but takes approx. 1s/call times 12 in my case). Fetching all variants is restricted to a max of 250 (and I got near 8000 variants). Since it is not a key-part of the system I am building I'll keep it to the loop knowingly the 12s delay. I could make it a-synchonous...but I rather fetch a cup of coffee then! ;)

    Cheers,
    Randy
Sign In or Register to comment.