Search code examples
autodesk-forgeautodesk-viewerautodeskautodesk-model-derivative

Autodesk forge - download pdf views error message: The requested resource does not exist


I have the following http get urn: https://developer.api.autodesk.com/modelderivative/v2/designdata/:urn/manifest/:derivativeUrn/signedcookies

with the following parameters:

urn: urn:adsk.wipprod:fs.file:*************?version=23

derivativeUrn: urn:adsk.viewing:fs.file:dXJuOmFkc2sud2lwcHJvZDpmcy5maWxlOnZmLkNTRmdGWWZqUlotRHV2cThEd3R3WFE_dmVyc2lvbj0yMw/output/Resource/Plano de planta/Planta Baja-Locales Comerciales 2287883/pdf/Planta Baja-Locales Comerciales.pdf

the endpoint docs: https://aps.autodesk.com/en/docs/model-derivative/v2/reference/http/urn-manifest-derivativeUrn-signedcookies-GET/

my code:

const { accessToken, urn } = req.body;
    const configADSK = {
      headers: {
        Authorization: `Bearer ${accessToken}`,
      },
    };
    //Get Manifest
    const response = await axios.get(
      `${baseUrl}/modelderivative/v2/designdata/${btoa(
        urn
      )
        .replace("/", "_")
        .replace("=", "")}/manifest`,
      configADSK
    );

let derivatives =
  response.data.derivatives[0].children; //the 0 is the main derivative, the index 1 comprise the thumbnails

//get 2d views
let pdfViews = derivatives.filter(
  (v) =>
    v.role == "2d" &&
    !!v.properties["Print Setting"]
);

//filter the thumbnails since they are also embedded here!!
let pdfDerivatives = pdfViews.map((v) =>
  v.children.find((d) => d.role == "pdf-page")
);
pdfDerivatives = pdfDerivatives.filter(
  (dv) => dv !== undefined
);

//revit version
const rvtVersion =
  response.data.derivatives[0].properties[
    "Document Information"
  ].RVTVersion;

//next step is to get the signedUrl!
let downloadUrls = [];
let options = {
  method: "GET",
  headers: {
    Authorization: "Bearer " + accessToken,
  },
};
for (const derivative of pdfDerivatives) {
  let url = `https://developer.api.autodesk.com/modelderivative/v2/designdata/${urn}/manifest/${derivative.urn}/signedcookies?useCdn=true`; //?useCdn=true`;

  let resp = await fetch(url, options);

  let respJSON = await resp.json();
  downloadUrls.push(respJSON);
}

res.json(downloadUrls);

when sending the request, the response return:

"developerMessage": "The requested resource does not exist.",
"moreInfo": "https://forge.autodesk.com/en/docs/oauth/v2/developers_guide/error_handling/",
"errorCode": ""

I've followed the instructions from this blog: https://aps.autodesk.com/blog/download-your-revit-2d-views-pdfs

My intuition tells me that it might be related with the space characters between the pdf file name such as in "Planta Baja-Locales Comerciales" So I also tried replacing space characters with "20%" symbols to represent empty spaces in url domains. However, this didn't fix the issue

Any other suggestion??


Solution

  • My bad, it turns out that I forgot to encode the urn as following:

      let url = 
      https://developer.api.autodesk.com/modelderivative/v2/designdata/${btoa(
        urn
      )
        .replace("/", "_")
        .replaceAll("=", "")}/manifest/${
        derivative.urn
      }/signedcookies;