error 403 url shortener with bitly and js

885 views Asked by At

I have searched for the answer but nothing helped. Please suggest me with a solution, when I try to shorten the url with bitly and vue js I get 403 error.

axios api:

const headers = {
        'Authorization': `Bearer ${myToken}`,
        "Access-Control-Allow-Origin": "*",
        "Content-Type": "application/json",
        'Access-Control-Allow-Credentials':true
      };
      const dataString =
        '{ "long_url": "https://dev.bitly.com", "domain": "bit.ly", "group_guid": "Ba1bc23dE4F" }';
      axios
        .post("https://api-ssl.bitly.com/v4/shorten", {
          headers: headers,
          body: dataString,
        })
        .then(function (response) {
          if (response.status == 200) {
            console.log(response);
          } else {
            console.log("Opps dude, status code != 200 :( ");
          }
        })
        .catch(function (error) {
          console.log("Error! " + error);
        });

I have changed code according proposal in the comments. But the same 403 error. enter image description here

1

There are 1 answers

1
Šarūnas Lekstutis On

I have just received bitly support email that it is not working because I use group_id. "... "Ba1bc23dE4F" is a placeholder value in our documentation to show where your group GUID would be passed if you have an account with multiple groups. In your case, you can remove this whole value and simply pass a body with: { "long_url": "https://dev.bitly.com", "domain": "bit.ly" }"