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

Create asset return 406 #350

Closed
Popesites opened this issue Feb 24, 2020 · 3 comments
Closed

Create asset return 406 #350

Popesites opened this issue Feb 24, 2020 · 3 comments

Comments

@Popesites
Copy link

Popesites commented Feb 24, 2020

Have been working on this issue for hours, cannot create asset using asset() resource.

Here is example query:

const id = this.themeId;

const query = {
  asset: {
    key: "snippets/test.liquid",
    value: "Content"
  }
};

const asset = await this.shopify.asset.create(id, query); // throws 406 Not Acceptable error

By the way I notice 2 small errors on asset create test...

  1. Using the asset 'update' fixin instead of the 'create' fixin
  2. Using the res fixin data instead of the req - basically an invalid request on the test itself?
@lpinca
Copy link
Collaborator

lpinca commented Feb 24, 2020

I don't see the error.

https://shopify.dev/docs/admin-api/rest/reference/online-store/asset#update-2020-01

it('creates an asset', () => {
const input = fixtures.req.create;
const output = fixtures.res.create;
scope.put('/admin/themes/828155753/assets.json', input).reply(200, output);
return shopify.asset
.create(828155753, input.asset)
.then((data) => expect(data).to.deep.equal(output.asset));
});

{
"asset": {
"key": "assets/empty.gif",
"attachment": "R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==\n"
}
}

{
"asset": {
"key": "assets/empty.gif",
"public_url": "https://cdn.shopify.com/s/files/1/0006/9093/3842/t/1/assets/empty.gif?16418212202600161583",
"created_at": "2015-09-02T14:51:55-04:00",
"updated_at": "2015-09-02T14:51:55-04:00",
"content_type": "image/gif",
"size": 43,
"theme_id": 828155753
}
}

In your usage example the second argument of the create() method should only be

const query = { key: 'snippets/test.liquid', value: 'Content' };

@Popesites
Copy link
Author

Popesites commented Feb 24, 2020

@lpinca

Thanks for quick reply. This worked!

Could you please check req.json:

https://github.com/MONEI/Shopify-api-node/blob/master/test/fixtures/asset/req/create.json

Looks like:

{
  "asset": {
    "key": "assets/empty.gif",
    "attachment": "R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==\n"
  }
}

I think this syntax is different than what you suggested?

Also that is strange, sorry I thought that on Shopify-api-node/test/asset.test.js that input was equal to res, not req. My bad, but please double check the input data to confirm if that should be updated.

@lpinca
Copy link
Collaborator

lpinca commented Feb 25, 2020

It's ok. See,

.create(828155753, input.asset)

input.asset is

{
  key: 'assets/empty.gif', 
  attachment: 'R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==\n' 
}

@lpinca lpinca closed this as completed Feb 25, 2020
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

2 participants