Error 403 Forbidden


(Ibean1996) #1

im using the data api to upload my model by using my api token,but when i run the application it throws the Error 403 forbidden.i dont konw where is wrong or the api has problem?How could i make it?

Have a good day



Can you please share your script? Thanks!

(Ibean1996) #3

import org.glassfish.jersey.client.ClientConfig;

 * cn.fserve.controller
 * @author 
 * @date 2018/4/12
public class SketchfabUploadController {

public SketchfabUploadController() {

public static void main(String[] args) {
 * Model Upload
 * Implementation Notes
 * Uploads a new model. Accepts multipart/form-data only.
String token = "my api token";

//Setting up client parameters
ClientConfig config = new ClientConfig();

//becarefull with timeout during large model file upload and your connection speed"jersey.config.client.connectTimeout", 5000);"jersey.config.client.readTimeout", 50000);

Client client = ClientBuilder.newClient(config);

WebTarget webTarget ="").path("/models");

FormDataMultiPart uploadModelMultipart = new FormDataMultiPart();
uploadModelMultipart.field("name", "Java Test1", MediaType.TEXT_PLAIN_TYPE);
//pro only
uploadModelMultipart.field("private", Boolean.TRUE, MediaType.TEXT_PLAIN_TYPE);
//pro only
uploadModelMultipart.field("password", "", MediaType.TEXT_PLAIN_TYPE);
//optional - default TRUE
uploadModelMultipart.field("isPublished", Boolean.TRUE, MediaType.TEXT_PLAIN_TYPE);
//optional - default FALSE
uploadModelMultipart.field("isInspectable", Boolean.FALSE, MediaType.TEXT_PLAIN_TYPE);
//limit of 1024 characters
uploadModelMultipart.field("description", "Model description", MediaType.TEXT_PLAIN_TYPE);

//you can specify extra informations like
//just follow the example above, always using "MediaType.TEXT_PLAIN_TYPE"

//For create body parts that contains a file attachments we will need to use "FileDataBodyPart" class
//model path on your local storage
String filePath3D = "F://test.fbx";

File modelFile = new File(filePath3D);
FileDataBodyPart modelFilePart = new FileDataBodyPart("modelFile", modelFile);

//attaching our "modelFilePart" to the request body

//Setting up our Token to request header
//if we don't, response will be "NotAuthorizedException"
Builder builder = webTarget.request(MediaType.APPLICATION_JSON_TYPE)
        .header("Authorization", "Token " + token);

try {
    //For a correct response of an object representation of JSON, we will use "jersey-media-json-jackson"
    SketchfabUploadModelResponse sketchfabUploadModelResponse =, MediaType.MULTIPART_FORM_DATA), SketchfabUploadModelResponse.class);

    System.out.println("Upload sucess!!! " + sketchfabUploadModelResponse.getUid() + " (" + sketchfabUploadModelResponse.getUri() + ")");
} catch (NotAuthorizedException ex) {
    //call not authorized, possible TOKEN problem
    System.out.println("Invalid Token -> " + token);
} catch (BadRequestException ex) {
    //bad parameters
    //remember that are some limitations on different plans of Sketchfab API
    //Model size
    //Basic - 50MB per upload
    //Pro - 200MB per upload
    //Business - 500MB per upload
    System.out.println("bad parameters");


//Inner class helper on JSON response convert
class SketchfabUploadModelResponse {

private String uid;

private String uri;

public SketchfabUploadModelResponse() {

public String getUid() {
    return uid;

public void setUid(String uid) {
    this.uid = uid;

public String getUri() {
    return uri;

public void setUri(String uri) {
    this.uri = uri;

This is my code by java and i hide my token then run it ,the console get the expection

Exception in thread "main" HTTP 403 Forbidden
	at org.glassfish.jersey.client.JerseyInvocation.convertToException(
	at org.glassfish.jersey.client.JerseyInvocation.translate(
	at org.glassfish.jersey.client.JerseyInvocation.access$700(
	at org.glassfish.jersey.client.JerseyInvocation$
	at org.glassfish.jersey.internal.Errors.process(
	at org.glassfish.jersey.internal.Errors.process(
	at org.glassfish.jersey.internal.Errors.process(
	at org.glassfish.jersey.process.internal.RequestScope.runInScope(
	at org.glassfish.jersey.client.JerseyInvocation.invoke(
	at org.glassfish.jersey.client.JerseyInvocation$Builder.method(
	at org.glassfish.jersey.client.JerseyInvocation$
	at cn.fserve.controller.SketchfabUploadController.main(

(Ibean1996) #4

I have solved this problem because I have less references to a dependency and the network times out. Thank you for your answer.Have fun!


Cool, glad you figured it out!