vectorexpress-api icon indicating copy to clipboard operation
vectorexpress-api copied to clipboard

How to use API

Open datnguyen20007 opened this issue 1 year ago • 10 comments

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

datnguyen20007 avatar Mar 25 '24 07:03 datnguyen20007

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.

FrankSandqvist avatar Mar 25 '24 08:03 FrankSandqvist

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

datnguyen20007 avatar Mar 25 '24 11:03 datnguyen20007

@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.

FrankSandqvist avatar Mar 25 '24 17:03 FrankSandqvist

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 avatar Mar 26 '24 01:03 datnguyen20007

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.

datnguyen20007 avatar Mar 26 '24 03:03 datnguyen20007

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.

corrideat avatar Mar 27 '24 12:03 corrideat

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

datnguyen20007 avatar Mar 29 '24 02:03 datnguyen20007

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,

corrideat avatar Apr 02 '24 17:04 corrideat

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.

datnguyen20007 avatar Apr 04 '24 01:04 datnguyen20007

Can this do png/jpg/gif to swg?

tippyentertainment avatar Jan 06 '25 02:01 tippyentertainment