API PUT Request Query

Hi all,

Would you be able to advise how to create a put/post request to Contentful in order to create a new item. I manage to connect and all get requests work fine. However, I am not sure what to do to send my request as Json Array through HTTP Request activity.

Below you can find the sample provided on their website.

=================
curl --include
–request PUT
–header ‘Authorization: Bearer <cma_token>’
–header ‘Content-Type: application/vnd.contentful.management.v1+json’
–data-binary ‘{
“name”: “Blog Post”,
“fields”: [
{
“id”: “title”,
“name”: “Title”,
“required”: true,
“localized”: true,
“type”: “Text”
},
{
“id”: “body”,
“name”: “Body”,
“required”: true,
“localized”: true,
“type”: “Text”
}
]
}’
https://api.contentful.com/spaces/{space_id}/environments/{environment_id}/content_types/{content_type_id}

I checked couple of UiPath API tutorials and they all suggest to set the Id, name etc… as parameters, but this does not work for more complex cases like this one with nested arrays.

{
“id”: “body”,
“name”: “Body”,
“required”: true,
“localized”: true,
“type”: “Text”
}

If you can provide me with a sample or screenshot on how to set up this it would be greatly appreciated. Thanks

@VasilD

why dont you set the body format as application/json and send the body in the body property.

something like chr(34) + "name" + chr(34)
image

chr(34) because json requires double quotes. You can also paste your json body in a txt file read that and pass that variable in body. try this and let me know.

2 Likes

Hi mate,

Thank you for the useful suggestions. I will definitely try to setup the body in a text file and replace the values afterwards as this is much more flexible and elegant way for managing the API calls.
However, for now I just set the body as per the below screenshots, but unfortunately does not work. Any ideas what I missed?

and

@VasilD shouldnt the request method be PUT in your screenshot it is POST. Also your space_id and environment_id are visible in the preview url field I assume you would want to hide since you have hidden them in the paramters field

I totally forgot about the preview filed :slight_smile: . Thank you for pointing this out.
I tried both PUT and POST and unfortunately none of them work.

what error code are you getting? could you attach a screenshot

Hi @VasilD

refer below thread.

HI all,

Thank you for your suggestions.
After playing with the API for several hours I managed to find a solution which works for me and would like to share, if anyone is in a similar situation:

  1. Instead of creating the json body as string and escaping/replacing the quotation marks with Chr(34). I set the body as in a JSON file and marked the values I would like to update as “/value/”:

image

  1. I read the Json file and parse it as a string using “JObject.Parse(YOUR_StringVar)”
  2. I used string replacements to update the string representation of the JSON file:

  1. Then I set the updated string version of the JSON body to the HTTP request > Body and it works :slight_smile:

Hope this will help someone :slight_smile: