Expose metafields to the Storefront API error - shopify

I want to expose the product metafields in shopify to my Storefront API.
I am referring to following documentation. https://help.shopify.com/en/api/guides/metafields/storefront-api-metafields
Following is the content of my body
mutation($input: MetafieldStorefrontVisibilityInput!) {
metafieldStorefrontVisibilityCreate( input: $input ) {
metafieldStorefrontVisibility {
id
}
userErrors {
field message
}
}
}
Following are the GRAPHQL VARIABLES
{
"input": {
"namespace": "global",
"key": "description_tag",
"ownerType": "PRODUCT"
}
}
Following is the URL
https://posdev07.myshopify.com/admin/api/2019-07/graphql.json
I get following error when I make the request.
{"errors":{"query":"Required parameter missing or invalid"}}

Related

Shopify cartDiscountCodesUpdate storefront API cartid

I want to apply discount coupon code to the cart page, I am trying to use the storefront API cartDiscountCodesUpdate which expect the cart id. How can I get this cart id. Here is what I tried. I have created the webhook cart/create which has payload id in the form of string something like '1eef2aa2c2b2e889ec325db72f0877ec'.
Then I tried calling this id which I got from cart/create response in storefront API cartDiscountCodesUpdate like:
mutation cartDiscountCodesUpdate($cartId: ID!, $discountCodes: [String!]) {
cartDiscountCodesUpdate(cartId: $cartId, discountCodes: $discountCodes) {
cart {
id
}
userErrors {
field
message
}
}
}
Query Varialbe:
{
"cartId": "gid://shopify/Cart/1eef2aa2c2b2e889ec325db72f0877ec",
"discountCodes": [
"64J1ZQMBN9W5"
]
}
But its response with below error. I think its the issue with incorrect cart id. Can anyone help me how to get cart id after the cart is created?
Response from cartDiscountCodesUpdate storefront API.
{
"data": {
"cartDiscountCodesUpdate": {
"cart": null,
"userErrors": [
{
"field": [
"cartId"
],
"message": "The specified cart does not exist."
}
]
}
}
}

how to bind the response (data) getting from services call angular 5

component.ts file
public htmlData:any;
ngOnInit() {
this._htmlServices.getHtml()
.subscribe(data => {
this.htmlData = data;
});
}
Response from serivces callbelow
{
"html": {
"title": "HTML Questions",
"questions": [
{
"qno": 1,
"q": "What does a doctype do?",
"a": [
"It specifies which markup standard the page is using. With the information, the browser determines how to render the page according to the page's source code."
]
}
]
}
}
binding in html p tag below but it is not binding
<p>{{htmlData.html.title}}</p>
Without assuming anything here, it's likely that your htmlData is actually a string rather than json.
You might be able to see this by a:
console.log(typeof(this.htmlData))
just after assignment. So the solution is probably as simple as using
this.htmlData = JSON.parse(data)

How to change the example values for api requests in Swagger UI?

I'm making an API for a site and I'm using Swagger UI, I currently have a route for adding a favorite for a user the route is "/users/{id}/favorites/", and the params in the spec are:
"parameters":[
{
"in":"path",
"name":"id",
"description":"User's Id",
"required":true,
"schema":{
"$ref":"#/definitions/User"
}
},
{
"in":"body",
"name":"body",
"description":"Enter user's id and video id for favorite",
"required":true,
"schema":{
"$ref":"#/definitions/Favorite"
}
}
],
The definition for the favorites model in the spec looks like this:
"Favorite":{
"type":"object",
"properties":{
"id":{
"type":"integer",
"format": "int64"
},
"userId":{
"$ref":"#/definitions/User/properties/id"
},
"videoId":{
"$ref":"#/definitions/Video/properties/id"
}
},
"xml":{
"name":"Flag"
}
}
But currently when I go the /api route the example value being shown for the body param is
{
"id": 0
}
on the docs it displays an almost correct request sample correctly and shows:
{
"id": 0,
"userId": 0,
"videoId": 0
}
How do I change the example value for the /api route to show
{
"userId": 0,
"videoId": 0
}
as an example and how do I remove the id param from the example on the doc
Found a way to do it, not sure if this is the best way but I just changed the definition and made userId an int instead of a $ref and the same for videoId.

updating inventory quantity with PUT returns error

Here is the body
{
"product": {
"id": 1202316036,
"title": "cricket bat for sale",
"variants":[
{
"inventory_quantity": 500
}
]
}
}
This returns the following error
{
"errors": {
"base": [
"The variant 'Default Title' already exists."
]
}
}
But where as the updating the title seems to be working fine. Here is the body
{
"product": {
"id": 1202316036,
"title": "cricket bat for sale"
}
}
I am sure that PUT header(Content-Type: application/json) are set properly. Because updating title does work. How should I go about updating inventory management
ps: I am using POSTMAN for using shopify API
So you do need the variant id otherwise Shopify thinks you are creating a new variant. Also your variants need to have been set up for Shopify to manage their inventory. e.g.
var product = {
product:{
id: productId,
variants: [
{
id:5991257025,
inventory_management : "shopify",
inventory_quantity:20
},
{
id:5991257089,
inventory_management : "shopify",
inventory_quantity:26
}
]
}
};
I'm not sure if you can do multiple variants per call but to update a single variant's inventory quantity you'd do it like:
var payload = JSON.stringify({
variant: {
id: variantId,
inventory_quantity: qty
}
});
and then put that to "https://myshopifydomain/admin/variants/" +variantId + ".json";
possibly all you need to do is add the variant id for each variant you are updating. Your variant ids can be gotten by GETting the json for your items.

Raven DB HTTP API - Property Traversal

I am given the following JSON structure:
{
"document": {
"sections": {
"x": {
"title": "foo"
},
"y": {
"title": "bar"
}
}
}
}
How do I update value of the title property for a given section using the HTTP API?
I would like to provide a path (string) to get to the property.
This was fixed in build 2254. You should now be able to issue a single scripted patch like this:
EVAL http://localhost:8080/docs/foos/1
{Script:"this.document.sections.x.title = newTitle;",Values:{"newTitle":"Whatever"}}