• Resolved Flamekebab

    (@flamekebab)


    I used to run a PHP script that would grab order data from the database and put together printable invoices for me.

    I wrote the script and would run it from the server’s command line.

    The way orders are stored has changed in 2.x so the script no longer works. It looks like I should be able to get the same data from the server using the new API.

    I’m not quite sure where to start though. If I understand correctly I should be able to use cURL in PHP to connect to the API and get data that way. Is that correct?

    I just want to make sure I’m researching in the right direction!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Flamekebab

    (@flamekebab)

    Probably the first stupid question:

    Which URL am I supposed to use?
    The documentation refers to this, for example:
    https://jigoshop.dev/api/v1/products/:id

    How does that relate to my JigoShop installation?

    Should it look like this?
    https://fox-box.co.uk/wp-content/plugins/jigoshop-ecommerce/src/Jigoshop/Api.php/v1/products/:6531

    Second stupid question: the documentation talks about a token.

    Before requesting information please make sure that you set authorization token and you are including it in headers. Each request to get or set data have to be provided with this header example:

    Authorization: Bearer [token]

    Right. Okay. What’s a token?

    In the JigoShop settings there’s a secret key but there’s also users and passwords:

    So, erm, what is the token supposed to look like?

    I’ve tried this, for example:
    curl https://fox-box.co.uk/wp-content/plugins/jigoshop-ecommerce/src/Jigoshop/Api.php/v1/products/:6531 -X GET -H "Authorization: Bearer [SOMETHING]"

    [Something] has been secret key, user, password, and user:password. I’m guessing all of those are wrong or something.

    By the looks of it the API should be easy to use but I cannot understand what I’m doing wrong because I know so little about how these things are supposed to work.

    Thread Starter Flamekebab

    (@flamekebab)

    Right, after a pointer from the JigoShop support staff it looks like the way to access it is relatively straightforward once one has a few key bits of information.

    First off – the location of the API!

    So my shop is at http://fox-box.co.uk

    The API access is as follows for me:
    https://fox-box.co.uk/api/v1/

    Visiting https://fox-box.co.uk/api/v1/ping results in this:
    {"success":true,"time":1494254232}
    That shows that we’ve got the right location!

    Then it’s a matter of authenticating. Setup users and passwords in JigoShop’s advanced settings tab.

    Running this:
    curl https://fox-box.co.uk/api/v1/token -X POST -u user:password

    Outputs this:
    {"success":true,"token":"[censored]"}

    The censored token being a string that’s 200+ characters long.
    That token is then used to make requests to the API. For example running this:
    curl https://fox-box.co.uk/api/v1/products/6531 -X GET -H "Authorization: Bearer [censored]"

    Spits out this:

    {
    "success": true,
    "data": {
    "id": 6531,
    "type": "simple",
    "name": "Fox Box Frankenork",
    "description": "<p>Back in 2010 <a href="http://gorkamorka.co.uk">The Unnamed Gorkamorka Site</a> released a Halloween scenario featuring “Da Monster” drawn by <a href="http://taytonclait.deviantart.com/art/Da-Frankenork-204020294">Clayton Tait</a>. Well <a href="https://yaktribe.org">YakTribe</a> had a contest a little while back with the theme “<a href="https://yaktribe.org/community/threads/yaktribe-competition-13-it-came-from-the.4663/">It came from the…</a>” and I felt like having a bash at this sculpt would be a fun challenge. It’s taken a while to get it cleared for commercial release but now we’re good to go!</p> <p>As you can see in the comparison photos – this guy is <em>big</em>. He can easily go toe-to-toe with a Games Workshop Ork warboss and uses a similar 40mm base.</p> <p>Also he only has nine toes. I was planning to link to <a href="http://weeblsstuff.wikia.com/wiki/Joust">the first Joust episode of Weebl and Bob at this point</a> but it’s no longer easily accessible (<a href="http://swfchan.com/5/21304/?Weebl+and+Bob+-+084+-+Joust.swf">although it can be found here</a>) so my hilariously antiquated pop culture references will have to be forgone on this occasion.</p> <p>This kit is supplied in four parts, including the base, cast in resin and so some clean-up may be required. For further details see our <a title="Working With Resin" href="http://fox-box.co.uk/working-with-resin/" target="_blank" rel="noopener noreferrer">Working With Resin page</a>.</p> <p>Sculpted by Benjamin Fox. Supplied unpainted.</p> <p><iframe src="https://www.youtube.com/embed/Iz8VC1uji3s?rel=0" width="518" height="291" frameborder="0" allowfullscreen="allowfullscreen"></iframe></p> ",
    "sku": "",
    "brand": "Fox Box",
    "gtin": "",
    "mpn": "",
    "featured": false,
    "visibility": 3,
    "is_taxable": true,
    "tax_classes": [
      "standard"
    ],
    "size": {
    "weight": "0",
    "width": "0",
    "height": "0",
    "length": "0"
    },
    "attributes": [],
    "attribute_order": null,
    "attachments": {
    "image": [
      {
    "width": 1000,
    "height": 1000,
    "file": "http://fox-box.co.uk/wp-content/uploads/2016/10/frankenork_square_side.jpg",
    "sizes": {
    "thumbnail": {
    "file": "http://fox-box.co.uk/wp-content/uploads/frankenork_square_side-150x150.jpg",
    "width": 150,
    "height": 150,
    "mime-type": "image/jpeg"
    },
    "medium": {
    "file": "http://fox-box.co.uk/wp-content/uploads/frankenork_square_side-250x250.jpg",
    "width": 250,
    "height": 250,
    "mime-type": "image/jpeg"
    },
    "medium_large": {
    "file": "http://fox-box.co.uk/wp-content/uploads/frankenork_square_side-768x768.jpg",
    "width": 768,
    "height": 768,
    "mime-type": "image/jpeg"
    },
    "post-thumbnail": {
    "file": "http://fox-box.co.uk/wp-content/uploads/frankenork_square_side-980x110.jpg",
    "width": 980,
    "height": 110,
    "mime-type": "image/jpeg"
    },
    "shop_tiny": {
    "file": "http://fox-box.co.uk/wp-content/uploads/frankenork_square_side-36x36.jpg",
    "width": 36,
    "height": 36,
    "mime-type": "image/jpeg"
    },
    "shop_thumbnail": {
    "file": "http://fox-box.co.uk/wp-content/uploads/frankenork_square_side-90x90.jpg",
    "width": 90,
    "height": 90,
    "mime-type": "image/jpeg"
    },
    "shop_small": {
    "file": "http://fox-box.co.uk/wp-content/uploads/frankenork_square_side-150x150.jpg",
    "width": 150,
    "height": 150,
    "mime-type": "image/jpeg"
    },
    "shop_large": {
    "file": "http://fox-box.co.uk/wp-content/uploads/frankenork_square_side-300x300.jpg",
    "width": 300,
    "height": 300,
    "mime-type": "image/jpeg"
    },
    "admin_product_list": {
    "file": "http://fox-box.co.uk/wp-content/uploads/frankenork_square_side-32x32.jpg",
    "width": 32,
    "height": 32,
    "mime-type": "image/jpeg"
    }
    },
    "image_meta": {
    "aperture": "0",
    "credit": "",
    "camera": "",
    "caption": "",
    "created_timestamp": "0",
    "copyright": "",
    "focal_length": "0",
    "iso": "0",
    "shutter_speed": "0",
    "title": "",
    "orientation": "0",
    "keywords": [],
    }
    },
      {
    "width": 1000,
    "height": 1000,
    "file": "http://fox-box.co.uk/wp-content/uploads/2016/10/frankenork_square_back.jpg",
    "sizes": {
    "thumbnail": {
    "file": "http://fox-box.co.uk/wp-content/uploads/frankenork_square_back-150x150.jpg",
    "width": 150,
    "height": 150,
    "mime-type": "image/jpeg"
    },
    "medium": {
    "file": "http://fox-box.co.uk/wp-content/uploads/frankenork_square_back-250x250.jpg",
    "width": 250,
    "height": 250,
    "mime-type": "image/jpeg"
    },
    "medium_large": {
    "file": "http://fox-box.co.uk/wp-content/uploads/frankenork_square_back-768x768.jpg",
    "width": 768,
    "height": 768,
    "mime-type": "image/jpeg"
    },
    "post-thumbnail": {
    "file": "http://fox-box.co.uk/wp-content/uploads/frankenork_square_back-980x110.jpg",
    "width": 980,
    "height": 110,
    "mime-type": "image/jpeg"
    },
    "shop_tiny": {
    "file": "http://fox-box.co.uk/wp-content/uploads/frankenork_square_back-36x36.jpg",
    "width": 36,
    "height": 36,
    "mime-type": "image/jpeg"
    },
    "shop_thumbnail": {
    "file": "http://fox-box.co.uk/wp-content/uploads/frankenork_square_back-90x90.jpg",
    "width": 90,
    "height": 90,
    "mime-type": "image/jpeg"
    },
    "shop_small": {
    "file": "http://fox-box.co.uk/wp-content/uploads/frankenork_square_back-150x150.jpg",
    "width": 150,
    "height": 150,
    "mime-type": "image/jpeg"
    },
    "shop_large": {
    "file": "http://fox-box.co.uk/wp-content/uploads/frankenork_square_back-300x300.jpg",
    "width": 300,
    "height": 300,
    "mime-type": "image/jpeg"
    },
    "admin_product_list": {
    "file": "http://fox-box.co.uk/wp-content/uploads/frankenork_square_back-32x32.jpg",
    "width": 32,
    "height": 32,
    "mime-type": "image/jpeg"
    }
    },
    "image_meta": {
    "aperture": "0",
    "credit": "",
    "camera": "",
    "caption": "",
    "created_timestamp": "0",
    "copyright": "",
    "focal_length": "0",
    "iso": "0",
    "shutter_speed": "0",
    "title": "",
    "orientation": "0",
    "keywords": [],
    }
    },
      {
    "width": 1500,
    "height": 860,
    "file": "http://fox-box.co.uk/wp-content/uploads/2016/10/frankenork_size_comparison_gw.jpg",
    "sizes": {
    "thumbnail": {
    "file": "http://fox-box.co.uk/wp-content/uploads/frankenork_size_comparison_gw-150x86.jpg",
    "width": 150,
    "height": 86,
    "mime-type": "image/jpeg"
    },
    "medium": {
    "file": "http://fox-box.co.uk/wp-content/uploads/frankenork_size_comparison_gw-250x143.jpg",
    "width": 250,
    "height": 143,
    "mime-type": "image/jpeg"
    },
    "medium_large": {
    "file": "http://fox-box.co.uk/wp-content/uploads/frankenork_size_comparison_gw-768x440.jpg",
    "width": 768,
    "height": 440,
    "mime-type": "image/jpeg"
    },
    "large": {
    "file": "http://fox-box.co.uk/wp-content/uploads/frankenork_size_comparison_gw-1024x587.jpg",
    "width": 1024,
    "height": 587,
    "mime-type": "image/jpeg"
    },
    "post-thumbnail": {
    "file": "http://fox-box.co.uk/wp-content/uploads/frankenork_size_comparison_gw-980x110.jpg",
    "width": 980,
    "height": 110,
    "mime-type": "image/jpeg"
    },
    "shop_tiny": {
    "file": "http://fox-box.co.uk/wp-content/uploads/frankenork_size_comparison_gw-36x21.jpg",
    "width": 36,
    "height": 21,
    "mime-type": "image/jpeg"
    },
    "shop_thumbnail": {
    "file": "http://fox-box.co.uk/wp-content/uploads/frankenork_size_comparison_gw-90x52.jpg",
    "width": 90,
    "height": 52,
    "mime-type": "image/jpeg"
    },
    "shop_small": {
    "file": "http://fox-box.co.uk/wp-content/uploads/frankenork_size_comparison_gw-150x86.jpg",
    "width": 150,
    "height": 86,
    "mime-type": "image/jpeg"
    },
    "shop_large": {
    "file": "http://fox-box.co.uk/wp-content/uploads/frankenork_size_comparison_gw-300x172.jpg",
    "width": 300,
    "height": 172,
    "mime-type": "image/jpeg"
    },
    "admin_product_list": {
    "file": "http://fox-box.co.uk/wp-content/uploads/frankenork_size_comparison_gw-32x18.jpg",
    "width": 32,
    "height": 18,
    "mime-type": "image/jpeg"
    }
    },
    "image_meta": {
    "aperture": "0",
    "credit": "",
    "camera": "",
    "caption": "",
    "created_timestamp": "0",
    "copyright": "",
    "focal_length": "0",
    "iso": "0",
    "shutter_speed": "0",
    "title": "",
    "orientation": "0",
    "keywords": [],
    }
    }
    ],
    },
    "categories": [
      {
    "id": 70,
    "name": "Fox Box",
    "slug": "fox-box",
    "link": "https://fox-box.co.uk/product-category/fox-box/"
    },
      {
    "id": 5,
    "name": "Greenskins",
    "slug": "orcs",
    "link": "https://fox-box.co.uk/product-category/orcs/"
    }
    ],
    "tags": [
      {
    "id": 86,
    "name": "Fox Box",
    "slug": "fox-box",
    "link": "https://fox-box.co.uk/product-tag/fox-box/"
    },
      {
    "id": 44,
    "name": "Orc",
    "slug": "orc",
    "link": "https://fox-box.co.uk/product-tag/orc/"
    },
      {
    "id": 31,
    "name": "Resin",
    "slug": "resin",
    "link": "https://fox-box.co.uk/product-tag/resin/"
    },
      {
    "id": 92,
    "name": "Special!",
    "slug": "special",
    "link": "https://fox-box.co.uk/product-tag/special/"
    }
    ],
    "link": "https://fox-box.co.uk/product/fox-box-frankenork/",
    "cross_sells": [],
    "up_sells": [],
    "regular_price": 5.99,
    "stock": {
    "manage": false,
    "status": 1,
    "allow_backorders": "no",
    "stock": 0
    },
    "sale": {
    "enabled": false,
    "price": "",
    "from": {
    "timestamp": 1493683200,
    "date": "2017-05-02"
    },
    "to": {
    "timestamp": 1493683200,
    "date": "2017-05-02"
    }
    }
    }
    }

    That should be enough to figure out the other bits of the API, I suspect.

    My only question now is – what’s the secret key for?!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Getting started with JigoShop’s API?’ is closed to new replies.