Utilisation CURL et php, fonctionne plus depuis MAJ de API


je viens vers vous car j’utilise généralement CURL en PHP pour alimenté ma base de donnée, mais depuis la MAJ de l’API cela ne fonctionne plus et je ne sais pas trop comment résoudre le problème.

Je récupéré sur la page d’un design, l’id, le titre, les tag, la description et l’image.

jusqu’à présent j’utilise CURL en php pour alimenter ma base de donnée avec les infos des designs.

mais cela ne fonctionne plus.

pouvez vous m’aider ?

  $site_url = htmlspecialchars($_POST['url']);
  $user_agent = "Mozilla/5.0 (X11; Linux i686; rv:24.0) Gecko/20140319 Firefox/24.0 Iceweasel/24.4.0";
  $design = [];

  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $site_url);
  curl_setopt($ch, CURLOPT_USERAGENT,$user_agent);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  $resultat = curl_exec($ch);

Maybe you find this useful:

1 Like

tu parle français ?

thank you I will try I have a bad I do not speak English.

? > $ session = “XXXXX”; // replace with a valid session

I do not understand what I need meter here.

I can understand, but not writing it :wink:


Try ignoring that value. I think its not necessary.

J’ai un peut de mal car a chaque fois que cela ne fonctionne pas ça fait planté apache sur Linux, je doit redémarré a chaque essai.

Mais je vois pas comment adapter ton code, car je ne veux pas GET ou POST avec l’API mais je veux récupéré le code html d’une page comme celle ci par exemple “https://www.spreadshirt.fr/dj+hip+hop+mix-A13407398”.

Pour récupéré mes informations, Cela fonctionner très bien avant :frowning:

Comme on peut vendre des designs de tous les designs sur notre boutique, je navigue sur spreadshirt et des qu’un me plaît je l’ajoute a ma boutique avec un lien URL et non via un lien API.


I have a bit of trouble because every time it does not work it crashed apache on Linux, I must restart at each test.

But I do not see how to adapt your code, because I do not want GET or POST with the API but I want to get the html code of a page like this for example “https://www.spreadshirt.fr/dj+hip+hop+mix-A13407398

To retrieve my information, it will work fine before :frowning:

As we can sell designs of all the designs on our shop, I browse spreadshirt and as I like it I add it to my shop with a URL link and not via an API link.

Ok, so there is another much easier solution. You could simply request following url with valid session and user agent (GET request):


where as 13407398 is your article id.
Then you won’t need to parse that html code anymore and receive xml or json (if you like).

If you like, I can create and post some sample for you, but it takes some time, as I am busy at the moment.

Thank you for taking this time to help me I thought there was no dev on the forum :slight_smile: I’m happy.

In fact my site works with the id of design.

it allows me to open a page with my tabloid and the ‘designid’ parameter directly to my “clients”.

on my site in the administration I made sure to make an “input” with the url and it records in the BDD.

With the API link I could probably do it too, but how do I get an API link from a URL.

I think your workflow is same like https://www.shirtrecycler.de right? If you click on a design, you will be redirected to the page with the tablomat, right?

So why do you don’t need to read html then? Do you want to read all your designs to create that list of designs? That would be something like: https://api.spreadshirt.net/api/v1/shops/609238/designs?locale=fr_FR&fullData=true

Then you’ve got a list of designs with images. This would build your url to redirect to your tablomat page.

I think I have to create a wordpress plugin out of it, this would be much easier. This is what my wp-spreadplugin does, but with focus on products, not on designs.

Please let me know your website, so I can imagine your targets better.

So yes I could use more products than designs.

But I use the designs of several accounts (to me and to other seller) which complicates things.

I tested the wordpress system some time ago but it is necessary to create the designs on my speadshirt account and it is very very long, my system allowed me to add a lot of designs quickly without going through my account spreadshirt.

here is my site tshirtfamily.fr but yes it’s a can the same system that the site you give me.

After it is shame because all my site walk properly but now spreadshirt no longer allow CURL visited these pages.
Maybe there are not many things added to my code.

ps: it’s a site that I have completely developed myself ‘from scratch’.

basket creation was modified by spreadshirt too, it does not work anymore :frowning:

pff but they alter all

here you go - working sample, above.


You may missed some blog posts regarding security changes, right? Anyway, I can help you with that :wink:

