Ergebnis 1 bis 8 von 8

Thema: Coding help needed - image uploads through API are failing

  1. #1
    Veteran Spreadster
    Registriert seit
    06.09.2012
    Beiträge
    90

    Standard Coding help needed - image uploads through API are failing

    We've been desperately seeking for help with this issue since February ... Where can we get API support ? We reported this issue a couple of times but never got any answer

    Since a couple of years we've been using a PHP app to mass upload images to our Spreadshirt account. It has been working perfectly until 2017, something seems to have changed on API side and now we can't upload images anymore.

    Please review the code we are using below, it is based on demos provided by Spreadshirt so it should be working.
    Just replace $session with a valid session ID to test the code, and set the API key and secret (or PM me to get my config)

    Code:
     <?php
    
    $session = "xxxxxxxxx"; // replace with a valid session
    $apiKey = "xxxxxxxx";
    $secret = "xxxxxxxxx";
    
    define('SHOP_ID', '');
    define('USER_ID', '790117');
    define('SPREADSHIRT_API_KEY', $apiKey);
    define('SPREADSHIRT_API_SECRET', $secret);
    define('SESSION_ID', $session);
    
     $requestfile = "design.png";
    
    // 1. Create design entity via data api
    $url = "http://api.spreadshirt.com/api/v1/users/" . USER_ID . "/designs";
    $header = array();
    $header[] = createSprdAuthHeader("POST", $url);
    $header[] = "Content-Type: application/xml";
    
    $xml = getFileData("design_xml.php");
    
    // Initialize handle and set options
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HEADER, true);
    $result = curl_exec($ch);
    // Close the handle
    curl_close($ch);
    
    echo $result . '<br />';
    
    $dataUrl = parseHttpHeaders($result, "Location");
    echo "Design URL: $dataUrl<br />";
    
    // 2. Fetch design data to retrieve upload url
    $header = array();
    $header[] = createSprdAuthHeader("GET", $dataUrl);
    $header[] = "Content-Type: application/xml";
    
    $ch = curl_init($dataUrl);
    curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
    $result = curl_exec($ch);
    // Close the handle
    curl_close($ch);
    
    $designXml = simplexml_load_string($result);
    $imageUrl = $designXml->resources->resource[0]->attributes('xlink', TRUE);
    echo "Image URL: " . $imageUrl . "<br />";
    
    // 3. Upload design data via image API
    $imageData = getFileData($requestfile);
    
    $header = array();
    $header[] = createSprdAuthHeader("PUT", $imageUrl);
    //$header[] = "Content-Type: image/svg+xml";
    
    $ch = curl_init($imageUrl . "?mediaType=png&method=PUT");
    curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $imageData);
    curl_setopt($ch, CURLOPT_HEADER, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $result = curl_exec($ch);
    curl_close($ch);
    
    function createSprdAuthHeader($method, $url) {
        $apiKey = SPREADSHIRT_API_KEY;
        $secret = SPREADSHIRT_API_SECRET;
        $session = SESSION_ID;
        $time = time() * 1000;
    
        $data = "$method $url $time";
        $sig = sha1("$data $secret");
    
        return "Authorization: SprdAuth apiKey=\"$apiKey\", data=\"$data\", sig=\"$sig\", sessionId=\"$session\"";
    }
    
    function parseHttpHeaders($header, $headername) {
        $retVal = array();
        $fields = explode("\r\n", preg_replace('/\x0D\x0A[\x09\x20]+/', ' ', $header));
        foreach ($fields as $field) {
            if (preg_match('/(' . $headername . '): (.+)/m', $field, $match)) {
                return $match[2];
            }
        }
        return $retVal;
    }
    
    function getFileData($file) {
        $currentWebDir = substr(__DIR__, strlen($_SERVER['DOCUMENT_ROOT']));
        $fp = file_get_contents("https://".$_SERVER['SERVER_NAME'] . $currentWebDir . "/" . $file, "r");
        return $fp;
    }
    
    ?>


    file #2 - design_xml.php
    Code:
    <?php
     $requestfile = "design.png";
    
    header ("Content-Type:text/xml");
    
    
    echo "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>
    <design xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns=\"http://api.spreadshirt.net\">
    <name>".getcwd()."/$requestfile</name>
    <description>$requestfile</description>
    </design>";
    
    ?>

    When upload_design.php is executed the app will upload "design.php" through Spreadshirt API. Then Spreadshirt API still returns a confirmation that the design was successfully uploaded even if it failed (weird), but it doesn't show in our user account like it used to do.

    Here's the result returned by the API

    HTTP/1.1 201 Created Content-Type: application/xml;charset=utf-8 Location: http://api.spreadshirt.com/api/v1/us...gns/1012106447 Content-Length: 240 Server: nginx/9.5 Cache-Control: private, max-age=7158 Date: Fri, 11 Aug 2017 01:35:57 GMT Connection: keep-alive X-Robots-Tag: noindex, nofollow X-Application: other X-DNS-Prefetch-Control: on
    Design URL: http://api.spreadshirt.com/api/v1/us...gns/1012106447
    Image URL: http://image.spreadshirtmedia.com/im...gns/1012106447
    However, the image URL returned by the API is broken - when trying to display the image, Spreadshirt server will return this error:
    Sorry, the server encountered an internal error that prevent it from fulfilling this request!
    Reason: unknown
    Here's a ZIP file ready to use if you want to reproduce the problem on your end (add a valid session, key & secret to upload_design.php) - download here: https://www.mediafire.com/file/4dtxd...shirt_test.zip

    We really need help on this. We're working on a new big shop and we really need this API feature for our project. Please advise where can we get API support


  2. #2
    Grand Spreader Elite Spreadster Avatar von lovetee
    Registriert seit
    10.03.2012
    Beiträge
    1.174

    Standard

    You may try spreadshirt tablomat (http://spreadshirt.github.io/apps/tablomat) or open up a designer shop (https://www.spreadshirt.com/userarea...shop-dashboard) in your Spreadshirt Partner area. This is the safest way.

    We love t-shirts!

    Shops: http://lovetee.de/ / http://www.alsterwasser-fisch.com/

    ----------------------------------------------------------------------
    NEU! Productor v2.2.0 - Lade deine Designs hoch, erstelle in sekundenschnelle hunderte neuer Produkte, übersetze sie automatisiert und füge sie dem Marktplatz hinzu! Sieh selbst was der Vorgänger bereits konnte: https://youtu.be/9VD40vyTT_k.
    Teste es doch mit unserem Testaccount!
    ----------------------------------------------------------------------

    Freies Wordpress Plugin mit Spreadshirts API: https://wordpress.org/plugins/wp-spreadplugin/ / Hilfe: http://forum.spreadshirt.net/threads...rdpress-plugin

    Wordpress Webseiten Templates: http://themeforest.net/category/wordpress?ref=thimo

  3. #3
    Veteran Spreadster
    Registriert seit
    06.09.2012
    Beiträge
    90

    Standard

    We're using this code in a backend app to batch upload multiple designs to our Spreadshirt partner account using PHP + Spreadshirt API. Unfortunately neither tablomat or a designer shop will help with this...

    This is supposed to be possible using Spreadshirt API. See here:
    Uploading Designs to Spreadshirt using Spreadshirt API v1
    https://developer.spreadshirt.net/di...shirtAPIv1-PHP
    and also here:
    https://github.com/spreadshirt/sprea...signupload.php

    The code in my original post is taken from this official documentation... but apparently Spreadshirt dropped support for design upload through API, which could be used as a very efficient time-saver tool to automate batch upload of large designs quantities

    Geändert von anarchoi (12.08.2017 um 01:47 Uhr)

  4. #4
    Grand Spreader Elite Spreadster Avatar von lovetee
    Registriert seit
    10.03.2012
    Beiträge
    1.174

    Standard

    Well, I know that documentation thing and I know from my own dev. work, it's sometimes hard to maintain code and documentation.

    Why they dropped it? It should be security concerns. Dropping it for public means more control and security for our designs and to keep out copycats. It's a walk along a razor's edge between having security and features.

    My response may differ from Spreadshirt ones, but I can only say, please switch to the new partner area or create a new account to have it. This new partner area, you may already heard of in blogs and so on, should safe you a lot of time, batch uploading, creating and translating products and designs.

    We love t-shirts!

    Shops: http://lovetee.de/ / http://www.alsterwasser-fisch.com/

    ----------------------------------------------------------------------
    NEU! Productor v2.2.0 - Lade deine Designs hoch, erstelle in sekundenschnelle hunderte neuer Produkte, übersetze sie automatisiert und füge sie dem Marktplatz hinzu! Sieh selbst was der Vorgänger bereits konnte: https://youtu.be/9VD40vyTT_k.
    Teste es doch mit unserem Testaccount!
    ----------------------------------------------------------------------

    Freies Wordpress Plugin mit Spreadshirts API: https://wordpress.org/plugins/wp-spreadplugin/ / Hilfe: http://forum.spreadshirt.net/threads...rdpress-plugin

    Wordpress Webseiten Templates: http://themeforest.net/category/wordpress?ref=thimo

  5. #5
    Veteran Spreadster
    Registriert seit
    06.09.2012
    Beiträge
    90

    Standard

    Thanks for the reply,

    My response may differ from Spreadshirt ones, but I can only say, please switch to the new partner area or create a new account to have it. This new partner area, you may already heard of in blogs and so on, should safe you a lot of time, batch uploading, creating and translating products and designs.
    The new features in the partner are are very interesting indeed, but the problem is that we've been told the new partner area isn't compatible at all with any API features, and since we use the API to do everything on our website it would break our platform. We're running a cooperative platform using API for a multitude of important features, so it is vital for our business model. We never used the default SpreadShop at all, we import the products from API then display it on our website and use Spreadshirt.com just for secure checkout. Due to these reason, upgrading to the new partner area isn't an option until Spreadshirt 100% supports the API

    I am aware of possible dev complications, however API features such as uploading designs and creating products worked perfectly from 2010 to 2016 so i don't understand why they phased it out. If it is due to security concerns, it could still be an option to enable specific API features just for select partners (just like they are doing with the fulfillment service). Some partners have very specific needs and have the sales count that justify the need for Spreadshirt to invest into fixing their API. During the past it has been proven to be a very successful tool that allowed partners to bring significant amount of sales to Spreadshirt, it's very disappointing to see how it has recently been abandoned by Spreadshirt and very worrying about the future.

    Our shops currently have over 56,000 products and the vast majority of them were created automatically using the API. Our custom system allows us to upload designs and then automate the process of creating 11 products for each designs. We definitely do not have the ressources to do this time-consuming process manually so we're 100% dependent on API for our business model.

    Again, the API is the #1 reason we're staying with Spreadshirt. We can't stress enough about the importance of this for our business and Spreadshirt's business. We really hope our comments will be heard by Spreadshirt's management as it is really hard to get in touch with the staff since there are no more "account managers".


  6. #6
    Grand Spreader Elite Spreadster Avatar von lovetee
    Registriert seit
    10.03.2012
    Beiträge
    1.174

    Standard

    Thats the last time, I post solutions for free here.

    Your sample, working again:
    https://pastebin.com/erK97gPG

    Sample with svg only:
    https://pastebin.com/jiz7J9u0

    p.s. It's not my coding style - just quick changes to have the basic sample running.

    Geändert von lovetee (13.08.2017 um 09:45 Uhr)
    We love t-shirts!

    Shops: http://lovetee.de/ / http://www.alsterwasser-fisch.com/

    ----------------------------------------------------------------------
    NEU! Productor v2.2.0 - Lade deine Designs hoch, erstelle in sekundenschnelle hunderte neuer Produkte, übersetze sie automatisiert und füge sie dem Marktplatz hinzu! Sieh selbst was der Vorgänger bereits konnte: https://youtu.be/9VD40vyTT_k.
    Teste es doch mit unserem Testaccount!
    ----------------------------------------------------------------------

    Freies Wordpress Plugin mit Spreadshirts API: https://wordpress.org/plugins/wp-spreadplugin/ / Hilfe: http://forum.spreadshirt.net/threads...rdpress-plugin

    Wordpress Webseiten Templates: http://themeforest.net/category/wordpress?ref=thimo

  7. #7
    Veteran Spreadster
    Registriert seit
    06.09.2012
    Beiträge
    90

    Standard

    Wow, thank you so much for this ! I'm not asking you to work for free, you can PM me your Paypal account and we can pay for your time

    However i'm a bit confused, i thought we just came to the conclusion that these features were not supported by the API anymore ? If you could share where you get your information, the next time we could look it up ourselves instead of asking for solutions on the forum. We did try to solve the problem ourselves before coming here, but the documentation is outdated and nobody at Spreadshirt could answer our questions. A mailing list or changelog for the API would be really useful, so we can be warned when a major change is introduced...

    Any idea if this method is compatible with the new user area ? Or just the classic version ?

    Thanks again


  8. #8
    Grand Spreader Elite Spreadster Avatar von lovetee
    Registriert seit
    10.03.2012
    Beiträge
    1.174

    Standard

    I thought it was just activated for me, but I was wrong and here you are.

    From my latest tests...
    Upload: classic and new
    Product creation: classic only

    No mailing lists or updated docs, yes, some of us - third party developers have already requested it, but without any luck.

    -
    Thimo


Lesezeichen

Berechtigungen

  • Neue Themen erstellen: Nein
  • Themen beantworten: Nein
  • Anhänge hochladen: Nein
  • Beiträge bearbeiten: Nein