Angular 5 Mailwizz Service Integration

Bradley

New Member
I'm looking to get some help on creating an Angular 5 injectable service for MailWizz. Any help or direction would be appreciated. It appears I'm struggling most with the HttpHeaders that should be passed to make the lists request. Thanks!
 
@Bradley - To make your life easier, from Backend > Settings > API, disable the signature check ;)
Thanks! Did that... still having issues. I'll do some more research on my end. I get a 400 error with the following message "Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource."
 
@Bradley - You are doing cross-domain requests, this isn't a mailwizz thing but it's just how browser will reject such requests if they are done from different domains.
You need to add CORS headers in the server where mailwizz is installed, see https://enable-cors.org/server_apache.html
@twisted1919 - thank you. Got the CORS sorted. But, when I make a get request to add a subscriber, I t get status 200 ok, but the response is a form to complete and the entry doesn't go into the database. Here's the "network" debug information. Anyone have an idea of how to fix this?

    1. Request URL:
      https://app.mysticmailer.com/lists/qz9268x2cx6c0/subscribe?EMAIL=asdfasd@asdfasdf.com&FNAME=asdfasd
    2. Request Method:
      GET
    3. Status Code:
      200 OK
    4. Remote Address:
      104.219.248.189:443
    5. Referrer Policy:
      no-referrer-when-downgrade
  1. Response Headersview source
    1. Cache-Control:
      no-store, no-cache, must-revalidate, post-check=0, pre-check=0
    2. Connection:
      Keep-Alive
    3. Content-Encoding:
      gzip
    4. Content-Length:
      1440
    5. Content-Type:
      text/html; charset=UTF-8
    6. Date:
      Fri, 19 Jan 2018 18:52:17 GMT
    7. Expires:
      Thu, 19 Nov 1981 08:52:00 GMT
    8. Keep-Alive:
      timeout=5, max=100
    9. Pragma:
      no-cache
    10. Server:
      Apache
    11. Set-Cookie:
      mwsid=ii19ajrnenjrbb6659042vl3a6; path=/; HttpOnly
    12. Set-Cookie:
      csrf_token=eaa9181e7ea79ca6bb4c8efac3adc61dc9710480s%3A88%3A%22THlqSmRPRzFQNG9UeFNWUzJOTTF1cFdaaXJ0NXJxWUpVcy1ejK7IgopchJ-Os4O3oyrxqVbApRa3OIoKY6Wu1g%3D%3D%22%3B; path=/; httponly
    13. Vary:
      Accept-Encoding
    14. X-XSS-Protection:
      1; mode=block
  2. Request Headersview source
    1. Accept:
      application/json, text/plain, */*
    2. Accept-Encoding:
      gzip, deflate, br
    3. Accept-Language:
      en-US,en;q=0.9
    4. Connection:
      keep-alive
    5. Host:
      app.mysticmailer.com
    6. Origin:
      http://localhost:4200
    7. Referer:
      http://localhost:4200/get-info/4clDuzRWowhSu66vx3RSNrz3bYh1/1
    8. User-Agent:
      Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36
  3. Query String Parametersview sourceview URL encoded
    1. EMAIL:
      asdfasd@asdfasdf.com
    2. FNAME:
      asdfasd
 
@Bradley - You are doing:
Code:
[LIST=1]
[*]Request URL:
https://app.mysticmailer.com/lists/qz9268x2cx6c0/subscribe?EMAIL=asdfasd@asdfasdf.com&FNAME=asdfasd
[*]Request Method:
GET
[*]Status Code:
200 OK
[/LIST]
Which is not api usage. You are just requesting a page with some params and as you see accessing https://app.mysticmailer.com/lists/qz9268x2cx6c0/subscribe?EMAIL=asdfasd@asdfasdf.com&FNAME=asdfasd those params get translated in forms, so you still have to click the submit button to make a POST request and send those params.
Instead, why not simply do a post request to start with? Do it for the url https://app.mysticmailer.com/lists/qz9268x2cx6c0/subscribe and instead of sending query strings, send the params as POST variables.

Anyway, i highly suggest using the api if possible, is much more useful than doing blind post requests to variouls app pages ;)
 
Thank you! I had tried POST with no luck too. I’ll dig deeper into the API. I’m just having a hard time following it. Baby steps for this old fat guy. Thanks for the help!
 
@Bradley - if you hit any particular issue, please ask for help ;)
Now that you ask...

I'm committed to getting this API thing sorted out. I'm trying to make a GET call to the 'lists' endpoint (https://app.mysticmailer.com/api/lists) to get the lists for a particular user. So, I'm passing parameters for the privateKey, publicKey, page and per_page. I get a 400 error. I'm trying to read your examples that are written in php and translate them to Angular 5 and simply don't understand what I'm doing wrong.

(to the other users here) - anyone figure this out? If so, I could sure use some help! Also... after I get this figured out, I'll create an open source freely distributed MailWizzService (service) for anyone to use.
 
@Bradley - If you disable the signature check from Backend > Settings > Api, then please just send a GET request but add the X-MW-PUBLIC-KEY having the value set to the public key. And keep this in mind for all requests, to authenticate at mailwizz, without signature check, just send this header ;)
 
@Bradley - If you disable the signature check from Backend > Settings > Api, then please just send a GET request but add the X-MW-PUBLIC-KEY having the value set to the public key. And keep this in mind for all requests, to authenticate at mailwizz, without signature check, just send this header ;)
Brilliant! Thanks. Will work on it shortly
 
@twisted1919 - I feel like I'm close, but just can't seem to get the list of lists for the user account (my own). Below is the HTTP Request and headers from the "inspect" view in Chrome. I'm not sure if this gives you what you might need to tell me what I'm doing wrong. I've got the CORS sorted out and I've figured out how to pass the headers with the request. Still no success. Any insight is appreciated.

Inspect: Network

    1. Request URL:
      https://app.mysticmailer.com/api/index.php/lists?page=1&per_page=100
    2. Request Method:
      OPTIONS
    3. Status Code:
      400 Bad Request
    4. Remote Address:
      104.219.248.189:443
    5. Referrer Policy:
      no-referrer-when-downgrade
  1. Response Headersview source
    1. Access-Control-Allow-Origin:
      *
    2. Cache-Control:
      no-store, no-cache, must-revalidate, post-check=0, pre-check=0
    3. Connection:
      close
    4. Content-Type:
      application/json; charset=UTF-8
    5. Date:
      Fri, 16 Feb 2018 05:36:19 GMT
    6. Expires:
      Thu, 19 Nov 1981 08:52:00 GMT
    7. Pragma:
      no-cache
    8. Server:
      Apache
    9. Set-Cookie:
      PHPSESSID=597gnb4d5t6b6jgk6la9n4knq3; path=/
    10. Transfer-Encoding:
      chunked
  2. Request Headersview source
    1. Accept:
      */*
    2. Accept-Encoding:
      gzip, deflate, br
    3. Accept-Language:
      en-US,en;q=0.9
    4. Access-Control-Request-Headers:
      x-mw-public-key,x-mw-remote-addr,x-mw-signature,x-mw-timestamp
    5. Access-Control-Request-Method:
      GET
    6. Connection:
      keep-alive
    7. Host:
      app.mysticmailer.com
    8. Origin:
      http://localhost:4200
    9. User-Agent:
      Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36
  3. Query String Parametersview sourceview URL encoded
    1. page:
      1
    2. per_page:
      100
