0

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

  • its either, myToken is not defined or it doesn't like JSON.stringify (that's done by the lib) – Lawrence Cherone Feb 18 '22 at 15:19
  • I changed JSON.stringify but the same. Token is mentioned in my code above, but it's not copied here. Btw, I wrote vue js because I am doing this project with it - changed now to js in the title. – Šarūnas Lekstutis Feb 19 '22 at 09:11
  • 1
    Error 403 indicates that eventhough your authorization is valid, your account is not allowed to do that particular operation or access that particular resource. What is that `group_guid`? You seem to have copied this literally from the api docs? Maybe you need to replace that guid with some id from your own account? – derpirscher Feb 19 '22 at 09:22

1 Answers1

1

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" }"