GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Breaking API change 03/2024 - 404 Error · Issue #19 · foo-git/rewe-discounts

Breaking API change 03/2024 - 404 Error #19

New issue
Copy link
New issue
Copy link
Open
Open
Breaking API change 03/2024 - 404 Error#19
Copy link
Labels
bugSomething isn't workinghelp wantedExtra attention is needed

Description

@foo-git
foo-git
opened on Mar 30, 2024
Issue body actions

The new API introduced in v2.6 (#17, #18) seems to be broken due to a change by REWE, it now yields a 404 error:

Traceback (most recent call last):
File "[...]/rewe_discounts.py", line 294, in less_elegant_query
data = scraper.get(url).json()
^^^^^^^^^^^^^^^^^^^^^^^
File "[...]/venv/lib/python3.11/site-packages/requests/models.py", line 975, in json
raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: Extra data: line 1 column 5 (char 4)
FAIL: Unknown error while fetching discounts from https://www.rewe.de/api/all-stationary-offers/[...], maybe a typo or the server rejected the request.

Right now, I have no solution available and the script will not work. If you find the correct API url, please let me know.

Activity

Next
  1. foo-git
    added
    bugSomething isn't working
    help wantedExtra attention is needed
    on Mar 30, 2024
  2. knautschka commented on Mar 30, 2024

    @knautschka
    knautschka
    on Mar 30, 2024
    More actions

    Hi,
    with the linked discussion thread I found out what still works:
    You can build the link for the API with the market-id from local REWE stores.
    So for example https://shop.rewe.de/api/products/?search=&market=1766005 should work and list all products of the specific market in a JSON. (Of course you could add a search term as an addtion in the URL if you'd like).

    Also, a note: I'm not sure if they changed the market-ids in general. When I used your script I got a market-id back with even the right adress of the market etc., so I thought it was right, but it didn't work.
    So instead I went to the REWE website, set a local market there manually over the UI and the URL looked like this: https://www.rewe.de/marktseite/dortmund/1766005/rewe-dortmund-husenerstr-50/
    So I tried what I thought should be the id (1766005) in the URL and it actually worked. The JSON you get lists also the prices for the products, which was the feature I was looking for.

    Don't know if this will help you and if this is the solution you had in mind. But anyway I wanted to try to because your work here helped me anyway! Never had thought you could use the API of REWE just like that. Keep up the good work! :)

    Reacted by foo-git
  3. foo-git commented on Mar 30, 2024

    @foo-git
    foo-git
    on Mar 30, 2024
    OwnerAuthor
    More actions

    If I interpret the first link of yours correctly, it shows all products from the Rewe Lieferdienst, which is unfortunately not a list of current discounts. My Rewe store for "testing the script" yields a NO_HIT response, so the URL is not globally valid.

    Regarding the market-ids, I could not reproduce your finding, as running the script with the PLZ from your store yields the correct market-id. Did you use the correct PLZ?

    ./rewe_discounts.py --list-markets 44319
    ID Location
    1766005: Filips Einzelhandels KG, Husenerstr. 50, 44319 Dortmund
    562336: Carsten Engel e.K., Wickeder Hellweg 100 - 104, 44319 Dortmund
    320195: Filips Supermarkt GmbH & Co. KG, Asselner Hellweg 94, 44319 Dortmund

    So thanks for your much appreciated feedback, but it's not the solution yet :(

    Reacted by Tim
  4. knautschka commented on Mar 30, 2024

    @knautschka
    knautschka
    on Mar 30, 2024
    More actions

    About the market-ids: Sorry, you're right! I actually had a typo and didn't notice... :D

    You're right, unfortunely my link doesn't show the current discounts. I'll keep trying to find a way to get them! :)

  5. knautschka commented on Mar 30, 2024

    @knautschka
    knautschka
    on Mar 30, 2024
    More actions

    I might have found something that could lead to a solution:
    I looked manually over the UI and noticed that when you click on a product that is in discount (for example an item on https://www.rewe.de/angebote/dortmund/1766005/rewe-dortmund-husenerstr-50/?week=current), there is a request for a JSON for the product you clicked on that can be requestet with for example https://www.rewe.de/api/offer-details/15962993?wwIdent=1766005. The ending of the URL seems to be made of the product-id and the market-id.

    This might be a good start. Now we have to find out how all discounted products can be requestet at once.

    What I didn't find yet: At the overview of the discounted products I don't find such a request for the data although it kind of has to be there. So I don't know how to make the request yet.

    I will try it further but maybe someone else will be faster than me with the API-request I posted.

    Edit: Noticed that you mentioned the URL-scheme in the other issue topic. But maybe it's at least good to know that it still works.

  6. modelD-svg commented on Mar 31, 2024

    @modelD-svg
    modelD-svg
    on Mar 31, 2024
    More actions

    I've been using the API you call "less elegant" for some time now and found this issue today, looking into why it stopped working. From what I can tell, all APIs (both browser and mobile) are now using fully cloudflare'd, WAF'd and fingerprinted endpoints. If you're curious, the app uses mobile-clients-api.rewe.de/api/stationary-app-offers/<mid> with seemingly heavy fingerprinting of course.

    I've mostly given up on fighting cloudflare for projects that "just need to run", so I've gone back to just getting the raw html and parsing it with soup. This requires a vm and a sketchy ahk script, but I already have those things anyways and that has been working mostly well for similar projects for eons.

    Reacted by donbilbo4488 and Fabian Seitz
  7. foo-git commented on Apr 1, 2024

    @foo-git
    foo-git
    on Apr 1, 2024
    OwnerAuthor
    More actions

    Maybe the VM way is the way to go. Incidentally, for v1.0 I used selenium and soup to get and process the raw html. From v2.0 onwards I switched to the APIs.

    I'll check if the selenium approach still works (although it seriously inflates the dependencies). I can't give an estimation on the timeline, as I'm busy with other tasks at the moment.

  8. modelD-svg commented on Apr 1, 2024

    @modelD-svg
    modelD-svg
    on Apr 1, 2024
    More actions

    I suspect you will have issues with cloudflare using selenium aswell, but good luck nontheless.

    Reacted by foo-git
  9. huskycgn commented on Apr 6, 2024

    @huskycgn
    huskycgn
    on Apr 6, 2024
    More actions

    I've built something similar a few months ago - unfortuntately also stopped working. :(

  10. BabyIsh88 commented on May 25, 2024

    @BabyIsh88
    BabyIsh88
    on May 25, 2024
    More actions

    Addon not Working.

  11. torbenpfohl commented on Jun 15, 2024

    @torbenpfohl
    torbenpfohl
    on Jun 15, 2024
    More actions

    I took a look at the rewe app which uses these two endpoints:

    https://mobile-api.rewe.de/api/v3/market/search?search="zipcode" for getting market ids in the area.
    https://mobile-clients-api.rewe.de/api/stationary-app-offers/"market-id" for getting all offers for a market.

    You have to use the same headers that the app uses and you have to specify a certificate and private key (both are in the rewe.apk).
    With that I got a working version again.

    But since I'm not sure if you are allowed to distribute the certificate and private key I haven't made a pull request yet. (Maybe somebody has some insight into that issue.) For now I just added a description on how to get the private key and the certificate. (in my fork)

    Reacted by modelD-svg and Marius
    Reacted by reeno and foo-git
  12. modelD-svg commented on Jun 16, 2024

    @modelD-svg
    modelD-svg
    on Jun 16, 2024
    More actions

    I took a look at the rewe app which uses these two endpoints:

    https://mobile-api.rewe.de/api/v3/market/search?search="zipcode" for getting market ids in the area. https://mobile-clients-api.rewe.de/api/stationary-app-offers/"market-id" for getting all offers for a market.

    You have to use the same headers that the app uses and you have to specify a certificate and private key (both are in the rewe.apk). With that I got a working version again.

    But since I'm not sure if you are allowed to distribute the certificate and private key I haven't made a pull request yet. (Maybe somebody has some insight into that issue.) For now I just added a description on how to get the private key and the certificate. (in my fork)

    Very nice! May I ask how you debugged the issue?

  13. ByteSizedMarius commented on Jun 16, 2024

    @ByteSizedMarius
    ByteSizedMarius
    on Jun 16, 2024
    More actions

    Have confirmed that calling the api works using the certs. I started automating the process (both extracting the certificates but also extracting the password) described by @torbenpfohl in powershell as a learning excercise (currently trying to get a bit better at ps). It's currently quite messy but if anyones interested in beta-testing it, please let me know. Otherwise I will probably publish it at some point in june. Personally, I would advise against publishing the certificates

    Reacted by Torben
  14. torbenpfohl commented on Jun 16, 2024

    @torbenpfohl
    torbenpfohl
    on Jun 16, 2024
    More actions

    @modelD-svg
    Was a bit messy. Basically I decompiled the apk with jadx and looked around in the code (with jadx-gui). Searching for "Request", "GET" and so on. Renaming a lot of functions for clarity.
    At some point I learned about frida and started to hook some basic networking classes - like java.net.Socket and the Conscrypt functions - first to look at the arguments being passed and the return value, and than to look at the stacktrace.
    The stacktrace limited the class I had to look at further. And from those classes it became clearer and clearer what class prepared the GET-request.
    At last I hooked (with frida) a function in that class that was being called a lot and logged the class-parameters (url and headers).

    The certificate and private key I found while looking through the resources of the decompiled apk (decompiled with apktool); there I found the mtls_prod.pfx file which was password protected. But searching for mtls_prod in the source code gave only a few classes and in one of them was the password (as a integer-array).

    But all in all I took a lot of time and poking around in the source code + hooking a lot of functions. (was my first reverse engineering project though)

    @ByteSizedMarius
    Thank you for the assessment and for testing!
    I mostly use a Linux distro without Powershell. But I look forward to your script. Maybe I can adapt it for bash.

    Reacted by Marius and Peer
  15. 30 remaining items

  16. Bit-Barron commented on Aug 29, 2024

    @Bit-Barron
    Bit-Barron
    on Aug 29, 2024
    More actions

    Can you show what the curl request (with --verbose added) on your VPS prints out?

    do you know how to fix it?

  17. torbenpfohl commented on Aug 29, 2024

    @torbenpfohl
    torbenpfohl
    on Aug 29, 2024
    More actions

    Not sure, yet.
    nginx related
    among other things, ipv4 related
    This is what I found so far, so first thing you might try is using IPv4 (--ipv4).
    Maybe if that's not working try using http1.1 (--http1.1).

  18. Bit-Barron commented on Aug 29, 2024

    @Bit-Barron
    Bit-Barron
    on Aug 29, 2024
    More actions

    Not sure, yet. nginx related among other things, ipv4 related This is what I found so far, so first thing you might try is using IPv4 (--ipv4). Maybe if that's not working try using http1.1 (--http1.1).

    okay i will try that, thank you

  19. Bit-Barron commented on Aug 29, 2024

    @Bit-Barron
    Bit-Barron
    on Aug 29, 2024
    More actions

    Not sure, yet. nginx related among other things, ipv4 related This is what I found so far, so first thing you might try is using IPv4 (--ipv4). Maybe if that's not working try using http1.1 (--http1.1).

    but if its not working, are there other methods where i can host my py backend to use it?

  20. eikaramba commented on Aug 29, 2024

    @eikaramba
    eikaramba
    on Aug 29, 2024
    More actions

    update: ok i saw now that you are already able to fetch the API just not on the VPS, in that case ignore my comment

    not sure if it helps but i am able to fetch the products (in my forked heissePreise repo) via:

    // reweClient.js
    
    const https = require("https");
    const fs = require("fs");
    const crypto = require("crypto");
    const zlib = require("zlib");
    
    const FULL_CERT_FILE_PATH = "private.pem";
    const FULL_KEY_FILE_PATH = "private.key";
    const client_cert = fs.readFileSync(FULL_CERT_FILE_PATH);
    const client_key = fs.readFileSync(FULL_KEY_FILE_PATH);
    
    class ReweClient {
        constructor(marketId) {
            this.hostname = "mobile-clients-api.rewe.de";
            this.marketId = marketId;
        }
    
        async fetch(url) {
            // const url = `/api/stationary-app-offers/${marketId}${path}`;
            const options = this._getRequestOptions(url);
    
            return new Promise((resolve, reject) => {
                const req = https.request(options, (res) => {
                    let data = [];
    
                    res.on("data", (chunk) => {
                        data.push(chunk);
                    });
    
                    res.on("end", () => {
                        const buffer = Buffer.concat(data);
                        this._processResponse(buffer, res.headers, resolve, reject);
                    });
                });
    
                req.on("error", (error) => {
                    reject(error);
                });
    
                req.end();
            });
        }
    
        _getRequestOptions(url) {
            return {
                hostname: this.hostname,
                port: 443,
                path: url,
                method: "GET",
                cert: client_cert,
                key: client_key,
                headers: {
                    "user-agent": "REWE-Mobile-Client/3.17.1.32270 Android/11 Phone/Google_sdk_gphone_x86_64",
                    rdfa: crypto.randomUUID(),
                    "Correlation-Id": crypto.randomUUID(),
                    "rd-service-types": "PICKUP",
                    "x-rd-service-types": "PICKUP",
                    "rd-is-lsfk": "false",
                    "rd-customer-zip": "48149",
                    "rd-postcode": "48149",
                    "x-rd-customer-zip": "",
                    "rd-market-id": this.marketId,
                    "x-rd-market-id": "",
                    "a-b-test-groups": "productlist-citrusad",
                    Host: this.hostname,
                    Connection: "Keep-Alive",
                    "Accept-Encoding": "gzip",
                },
            };
        }
    
        _processResponse(buffer, headers, resolve, reject) {
            if (headers["content-encoding"] === "gzip") {
                zlib.gunzip(buffer, (err, decoded) => {
                    if (err) {
                        reject(new Error("Error decompressing data: " + err.message));
                        return;
                    }
                    this._parseAndResolve(decoded, resolve, reject);
                });
            } else {
                this._parseAndResolve(buffer, resolve, reject);
            }
        }
    
        _parseAndResolve(data, resolve, reject) {
            try {
                const jsonData = JSON.parse(data.toString());
                resolve(jsonData);
            } catch (e) {
                reject(new Error("Error parsing JSON: " + e.message));
            }
        }
    }
    module.exports = ReweClient;
    
    

    and then

    const client = new ReweClient(1940221);
    const firstPage = await client.fetch(`/api/products?query=*&page=${pageId++}&objectsPerPage=250`);
    
  21. Bit-Barron commented on Aug 29, 2024

    @Bit-Barron
    Bit-Barron
    on Aug 29, 2024
    More actions

    not sure if it helps but i am able to fetch the products (in my forked heissePreise repo) via:

    // reweClient.js
    
    const https = require("https");
    const fs = require("fs");
    const crypto = require("crypto");
    const zlib = require("zlib");
    
    const FULL_CERT_FILE_PATH = "private.pem";
    const FULL_KEY_FILE_PATH = "private.key";
    const client_cert = fs.readFileSync(FULL_CERT_FILE_PATH);
    const client_key = fs.readFileSync(FULL_KEY_FILE_PATH);
    
    class ReweClient {
        constructor(marketId) {
            this.hostname = "mobile-clients-api.rewe.de";
            this.marketId = marketId;
        }
    
        async fetch(url) {
            // const url = `/api/stationary-app-offers/${marketId}${path}`;
            const options = this._getRequestOptions(url);
    
            return new Promise((resolve, reject) => {
                const req = https.request(options, (res) => {
                    let data = [];
    
                    res.on("data", (chunk) => {
                        data.push(chunk);
                    });
    
                    res.on("end", () => {
                        const buffer = Buffer.concat(data);
                        this._processResponse(buffer, res.headers, resolve, reject);
                    });
                });
    
                req.on("error", (error) => {
                    reject(error);
                });
    
                req.end();
            });
        }
    
        _getRequestOptions(url) {
            return {
                hostname: this.hostname,
                port: 443,
                path: url,
                method: "GET",
                cert: client_cert,
                key: client_key,
                headers: {
                    "user-agent": "REWE-Mobile-Client/3.17.1.32270 Android/11 Phone/Google_sdk_gphone_x86_64",
                    rdfa: crypto.randomUUID(),
                    "Correlation-Id": crypto.randomUUID(),
                    "rd-service-types": "PICKUP",
                    "x-rd-service-types": "PICKUP",
                    "rd-is-lsfk": "false",
                    "rd-customer-zip": "48149",
                    "rd-postcode": "48149",
                    "x-rd-customer-zip": "",
                    "rd-market-id": this.marketId,
                    "x-rd-market-id": "",
                    "a-b-test-groups": "productlist-citrusad",
                    Host: this.hostname,
                    Connection: "Keep-Alive",
                    "Accept-Encoding": "gzip",
                },
            };
        }
    
        _processResponse(buffer, headers, resolve, reject) {
            if (headers["content-encoding"] === "gzip") {
                zlib.gunzip(buffer, (err, decoded) => {
                    if (err) {
                        reject(new Error("Error decompressing data: " + err.message));
                        return;
                    }
                    this._parseAndResolve(decoded, resolve, reject);
                });
            } else {
                this._parseAndResolve(buffer, resolve, reject);
            }
        }
    
        _parseAndResolve(data, resolve, reject) {
            try {
                const jsonData = JSON.parse(data.toString());
                resolve(jsonData);
            } catch (e) {
                reject(new Error("Error parsing JSON: " + e.message));
            }
        }
    }
    module.exports = ReweClient;
    

    and then const firstPage = await client.fetch(/api/products?query=*&page=${pageId++}&objectsPerPage=250);

    is the script hostet somewhere?

  22. eikaramba commented on Aug 29, 2024

    @eikaramba
    eikaramba
    on Aug 29, 2024
    More actions

    Yes it is hosted in a docker container on my local server fetching prices every day from my home I. but not on a cloud server environment if that is the question.

  23. ByteSizedMarius commented on Aug 29, 2024

    @ByteSizedMarius
    ByteSizedMarius
    on Aug 29, 2024
    More actions

    like exactly that code is working locally and on my vps not

    maybe check if the vps's IP is on a blacklist. https://mxtoolbox.com/blacklists.aspx

    if it's not the certificates (make sure its not the certificates somehow!) no idea

  24. torbenpfohl commented on Aug 29, 2024

    @torbenpfohl
    torbenpfohl
    on Aug 29, 2024
    More actions

    Not sure, yet. nginx related among other things, ipv4 related This is what I found so far, so first thing you might try is using IPv4 (--ipv4). Maybe if that's not working try using http1.1 (--http1.1).

    but if its not working, are there other methods where i can host my py backend to use it?

    Homeserver (e.g. raspberrypi) might be the way to go.. but honestly I have no experience.

    Adding to @ByteSizedMarius maybe check the route as well (traceroute mobile-clients-api.rewe.de). And try using a VPN (e.g. protonvpn has a free tier).

  25. angelognazzo commented on Jan 22, 2025

    @angelognazzo
    angelognazzo
    on Jan 22, 2025
    More actions

    Hi guys, I am trying these days to get the private.pem and private.key.txt from the app. Was following @torbenpfohl guide too (https://github.com/torbenpfohl/rewe-discounts/blob/main/how%20to%20get%20private.pem%20and%20private.key.txt) but seems like this is not working anymore, at least for me. Is anybody having issues nowadays?

  26. eikaramba commented on Jan 22, 2025

    @eikaramba
    eikaramba
    on Jan 22, 2025
    More actions

    yes it seems they changed the authentication and the key is not there anymore. at least i didn't find it.

    update: ahh i also downloaded the wrong apk, see answer below :P

  27. ByteSizedMarius commented on Jan 22, 2025

    @ByteSizedMarius
    ByteSizedMarius
    on Jan 22, 2025
    More actions

    Starting with Rewe v4, they changed to an xapk, which is differently packaged. Torbens guide is a little more difficult than it has to be, you can just unzip it.

    1. download rewe-4-0-x.xapk
    2. rename the file to rewe.zip
    3. open the zip and copy de.rewe.app.mobile.apk from the zip
    4. rename de.rewe.app.mobile.apk to de.rewe.app.mobile.zip
    5. open the zip. the certificate is in /res/raw

    Please note that when trying to download the apk from uptodown, you don't accidentally download the uptodown store-installer (which is the default download). They seem to have added a dark pattern in order to get you to install their store.

    Download the real apk by clicking on "all variants", then the version name. The apk should be around ~75mb, not 20mb.

    Please let me know if that works for you @angelognazzo

    I will update my repo later today too to reflect these changes

  28. angelognazzo commented on Jan 22, 2025

    @angelognazzo
    angelognazzo
    on Jan 22, 2025
    More actions

    Starting with Rewe v4, they changed to an xapk, which is differently packaged. Torbens guide is a little more difficult than it has to be, you can just unzip it.

    1. download rewe-4-0-x.xapk
    
    2. rename the file to rewe.zip
    
    3. open the zip and copy de.rewe.app.mobile.apk from the zip
    
    4. rename de.rewe.app.mobile.apk to de.rewe.app.mobile.zip
    
    5. open the zip. the certificate is in /res/raw
    

    Please note that when trying to download the apk from uptodown, you don't accidentally download the uptodown store-installer (which is the default download). They seem to have added a dark pattern in order to get you to install their store.

    Download the real apk by clicking on "all variants", then the version name. The apk should be around ~75mb, not 20mb.

    Please let me know if that works for you @angelognazzo

    I will update my repo later today too to reflect these changes

    Hi Marius, thanks so much, this works and helped a lot, I was not aware that I was downloading the wrong apk file from uptodown, now I managed to find the correct version and the certificate. Thanks!
    And very nice work with your Go repo, I will use the opportunity to study a bit more Go!

    Reacted by Marius
  29. ByteSizedMarius commented on Jan 22, 2025

    @ByteSizedMarius
    ByteSizedMarius
    on Jan 22, 2025
    More actions

    updated the repo, thanks for flagging. wouldn't have noticed any time soon :)

  30. ByteSizedMarius commented on Feb 7, 2026

    @ByteSizedMarius
    ByteSizedMarius
    on Feb 7, 2026
    More actions

    I now also have a python wrapper for the go project and all endpoints from the app known to me are supported for both languages; https://github.com/ByteSizedMarius/rewerse-engineering // https://pypi.org/project/rewerse/

    Reacted by foo-git
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402792 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.