# Mutation request working in postman but not in code

**URL:** <https://community.shiphero.com/t/mutation-request-working-in-postman-but-not-in-code/1381>\
**Category:** GraphQL API\
**Created:** [June 17, 2021, 11:31pm UTC](https://community.shiphero.com/t/mutation-request-working-in-postman-but-not-in-code/1381 "2021-06-17T23:31:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![FMCjohn](https://avatars.discourse-cdn.com/v4/letter/f/919ad9/32.png) [@FMCjohn](https://community.shiphero.com/u/FMCjohn)\
**Post date:** [June 17, 2021, 11:31pm UTC](https://community.shiphero.com/t/mutation-request-working-in-postman-but-not-in-code/1381/1 "2021-06-17T23:31:02Z")

</div>

My mutation is formatted exactly the same in my custom code as it is in postman but it keeps returning a 400 error when I try to run it on my server. Not sure if anyone has had this experience but if there is any feed back that would be great! This is what the code looks like

`const mutation = `mutation {  
product\_create(  
data: {  
name: “john”  
sku: “john123”  
price: “23.00”  
warehouse\_products: {  
warehouse\_id: “actualidnotshown”  
on\_hand: 130  
inventory\_bin: “Bin A1”  
reserve\_inventory: 0  
replenishment\_level: 1  
reorder\_level: 1  
reorder\_amount: 20  
custom: false  
}  
value: “15.00”  
barcode: “2233443355chair”  
country\_of\_manufacture: “US”  
dimensions: { weight: “12”, height: “25”, width: “10”, length: “25” }  
kit: false  
kit\_build: false  
no\_air: false  
final\_sale: false  
customs\_value: “1.00”  
not\_owned: true  
dropship: false  
}  
) {  
request\_id  
complexity  
product {  
id  
legacy\_id  
account\_id  
name  
sku  
price  
value  
barcode  
country\_of\_manufacture  
dimensions {  
weight  
height  
width  
length  
}  
tariff\_code  
kit  
kit\_build  
no\_air  
final\_sale  
customs\_value  
customs\_description  
not\_owned  
dropship  
created\_at  
}  
}  
}`

```
    const options = {

        headers: {
            "Authorization": `Bearer ${accessToken}`,
            "Content-Type": "application/json",
        },
        body: JSON.stringify({ mutation }),

    }

    got
        .post(shipheroUrl, options)
        .then((response) => {
            console.log(response)
        }).catch((err) => {
            console.log(err)
        })
})`
```

---

<div class="post-metadata">

**Author:** ![FMCjohn](https://avatars.discourse-cdn.com/v4/letter/f/919ad9/32.png) [@FMCjohn](https://community.shiphero.com/u/FMCjohn)\
**Post date:** [June 17, 2021, 11:36pm UTC](https://community.shiphero.com/t/mutation-request-working-in-postman-but-not-in-code/1381/2 "2021-06-17T23:36:17Z")

</div>

it is also letting me do a query just not a mutation.

---

<div class="post-metadata">

**Author:** ![tomasw](https://sea2.discourse-cdn.com/flex020/user_avatar/community.shiphero.com/tomasw/32/248_2.png) [@tomasw](https://community.shiphero.com/u/tomasw)\
**Post date:** [July 9, 2021, 2:38pm UTC](https://community.shiphero.com/t/mutation-request-working-in-postman-but-not-in-code/1381/3 "2021-07-09T14:38:50Z")

</div>

Hi @FMCjohn !  
Are you still having issues with this?  
This is Javascript, right? if that is the case we have a section that could help with GraphQL Client [GraphQL Primer – Developer Resources | ShipHero](https://developer.shiphero.com/graphql-primer/#javascript)

Thanks in advance!  
Tom

---

<div class="post-metadata">

**Author:** ![jknechtv](https://avatars.discourse-cdn.com/v4/letter/j/ecb155/32.png) [@jknechtv](https://community.shiphero.com/u/jknechtv)\
**Post date:** [July 9, 2021, 2:53pm UTC](https://community.shiphero.com/t/mutation-request-working-in-postman-but-not-in-code/1381/4 "2021-07-09T14:53:26Z")

</div>

Hey FMCJohn,

I had this problem yesterday and it turns out in graphQL it seems EVERYTHING is technically a query. You just gotta wrap your mutation in a query object:  
(P.S. avoid using JSON.stringify() as it will add quotes ("") around variable names)

```auto
const mutation = `mutation{ my-mutation( ) }`
const query = {
  query: mutation
}
const options = {

        headers: {
            "Authorization": `Bearer ${accessToken}`,
            "Content-Type": "application/json",
        },
        body: query),

    }

```

If that does work I found writing my mutation on a single line with CSV works well

```auto
const mutation = mutation {
product_create(
data: { name: “John”, sku: “john123”, price: “23.00”, warehouse_products: { warehouse_id: “actualidnotshown”, on_hand: 130, inventory_bin: “Bin A1”, reserve_inventory: 0, replenishment_level: 1, reorder_level: 1, reorder_amount: 20, custom: false }, value: “15.00”, barcode: “2233443355chair”, country_of_manufacture: “US”, dimensions: { weight: “12”, height: “25”, width: “10”, length: “25” }, kit: false, kit_build: false, no_air: false, final_sale: false, customs_value: “1.00”, not_owned: true, dropship: false } ) {
request_id
complexity
product {
id
legacy_id
account_id
name
sku
price
value
barcode
country_of_manufacture
dimensions {
weight
height
width
length
}
tariff_code
kit
kit_build
no_air
final_sale
customs_value
customs_description
not_owned
dropship
created_at
}
}
}`

```

---

<div class="post-metadata">

**Author:** ![FMCjohn](https://avatars.discourse-cdn.com/v4/letter/f/919ad9/32.png) [@FMCjohn](https://community.shiphero.com/u/FMCjohn)\
**Post date:** [August 10, 2021, 7:16pm UTC](https://community.shiphero.com/t/mutation-request-working-in-postman-but-not-in-code/1381/5 "2021-08-10T19:16:38Z")

</div>

Just now seeing this. THANKYOU!!!