Regarding Basket, you see this extensions I made to your code above? You may also do that with your basket code. Otherwise send it to me in a private message and I’ll change it for you, so it will work again.


$user_agent = 'test/1.0 (http://tshirtfamily.fr/; test@mail.de)';
ini_set('user_agent', $user_agent);


curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);

There is always a solution :slight_smile:

thank you for all your time and help !!! JI’m lucky you’re here.

I’m going to sleep my little girl and I have to go eat, I’ll wake up tomorrow.

Actually it is a problem of access for the basket with the new security of the API with your examples I should have arrived there.

and I will test the example given.

I will return tomorrow !

1 Like

hello love tee :slight_smile: so this morning I worked on the basket and thanks to your code on the site I managed to eliminate a lot of mistakes but I still have a problem and I do not understand why.


I can not add products to the basket I create

print_r at line 103 I have a return

HTTP/1.1 400 Bad Request Content-Type: application/xml Content-Length: 165 Server: nginx/9.5 Cache-Control: private, no-cache, no-store Date: Tue, 20 Mar 2018 11:26:21 GMT Connection: close Access-Control-Max-Age: 86400 Access-Control-Allow-Credentials: false Access-Control-Allow-Headers: X-PINGOTHER,Origin,X-Requested-With,Content-Type,Accept Access-Control-Allow-Methods: GET,POST,PUT,DELETE,OPTIONS Access-Control-Allow-Origin: * X-Robots-Tag: noindex, nofollow X-Application: other HTTP 400 Bad Request-00001

I do not use sessionID in spreadshirt functions, maybe that’s it. I tried but it did not work I put a random number because I did not understand what it was necessary to add.


I also tested the code for CURL to read the html but it did not work by adding the usér agent.


var_dump return FALSE

I had already tried this solution because I came across this page> https://www.spreadshirt.fr/blog/2017/12/21/api-changements/

it should work by adding at the top of the file.

$user_agent = 'test/1.0 (http://tshirtfamily.fr/; test@mail.de)';
ini_set('user_agent', $user_agent);

at // 7. Obtenir une URL de caisse you’re missing the user_agent.

curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);

Please add it there too.

Funny thing, yesterday it worked from home. I could only imagine, some config problems on my working machine and not on my home one or something changed @ sprd from yesterday till today.
Anyway I’ll test today evening and let you know. Beside of that, you may really switch to api getting designs. It’s a lot easier, reliable and is working great.
Here’s how to retrieve marketplace designs: https://pastebin.com/mwi8C2KE

Funny thing, yesterday it worked from home. I could only imagine, some config problems on my working machine and not on my home one or something changed @ sprd from yesterday till today.
Anyway I’ll test today evening and let you know. Beside of that, you may really switch to api getting designs. It’s a lot easier, reliable and is working great.
Here’s how to retrieve marketplace designs: https://pastebin.com/mwi8C2KE2
yes you’re right I could maybe use the api, I just watched it could have worked.

The small problem is that I could not add a design of other sellers.

The big problem is that I have multiple accounts and this system only works on old account no?

Please add it there too.

On line 3 and 97 (https://pastebin.com/X7LDsuhD) I already put what you said, I did not put “ini_set (‘user_agent’, $ user_agent);” so I added it.

in the same 7 without user_agent I get to have the basket url. I added it anyway but it did not change anything

I tried with my user_agent and then with yours user_agent but it does not work I always have the same error.

Well, I should have mentioned, I am requesting the eu marketplace with the given id. So there are all designs listed of all sellers - which are published to marketplace. This is independent of any old/new account problems!

Here’s what I said: https://pastebin.com/Tx7n9t3M :slight_smile:

Tested from home, not working anymore…

1 Like

All Europe lol it’s thousands of design that. :slight_smile: It will be hard to find those of my recent accounts inside.
I will look at this problem after, I have to get my basket to work first

Here’s what I said: https://pastebin.com/Tx7n9t3M

I misunderstood to talk about the “7” I test after, and I also try to copy / paste your code.

But I have the same mistake.

but for the “7” is the creation of the url of the basket and I have no problem that it creates me well.

but I can not add more products.

exemple : https://api.spreadshirt.net/api/v1/baskets/1b066874-61f9-4ea3-9b0d-09be8a9ab10c

good news my test


with the code of


that I adapt with the new security to the working area …

yet it’s the same thing there must be a very small problem.