HTTP Request WebAPI Help

Hello. I’m trying to generate mockups using Printful’s API by sending a POST request using the HTTP Request activity. The below is the official documentation.

I imported the following cURL HTTP request

curl -X POST \
  https://api.printful.com/v2/mockup-tasks \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer [MY ACCESS TOKEN]' \
  -H 'X-PF-Store-Id: 13334145' \
  -d '{
    "format": "jpg",
    "products": [
      {
        "source": "product_template",
        "mockup_style_ids": [766],
        "product_template_id": 67856103,
        "catalog_variant_ids": [4011, 4026]
      }
    ]
  }'

Result:

{
  "data": "Invalid JSON data in the request body",
  "error": {
    "reason": "BadRequest",
    "message": "Invalid JSON data in the request body"
  }
}
1 Like

@private_matter,

What’s the exact json you are passing?

Thganks,
Ashok :slight_smile:

1 Like

Hi @ashokkarale

I created a new variable called jsonObject of type JObject. I then assigned it the following value:

Newtonsoft.Json.JsonConvert.DeserializeObject(Of Newtonsoft.Json.Linq.JObject)("{""format"":""jpg"",""products"":[{""source"":""product_template"",""mockup_style_ids"":[766],""product_template_id"":67856103,""catalog_variant_ids"":[4011,4026]}]")

2024-04-02_180732

Still producing the same error as before.

1 Like

Deserialize takes the string and converts it to a JSON object. You need to be passing the JSON as a string in the body of the request. Add .ToString onto the end of your expression to get it back out as a string:

Newtonsoft.Json.JsonConvert.DeserializeObject(Of Newtonsoft.Json.Linq.JObject)("{""format"":""jpg"",""products"":[{""source"":""product_template"",""mockup_style_ids"":[766],""product_template_id"":67856103,""catalog_variant_ids"":[4011,4026]}]").ToString

Or just build the string and pass it:

"{""format"":""jpg"",""products"":[{""source"":""product_template"",""mockup_style_ids"":[766],""product_template_id"":67856103,""catalog_variant_ids"":[4011,4026]}]}"

I added another ]} on the end because you were missing it.

@private_matter , you should be passing jsson in plain string not as an object

its already converted to a string. I don’t see where’s the issue.

No worries. Solved the issue. I was inserting the JSON string as a parameter instead of pasting it in the right side of the Properties panel in the Body field. Response was successful.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.