Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use API #10

Open
datnguyen20007 opened this issue Mar 25, 2024 · 9 comments
Open

How to use API #10

datnguyen20007 opened this issue Mar 25, 2024 · 9 comments

Comments

@datnguyen20007
Copy link

Dear Vector Express,
Could you please write more detail about the API to call with full link to API?
I want to buy but I don't know how to use your API by python language.
Thank you very much

@FrankSandqvist
Copy link
Contributor

Hi,

Which endpoint are you having an issue with, specifically?

You can find information about how to do conversions in the README. Though, we're happy to help if you have a specific question.

@datnguyen20007
Copy link
Author

Can you give me the example code to call API by python please?
I see the readme file, but I don't know which part, information to use like credential, ID, password ...
Thank you so much

@FrankSandqvist
Copy link
Contributor

@datnguyen20007 You can try this (example of dxf -> svg)

import requests

headers = {
    'Content-Type': 'application/x-www-form-urlencoded',
}

# this being the path to the file you wish to convert
with open('myvector.dxf', 'rb') as f:
    data = f.read()

# this should get you a JSON response with a download URL
response = requests.post('https://vector.express/api/v2/public/convert/dxf/cadlib/svg/', headers=headers, data=data)

...and to download your file:

# Use the URL you received earlier
response = requests.get('https://vector.express/api/v2/public/files/[id].svg')

with open('converted.svg', 'wb') as f:
    f.write(response.content)

If you have subscribed, and need help with the metered endpoints, @corrideat should be able to help you out.

@datnguyen20007
Copy link
Author

Dear @FrankSandqvist
Thank you very much for your code.
From your code, this is what I know about the process
Firstly, to call API
API = "https://vector.express/api/v2/public/convert/dxf/cadlib/svg/"
as I analyze, API has some parts:

  1. Common part = "https://vector.express/api/v2/public/convert/"
  2. Input format = "dxf"
  3. Lib to convert = "cadlib"
  4. Output format = "SVG"

Secondly, save the file
Link to download = "https://vector.express/api/v2/public/files/[id].svg"
where [id] is a field in the variable "response" in the First part.

After I test it well, I will discuss about the price.
As I see, the price is

  • 14.95 USD / month => first 500 successful conversion.
  • after that, 01 cent / success file.
    Is this correct ?
    I feel the price is so good.

I want to convert SVG to PLT and .CUT to let the cutting machine to cut the paper.
Can you convert PLT or SVG to .CUT format please?

@datnguyen20007
Copy link
Author

Dear @corrideat Could you help me please?
I use this code

import requests

headers = {
'Content-Type': 'application/x-www-form-urlencoded',
}

this being the path to the file you wish to convert

with open('myvector.dxf', 'rb') as f:
data = f.read()

this should get you a JSON response with a download URL

response = requests.post('https://vector.express/api/v2/public/convert/dxf/cadlib/svg/', headers=headers, data=data)
print(response)

and I got the result:
<Response [201]>

then I use code
response = requests.get('https://vector.express/api/v2/public/files/201.svg')

with open('converted.svg', 'wb') as f:
f.write(response.content)

and get an empty file SVG.

Can you explain me more please?
Thank you for your time.

@corrideat
Copy link
Member

corrideat commented Mar 27, 2024

Hi @datnguyen20007,

The issue you seem to have is that you're using 201 as the result file, but that isn't the ID @FrankSandqvist was talking about (how you get the correct ID was missing; 201 is the HTTP status code). This is a more complete example:

import requests

headers = {
    'Content-Type': 'application/octet-stream',
}

# this being the path to the file you wish to convert
with open('myvector.dxf', 'rb') as f:
    data = f.read()

# this should get you a JSON response with a download URL
response = requests.post('https://vector.express/api/v2/public/convert/dxf/cadlib/svg/', headers=headers, data=data)

# Just for debugging purposes.
# For production use, you also need to check if the HTTP status code was a
# success response or not.
print(response.json())

# this is the result of the conversion, which you need to download
result = response.json()['resultUrl']

# Use the URL you received earlier
response = requests.get(result)

with open('converted.svg', 'wb') as f:
    f.write(response.content)

I hope that that helps.

ETA: Although we don't currently have a Python SDK, you can take a look at our TypeScript SDK to get an idea of how things work if you need an example implementation.

@datnguyen20007
Copy link
Author

Dear @corrideat ,
After using your code, I can convert the DXF to SVG 👍
But the problem:

  1. Image size is too small, width="89px" height="78px"
  2. Lose the text inside the file

Later, I try to convert PLT to SVG by this endpoint
https://vector.express/api/v2/public/convert/plt/uniconvertor/svg/

Then I got this error.
{'error': {'message': 'An error occurred during conversion', 'chainId': 'b9633a5c-d0e3-4f29-bb59-6562e8a53df4', 'program': 'uniconvertor', 'inputFormat': 'plt', 'outputFormat': 'svg'}}

Could you please help me with those problems ?
A. DXF to SVG, maybe I need to change the setting ?
B. PLT to SVG, What should I do ?

Thank you very much

@corrideat
Copy link
Member

Hi,

Regarding the issue with Uniconvertor: unfortunately it's, in my experience, not very reliable, and because of this we were considering dropping support. It's still included because, when it works, it supports a range wide of files.

Note that we support chaining convertors, so most of the time this is not an issue.

Regarding the second problem, can you please provide an example file that triggers the issue?

Thanks,

@datnguyen20007
Copy link
Author

sample vt express.zip

Dear @corrideat ,

Could you please check those files (plt, dxf) ? and try to convert to SVG at the correct size.
Please share your knowledge on plt file because the problem as I see

  • PLT file is measure in cm or milimet to print exactly.
  • SVG file is in pixel and can scale those vectors to the size that we want.
    Later, I will merge SVG files into a big SVG file.
    Finally, I will convert big SVG file to plt and print it.
    So the problem of image size is important here.

Thank you very much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants