Question

Newbie question doing my first API call - 403 response

  • 9 February 2024
  • 6 replies
  • 63 views

Badge +2

Hello all - I’m trying to get my development environment set up to build some desktop utilities to modify LucidChart documents. I’m attempting my first API call to the documents endpoint and getting a 403 response. Any help would be greatly appreciated - and sorry for the long post.

Here’s what I’ve done so far:

  • Created my document in LucidChart, so I am the owner of it. Grabbed the document ID from the URL (hopefully that’s the right one?)
  • In the Lucid Developer Portal, I created an application, created the OAuth 2.0 client, generated my client ID and Client secret, and registered the Lucid Test redirect URI using my client ID. 
  • I am using VS Code and Python, and have leveraged some of your sample code from the documentation to get the authentication and token refreshing working, storing the access token locally for use until expired. Seems to be working great so far!
  • Since I’m building against just the console right now, I temporarily have the script launch a web browser for the OAuth process, and then it waits for me to manually copy and paste the verification code from the redirect page back into my app prompt. (fancy fancy I know!)
  • I threw a bit of the kitchen sink in with the Scopes:
    "lucidchart.document.app lucidchart.document.content offline_access user.profile"

params = {
'response_type': 'code',
    'client_id': self.client_id,
    'scope': self.scopes,
    'redirect_uri': self.redirect_uri }
  • Now that I have an access token, here’s my attempt to get document information. This is where I’m receiving a 403 response.
def get_document(access_token, document_id):

# The API endpoint to get information about the LucidChart document
url = f'https://api.lucid.co/documents/{document_id}'

# Required headers
headers = {
'Authorization': f'Bearer {access_token}',
'Lucid-Api-Version': '1',
'Accept': 'application/json'}

# Make the GET request
response = requests.get(url, headers=headers)

# Check if the request was successful
if response.status_code == 200:
# Parse the response JSON and work with the data
document_data = response.json()
return document_data
else:
print(f'Failed to retrieve document data: {response.status_code}')
return None

Thanks in advance!

 

Matt


Comments

Userlevel 1
Badge

Hi Matt, thanks for taking interest in our APIs!

I tried running your get_document code using my own token and document and was able to get a successful response, so it looks like you’re making the request correctly. Something that could cause this error is if you are using the Lucidchart scopes with a Lucidspark document. Would you mind checking to see that your document_id matches a Lucidchart document or adding “lucidspark.document.content” to your list of scopes?

If that doesn’t work, we’re happy to take a deeper look.

Badge +2

Hi Trevor - thanks for responding and taking a look at this! I can confirm, however, that it is a LucidChart document I’m trying to access. Would appreciate very much if you have any other troubleshooting ideas.

 

Matt

Userlevel 1
Badge

Would you mind sharing your clientId and/or a documentId that you’ve performed the request on? We’ll search for your API requests to see specifically what went wrong.

Badge +2

Sure - thanks.

clientId: ftwUSAw8JXrR5OZIbagtBcKodzKVMMT9DOf-qG3O

documentId: 82770042-c88e-496d-bbc8-3814c9d836ab

Userlevel 1
Badge

We dug around a little on our end and couldn’t find anything obvious. Could we set up a call to walk through it together? You should expect an email that’ll let you schedule a time with my PM and myself.

Badge +2

That sounds great - I appreciate it. Just scheduled a meeting for later today.

 

Matt

Reply