== HTTP Request ==
HttpRequest
{url: "https://app.mysticmailer.com/api/index.php/lists", body: null, reportProgress: false, withCredentials: false, responseType: "json", …}
body: null
headers: HttpHeadersheaders: Map(4)size: (...)__proto__: Map[[Entries]]: Array(4)0: {"x-mw-public-key" => Array(1)}key: "x-mw-public-key"value: ["222a50dbad64b237REMOVEDTOPROTECTACCOUNTacad0f339"]1: {"x-mw-remote-addr" => Array(1)}key: "x-mw-remote-addr"value: [""]2: {"x-mw-timestamp" => Array(1)}key: "x-mw-timestamp"value: ["1518759379535"]3: {"x-mw-signature" => Array(1)}key: "x-mw-signature"value: [""]length: 4lazyInit: nulllazyUpdate: nullnormalizedNames: Map(4)size: (...)__proto__: Map[[Entries]]: Array(4)0: {"x-mw-public-key" => "X-MW-PUBLIC-KEY"}key: "x-mw-public-key"value: "X-MW-PUBLIC-KEY"1: {"x-mw-remote-addr" => "X-MW-REMOTE-ADDR"}key: "x-mw-remote-addr"value: "X-MW-REMOTE-ADDR"2: {"x-mw-timestamp" => "X-MW-TIMESTAMP"}key: "x-mw-timestamp"value: "X-MW-TIMESTAMP"3: {"x-mw-signature" => "X-MW-SIGNATURE"}key: "x-mw-signature"value: "X-MW-SIGNATURE"length: 4__proto__: Objectmethod: "GET"params: HttpParams {updates: Array(2), cloneFrom: null, encoder: HttpUrlEncodingCodec, map: Map(2)}reportProgress: falseresponseType: "json"url: "https://app.mysticmailer.com/api/index.php/lists"urlWithParams: "https://app.mysticmailer.com/api/index.php/lists?page=1&per_page=100"withCredentials: false__proto__: Object
 
Back
Top