Question

Regarding attachments returned through API

  • 14 June 2022
  • 4 replies
  • 159 views

Hi Team,

I am using the search (https://api.getguru.com/api/v1/search/query?q=) and trying to fetch the attachments, however we see that, we are getting all the attachment information like images, and videos in the content field. We get a URL in the src field when we try to use that URL for file information, We get a 404 error.  Any pointers to fetch the attachment information from API ??


4 replies

Userlevel 3
Badge

Hi @SU Commerce! 👋

Thanks for the question!

You’re correct - when you use the /api/v1/search/query endpoint, you will see a field called src that will be present for any attachments in the card. The contents of that field should look like this:

https://content.api.getguru.com/files/view/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

To download the file in the link above, you’ll need to call it as an API endpoint with the GET method, still using your same Guru API credentials.

Let me know if this helps!

Joe

Hi @Joe Duffy , Thanks for the quick response. I tried that and I was able to get the contents of the attachment using a user token but I have two open queries.

  1. I was not able to get the content using the collection token, I got the status code as 200 but I got some HTML instead of the content of the attachment. is there any known limitation based on the token type.? 
  2. In some cases, I was able to get the link from <src> as you mentioned but in some of the cases, I was getting the link from <a> tag instead of <src>. Are there any criteria for this behavior?

 

Userlevel 3
Badge

Hi @SU Commerce!

You should be able to retrieve the same information using a collection token - can you confirm that you are passing in the collection ID (ex. xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx) as the username, and the collection Token as the password?

Additionally, we have two types of attachments: a file or an image. So you could be looking for the attachment url value from either an <a> anchor tag or <img> image tag.

  • For an anchor tag, the url will be in an href attribute.
  • For an image tag, the url will be in a src attribute.

Here’s a picture breaking down the two (the asterisk in the url will be a long id) and where to find those attributes from our html content, and comparing to a plain link.

Let me know if this helps!

My website is downloading a card attachment using the technique that Joe described above.

The card is downloaded using a GET with a URL of /cards/CardGUID/extented. This GET is successfully completed under a Collection Token.

My problem is the GET for the attachment fails using the same Collection Token, but it succeeds using a my User Token.

Does the GET for the attachment require more access than the GET for the Card?

Reply