chatnsign-alexandre | Posts: 4

[Solved] Package Add Document - 406 Not Allowed

0 votes

Hi,

  I'm trying to send an extra document to an existing package (with no document) using the REST API endpoint /api/packages/{packageId}/documents.

  Doing so returns me a "406 Not Acceptable" error, which doesn't tell me much on what is wrong.

  I've checked again and again with documentation, and my JSON has the right structure.

  I've also tested based on this tutorial and I'm getting the same, even if I trim down my test to the minimum like that example do: https://community.onespan.com/documentation/onespan-sign/guides/feature-guides/developer/uploading-deleting-documents

  I'm using GuzzleHttp\Client in PHP to send my payload.

  Here the code:

 

$payload = [
  [
    'id' => 'file.88',
    'name' => 'sample-single-page.pdf',
    'index' => '0',
    'approvals' => [[
        'fields' => [[
            'width' => '126',
            'height' => '48',
            'top' => '315',
            'left' => '424',
            'page' => '1',
            'type' => 'SIGNATURE',
            'subtype' => 'CAPTURE',
          ],
        ],
        'role' => 'representative.5',
        'id' => 'signature.rep-5',
      ],[
        'fields' => [[
            'width' => '229',
            'height' => '40',
            'top' => '256',
            'left' => '328',
            'page' => '1',
            'type' => 'SIGNATURE',
            'subtype' => 'CAPTURE',
          ],
        ],
        'role' => 'signer.188',
        'id' => 'signature.sig-188',
      ],
    ],
  ],
];

self::$client = new \GuzzleHttp\Client([
  'base_uri' => 'https://sandbox.esignlive.com/api/',
  'headers' => [
    'Accept'
=> 'application/json',
    'Authorization'
=> 'Basic ' . self::$apiKey
  ]
]);

$request = ['multipart' => [[
  'name'
=> 'file',
  'filename' => 'sample-single-page.pdf',
  'contents'
=> $content
], [
  'name'
=> 'payload',
  'contents'
=> json_encode($payload)
]]];


$response = self::$client->request('POST', 'packages/' . rawurlencode($packageid) . '/documents', $request);

 


Duo_Liang | Posts: 3776

Reply to: [Solved] Package Add Document - 406 Not Allowed

0 votes

Hi Alexandre,

 

At a first glance, could you try to set the "accept" as "text/html" for just this API endpoint? It's a bit weird that only the upload document API returns in this type than JSON.

 

Duo

 


chatnsign-alexandre | Posts: 4

Reply to: [Solved] Package Add Document - 406 Not Allowed

0 votes

Indeed, by changing the Accept from "application/json" to "text/html" on this endpoint, it worked properly.

I now know that on this page: https://community.onespan.com/products/onespan-sign/sandbox#/Documents/api.packages._packageId.documents.post

I need to check the "Media-Type" of the 200 HTTP-code.

Thank you !


Hello! Looks like you're enjoying the discussion, but haven't signed up for an account.

When you create an account, we remember exactly what you've read, so you always come right back where you left off